Skip to content

Commit

Permalink
Add the spectate entities rule
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Gegy committed Mar 12, 2023
1 parent 9e9b2c6 commit a1f17b6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Leukocyte provides various rules that can be applied within authorities. These r
- `interact` controls global interaction over blocks and entities
- `attack` controls whether players can attack other entities
- `pvp` controls whether players can attack other players
- `spectate_entities` controls whether players can spectate entities from the entity's perspective in spectator mode
- `portals` controls whether players can construct portals
- `crafting` controls whether players can craft items
- `fall_damage` controls whether players should receive fall damage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class ProtectionRule {

public static final ProtectionRule ATTACK = register("attack");
public static final ProtectionRule PVP = register("pvp");
public static final ProtectionRule SPECTATE_ENTITIES = register("spectate_entities");

public static final ProtectionRule PORTALS = register("portals");
public static final ProtectionRule CRAFTING = register("crafting");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import xyz.nucleoid.stimuli.event.player.PlayerConsumeHungerEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent;
import xyz.nucleoid.stimuli.event.player.PlayerRegenerateEvent;
import xyz.nucleoid.stimuli.event.player.PlayerSpectateEntityEvent;
import xyz.nucleoid.stimuli.event.world.*;

import java.util.ArrayList;
Expand All @@ -54,6 +55,9 @@ public void applyTo(ProtectionRuleMap rules, EventRegistrar events) {
return attacked instanceof PlayerEntity ? rule : ActionResult.PASS;
});

this.forRule(events, rules.test(ProtectionRule.SPECTATE_ENTITIES))
.applySimple(PlayerSpectateEntityEvent.EVENT, rule -> (player, target) -> rule);

this.forRule(events, rules.test(ProtectionRule.CRAFTING))
.applySimple(ItemCraftEvent.EVENT, rule -> (player, recipe) -> rule);

Expand Down

0 comments on commit a1f17b6

Please sign in to comment.