diff --git a/src/main/java/ch/njol/skript/conditions/CondIsDashing.java b/src/main/java/ch/njol/skript/conditions/CondIsDashing.java new file mode 100644 index 00000000000..fe9141e6b79 --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondIsDashing.java @@ -0,0 +1,36 @@ +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.Camel; +import org.bukkit.entity.LivingEntity; + +@Name("Camel Is Dashing") +@Description("Checks whether a camel is currently using its dash ability.") +@Examples({ + "if last spawned camel is dashing:", + "\tkill last spawned camel" +}) +@Since("INSERT VERSION") +public class CondIsDashing extends PropertyCondition { + + static { + register(CondIsDashing.class, "dashing", "livingentities"); + } + + @Override + public boolean check(LivingEntity entity) { + if (entity instanceof Camel camel) + return camel.isDashing(); + return false; + } + + @Override + protected String getPropertyName() { + return "dashing"; + } + +} diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSprinting.java b/src/main/java/ch/njol/skript/conditions/CondIsSprinting.java index c1f25ea82e2..6740ce47d07 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSprinting.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSprinting.java @@ -1,16 +1,12 @@ package ch.njol.skript.conditions; -import org.bukkit.entity.Player; - 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.Player; -/** - * @author Peter Güttinger - */ @Name("Is Sprinting") @Description("Checks whether a player is sprinting.") @Examples("player is not sprinting") @@ -22,8 +18,8 @@ public class CondIsSprinting extends PropertyCondition { } @Override - public boolean check(final Player p) { - return p.isSprinting(); + public boolean check(Player player) { + return player.isSprinting(); } @Override diff --git a/src/main/java/ch/njol/skript/effects/EffSprinting.java b/src/main/java/ch/njol/skript/effects/EffSprinting.java new file mode 100644 index 00000000000..01a0b9d0b9b --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffSprinting.java @@ -0,0 +1,65 @@ +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.Player; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; + +@Name("Sprinting") +@Description({ + "Make a player start or stop sprinting.", + "If the player is not moving when this effect is used, they will be put in sprint mode for a tick and then stopped (this causes the FOV to change). " + + "Using it a second time, without the player manually sprinting in between, causes the player to stay in sprint mode, with some quirks.", + " - Particles may not be produced under the player's feet.", + " - The player will not exit the sprinting state if they stop moving.", + " - Restrictions like low hunger will not prevent the player from sprinting", + " - The player pressing shift will stop them sprinting, and pressing sprint will re-assert normal sprinting behavior", + "Using this effect two or more consecutive times on a stationary player produces undefined behavior and should not be relied on." +}) +@Examples({ + "make player start sprinting", + "force player to start sprinting" +}) +@Since("INSERT VERSION") +public class EffSprinting extends Effect { + + static { + Skript.registerEffect(EffSprinting.class, + "make %players% (start sprinting|sprint)", + "force %players% to (start sprinting|sprint)", + "make %players% (stop sprinting|not sprint)", + "force %players% to (stop sprinting|not sprint)"); + } + + private Expression players; + private boolean sprint; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + //noinspection unchecked + players = (Expression) exprs[0]; + sprint = matchedPattern <= 1; + return true; + } + + @Override + protected void execute(Event event) { + for (Player player : players.getArray(event)) { + player.setSprinting(sprint); + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "make " + players.toString(event, debug) + (sprint ? " start" : " stop") + " sprinting"; + } + +}