diff --git a/src/main/java/ch/njol/skript/conditions/CondIsPlayingDead.java b/src/main/java/ch/njol/skript/conditions/CondIsPlayingDead.java new file mode 100644 index 00000000000..a7961ee474c --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondIsPlayingDead.java @@ -0,0 +1,34 @@ +package ch.njol.skript.conditions; + +import ch.njol.skript.conditions.base.PropertyCondition; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import org.bukkit.entity.Axolotl; +import org.bukkit.entity.LivingEntity; + +@Name("Is Playing Dead") +@Description("Checks to see if an axolotl is playing dead.") +@Examples({ + "if last spawned axolotl is playing dead:", + "\tmake last spawned axolotl stop playing dead" +}) +@Since("INSERT VERSION") +public class CondIsPlayingDead extends PropertyCondition { + + static { + PropertyCondition.register(CondIsPlayingDead.class, PropertyType.BE, "playing dead", "livingentities"); + } + + @Override + public boolean check(LivingEntity entity) { + return (entity instanceof Axolotl axolotl) ? axolotl.isPlayingDead() : false; + } + + @Override + protected String getPropertyName() { + return "playing dead"; + } + +} diff --git a/src/main/java/ch/njol/skript/effects/EffPlayingDead.java b/src/main/java/ch/njol/skript/effects/EffPlayingDead.java new file mode 100644 index 00000000000..e9db97bbfd6 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffPlayingDead.java @@ -0,0 +1,55 @@ +package ch.njol.skript.effects; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Axolotl; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; + +@Name("Play Dead") +@Description("Make an axolotl start or stop playing dead.") +@Examples("make last spawned axolotl play dead") +@Since("INSERT VERSION") +public class EffPlayingDead extends Effect { + + static { + Skript.registerEffect(EffPlayingDead.class, + "make %livingentities% (start playing|play) dead", + "force %livingentities% to (start playing|play) dead", + "make %livingentities% (stop playing|not play) dead", + "force %livingentities% to (stop playing|not play) dead"); + } + + private Expression entities; + private boolean playDead; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + //noinspection unchecked + entities = (Expression) exprs[0]; + playDead = matchedPattern <= 1; + return true; + } + + @Override + protected void execute(Event event) { + for (LivingEntity entity : entities.getArray(event)) { + if (entity instanceof Axolotl axolotl) + axolotl.setPlayingDead(playDead); + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "make " + entities.toString(event, debug) + (playDead ? " start" : " stop") + " playing dead"; + } + +} diff --git a/src/test/skript/tests/syntaxes/effects/EffPlayingDead.sk b/src/test/skript/tests/syntaxes/effects/EffPlayingDead.sk new file mode 100644 index 00000000000..49f8cbc0125 --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffPlayingDead.sk @@ -0,0 +1,9 @@ +test "playing dead": + # Combines: EffPlayingDead and CondPlayingDead + spawn an axolotl at test-location: + set {_entity} to entity + make {_entity} start playing dead + assert {_entity} is playing dead with "Axolotl should be playing dead" + make {_entity} stop playing dead + assert {_entity} is not playing dead with "Axolotl should not be playing dead" + clear entity within {_entity}