diff --git a/src/main/java/ch/njol/skript/conditions/CondAI.java b/src/main/java/ch/njol/skript/conditions/CondAI.java deleted file mode 100644 index da7c896917b..00000000000 --- a/src/main/java/ch/njol/skript/conditions/CondAI.java +++ /dev/null @@ -1,36 +0,0 @@ -package ch.njol.skript.conditions; - -import org.bukkit.entity.LivingEntity; - -import ch.njol.skript.conditions.base.PropertyCondition; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Example; -import ch.njol.skript.doc.Name; -import ch.njol.skript.doc.Since; - -@Name("Has AI") -@Description("Checks whether an entity has AI.") -@Example("target entity has ai") -@Since("2.5") -public class CondAI extends PropertyCondition { - - static { - register(CondAI.class, PropertyType.HAVE, "(ai|artificial intelligence)", "livingentities"); - } - - @Override - public boolean check(LivingEntity entity) { - return entity.hasAI(); - } - - @Override - protected PropertyType getPropertyType() { - return PropertyType.HAVE; - } - - @Override - protected String getPropertyName() { - return "artificial intelligence"; - } - -} diff --git a/src/main/java/ch/njol/skript/expressions/ExprAI.java b/src/main/java/ch/njol/skript/expressions/ExprAI.java index 33faceabbcb..4c17c020dad 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprAI.java +++ b/src/main/java/ch/njol/skript/expressions/ExprAI.java @@ -1,5 +1,8 @@ package ch.njol.skript.expressions; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -11,16 +14,24 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; import ch.njol.util.coll.CollectionUtils; +import org.skriptlang.skript.lang.script.ScriptWarning; @Name("Entity AI") -@Description("Returns whether an entity has AI.") +@Description("Returns whether an entity has AI. This expression is deprecated and will be removed in a future version. Use the Entity AI effect instead.") @Example("set artificial intelligence of target entity to false") @Since("2.5") +@Deprecated(since = "INSERT VERSION", forRemoval = true) public class ExprAI extends SimplePropertyExpression { static { register(ExprAI.class, Boolean.class, "(ai|artificial intelligence)", "livingentities"); } + + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + ScriptWarning.printDeprecationWarning("This expression is deprecated and will be removed in a future version. Use the AI effect instead: 'enable ai for " + expressions[0].toString(null, false) + "'."); + return super.init(expressions, matchedPattern, isDelayed, parseResult); + } @Override @Nullable diff --git a/src/main/java/ch/njol/skript/expressions/ExprFlightMode.java b/src/main/java/ch/njol/skript/expressions/ExprFlightMode.java index 47032801823..4f0a1d49092 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprFlightMode.java +++ b/src/main/java/ch/njol/skript/expressions/ExprFlightMode.java @@ -6,22 +6,33 @@ import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.lang.script.ScriptWarning; @Name("Flight Mode") -@Description("Whether the player(s) are allowed to fly. Use Make Fly effect to force player(s) to fly.") +@Description("Whether the player(s) are allowed to fly. This expression is deprecated and will be removed in a future version. Use Make Fly effect to force player(s) to fly instead.") @Example("set flight mode of player to true") @Example("send \"%flying state of all players%\"") @Since("2.2-dev34") +@Deprecated(since = "INSERT VERSION", forRemoval = true) public class ExprFlightMode extends SimplePropertyExpression { static { register(ExprFlightMode.class, Boolean.class, "fl(y[ing]|ight) (mode|state)", "players"); } + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + ScriptWarning.printDeprecationWarning("This expression is deprecated and will be removed in a future version. Use the Make Fly effect instead: 'make " + expressions[0].toString(null, false) + " fly'."); + return super.init(expressions, matchedPattern, isDelayed, parseResult); + } + @Override public Boolean convert(final Player player) { return player.getAllowFlight(); diff --git a/src/main/java/ch/njol/skript/expressions/ExprGlowing.java b/src/main/java/ch/njol/skript/expressions/ExprGlowing.java index 31770fcc7e7..7377eeeabc3 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprGlowing.java +++ b/src/main/java/ch/njol/skript/expressions/ExprGlowing.java @@ -1,5 +1,8 @@ package ch.njol.skript.expressions; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; import org.bukkit.entity.Entity; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; @@ -10,16 +13,24 @@ import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; +import org.skriptlang.skript.lang.script.ScriptWarning; @Name("Glowing") -@Description("Indicates if targeted entity is glowing (new 1.9 effect) or not. Glowing entities can be seen through walls.") +@Description("Indicates if targeted entity is glowing (new 1.9 effect) or not. Glowing entities can be seen through walls. This expression is deprecated and will be removed in a future version. Use the Entity Glow/a> effect instead.") @Example("set glowing of player to true") @Since("2.2-dev18") +@Deprecated(since = "INSERT VERSION", forRemoval = true) public class ExprGlowing extends SimplePropertyExpression { static { register(ExprGlowing.class, Boolean.class, "glowing", "entities"); } + + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + ScriptWarning.printDeprecationWarning("This expression is deprecated and will be removed in a future version. Use the glowing effect instead: 'make " + expressions[0].toString(null, false) + " glow'."); + return super.init(expressions, matchedPattern, isDelayed, parseResult); + } @Override public Boolean convert(final Entity e) { diff --git a/src/main/java/ch/njol/skript/expressions/ExprGravity.java b/src/main/java/ch/njol/skript/expressions/ExprGravity.java index e71c4cbb408..417ec629052 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprGravity.java +++ b/src/main/java/ch/njol/skript/expressions/ExprGravity.java @@ -1,26 +1,36 @@ package ch.njol.skript.expressions; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; import org.bukkit.entity.Entity; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; -import ch.njol.skript.Skript; import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Example; import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; +import org.skriptlang.skript.lang.script.ScriptWarning; @Name("Gravity") -@Description("If entity is affected by gravity or not, i.e. if it has Minecraft 1.10+ NoGravity flag.") -@Example("set gravity of player off") +@Description("If entity is affected by gravity or not, i.e. if it has Minecraft 1.10+ NoGravity flag. This expression is deprecated and will be removed in a future version. Use the Entity Gravity effect instead.") +@Example("set gravity of player to off") @Since("2.2-dev21") +@Deprecated(since = "INSERT VERSION", forRemoval = true) public class ExprGravity extends SimplePropertyExpression { static { register(ExprGravity.class, Boolean.class, "gravity", "entities"); } + + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + ScriptWarning.printDeprecationWarning("This expression is deprecated and will be removed in a future version. Use the gravity effect instead: 'enable gravity of " + expressions[0].toString(null, false) + "'."); + return super.init(expressions, matchedPattern, isDelayed, parseResult); + } @Override public Boolean convert(final Entity e) { diff --git a/src/main/java/ch/njol/skript/expressions/ExprProjectileCriticalState.java b/src/main/java/ch/njol/skript/expressions/ExprProjectileCriticalState.java index 806e36fb2e8..fb4c4ffcf29 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprProjectileCriticalState.java +++ b/src/main/java/ch/njol/skript/expressions/ExprProjectileCriticalState.java @@ -1,5 +1,8 @@ package ch.njol.skript.expressions; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.Arrow; import org.bukkit.entity.Projectile; @@ -14,15 +17,17 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; import ch.njol.util.coll.CollectionUtils; +import org.skriptlang.skript.lang.script.ScriptWarning; @Name("Projectile Critical State") -@Description("A projectile's critical state. The only currently accepted projectiles are arrows and tridents.") +@Description("A projectile's critical state. The only currently accepted projectiles are arrows and tridents. This expression is deprecated and will be removed in a future version. Use the Projectile Critical State effect instead.") @Example(""" on shoot: event-projectile is an arrow set projectile critical mode of event-projectile to true """) @Since("2.5.1") +@Deprecated(since = "INSERT VERSION", forRemoval = true) public class ExprProjectileCriticalState extends SimplePropertyExpression { private static final boolean abstractArrowExists = Skript.classExists("org.bukkit.entity.AbstractArrow"); @@ -30,6 +35,12 @@ public class ExprProjectileCriticalState extends SimplePropertyExpression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + ScriptWarning.printDeprecationWarning("This expression is deprecated and will be removed in a future version. Use the projectile critical state effect instead: 'make " + expressions[0].toString(null, false) + " crit'."); + return super.init(expressions, matchedPattern, isDelayed, parseResult); + } @Nullable @Override diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/EntityModule.java b/src/main/java/org/skriptlang/skript/bukkit/entity/EntityModule.java index bdd2f43c897..5a8de03b75a 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/entity/EntityModule.java +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/EntityModule.java @@ -13,6 +13,14 @@ import org.skriptlang.skript.addon.HierarchicalAddonModule; import org.skriptlang.skript.addon.SkriptAddon; import org.skriptlang.skript.bukkit.entity.displays.DisplayModule; +import org.skriptlang.skript.bukkit.entity.elements.conditions.CondAI; +import org.skriptlang.skript.bukkit.entity.elements.conditions.CondGravity; +import org.skriptlang.skript.bukkit.entity.elements.conditions.CondIsGlowing; +import org.skriptlang.skript.bukkit.entity.elements.conditions.CondProjectileIsCritical; +import org.skriptlang.skript.bukkit.entity.elements.effects.EffAI; +import org.skriptlang.skript.bukkit.entity.elements.effects.EffGlowing; +import org.skriptlang.skript.bukkit.entity.elements.effects.EffGravity; +import org.skriptlang.skript.bukkit.entity.elements.effects.EffProjectileCriticalState; import org.skriptlang.skript.bukkit.entity.elements.expressions.ExprPathfindingLocation; import org.skriptlang.skript.bukkit.entity.elements.expressions.ExprPathfindingTarget; import org.skriptlang.skript.bukkit.entity.elements.effects.EffTeleport; @@ -83,11 +91,20 @@ protected void loadSelf(SkriptAddon addon) { .build()); register(addon, + CondAI::register, + CondGravity::register, + CondIsGlowing::register, + CondProjectileIsCritical::register, + + EffAI::register, + EffGlowing::register, + EffGravity::register, + EffProjectileCriticalState::register, + EffTeleport::register, + ExprDeathMessage::register, ExprPathfindingLocation::register, - ExprPathfindingTarget::register, - EffTeleport::register, - ExprDeathMessage::register + ExprPathfindingTarget::register ); } diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondAI.java b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondAI.java new file mode 100644 index 00000000000..155e837eadd --- /dev/null +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondAI.java @@ -0,0 +1,53 @@ +package org.skriptlang.skript.bukkit.entity.elements.conditions; + +import org.bukkit.entity.LivingEntity; + +import ch.njol.skript.conditions.base.PropertyCondition; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Example; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import org.skriptlang.skript.registration.SyntaxRegistry; + +@Name("Has AI") +@Description( + "Check whether an entity has AI. Entities without AI will not try to attack " + + "other entities and will not be able to move at all. This includes knockback " + + "from getting hit, falling due to gravity, getting pushed by entities/water, " + + "changing velocity with commands and any other form of movement. Accumulated " + + "knockback and velocity changes will be applied when ai is enabled again." +) +@Example("target entity has ai") +@Since("2.5") +public class CondAI extends PropertyCondition { + + public static void register(SyntaxRegistry registry) { + registry.register( + SyntaxRegistry.CONDITION, + infoBuilder( + CondAI.class, + PropertyType.HAVE, + "(ai|artificial intelligence)", + "livingentities" + ) + .supplier(CondAI::new) + .build() + ); + } + + @Override + public boolean check(LivingEntity entity) { + return entity.hasAI(); + } + + @Override + protected PropertyType getPropertyType() { + return PropertyType.HAVE; + } + + @Override + protected String getPropertyName() { + return "artificial intelligence"; + } + +} diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondGravity.java b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondGravity.java new file mode 100644 index 00000000000..4604128af72 --- /dev/null +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondGravity.java @@ -0,0 +1,59 @@ +package org.skriptlang.skript.bukkit.entity.elements.conditions; + +import ch.njol.skript.conditions.base.PropertyCondition; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Example; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Entity; +import org.skriptlang.skript.registration.SyntaxRegistry; + +@Name("Experiences Gravity") +@Description( + "Change whether an entity is affected by gravity. This will override any effects " + + "from the gravity attribute or potions like slow falling." +) +@Example("send whether player experiences gravity") +@Since("INSERT VERSION") +public class CondGravity extends PropertyCondition { + + public static void register(SyntaxRegistry registry) { + registry.register( + SyntaxRegistry.CONDITION, + infoBuilder( + CondGravity.class, + PropertyType.BE, + "affected by gravity", + "entities" + ) + .addPatterns( + "%entities% experience[s] gravity", + "%entities% (doesn't|does not|do not|don't) experience gravity" + ) + .supplier(CondGravity::new) + .build() + ); + } + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + //noinspection unchecked + setExpr((Expression) exprs[0]); + setNegated(matchedPattern % 2 == 1); + return true; + } + + @Override + public boolean check(Entity entity) { + return entity.hasGravity(); + } + + @Override + protected String getPropertyName() { + return "affected by gravity"; + } + +} diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondIsGlowing.java b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondIsGlowing.java new file mode 100644 index 00000000000..cc7d5620cfe --- /dev/null +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondIsGlowing.java @@ -0,0 +1,49 @@ +package org.skriptlang.skript.bukkit.entity.elements.conditions; + +import ch.njol.skript.conditions.base.PropertyCondition; +import ch.njol.skript.doc.*; +import org.bukkit.entity.Entity; +import org.skriptlang.skript.registration.SyntaxRegistry; + +@Name("Is Glowing") +@Description( + "Check whether an entity is glowing. Glowing entites have outlines that can be " + + "seen through blocks. This will change the entity's glowing property (NBT). This " + + "is not related to the glowing potion effect." +) +@Example(""" + command /glow: + trigger: + if player is glowing: + make player stop glowing + else: + make player glow + """) +@Since("INSERT VERSION") +public class CondIsGlowing extends PropertyCondition { + + public static void register(SyntaxRegistry registry) { + registry.register( + SyntaxRegistry.CONDITION, + infoBuilder( + CondIsGlowing.class, + PropertyType.BE, + "glowing", + "entities" + ) + .supplier(CondIsGlowing::new) + .build() + ); + } + + @Override + public boolean check(Entity entity) { + return entity.isGlowing(); + } + + @Override + protected String getPropertyName() { + return "glowing"; + } + +} diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondProjectileIsCritical.java b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondProjectileIsCritical.java new file mode 100644 index 00000000000..958cf088451 --- /dev/null +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/conditions/CondProjectileIsCritical.java @@ -0,0 +1,53 @@ +package org.skriptlang.skript.bukkit.entity.elements.conditions; + +import ch.njol.skript.conditions.base.PropertyCondition; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Example; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.entity.EntityData; +import org.bukkit.entity.AbstractArrow; +import org.bukkit.entity.Projectile; +import org.skriptlang.skript.registration.SyntaxRegistry; + +@Name("Projectile Is Critical") +@Description(""" + Check whether a projectile is in its critical state. When in critical state the projectile will have a trail of particles and deal more damage. + Currently this only applies to arrows and tridents. + """) +@Example(""" + on shoot: + if event-projectile will crit: + enable projectile critical state of event-projectile + """) +@Since("INSERT VERSION") +public class CondProjectileIsCritical extends PropertyCondition { + + public static void register(SyntaxRegistry registry) { + registry.register( + SyntaxRegistry.CONDITION, + infoBuilder( + CondProjectileIsCritical.class, + PropertyType.WILL, + "[be] crit[ical]", + "projectiles" + ) + .supplier(CondProjectileIsCritical::new) + .build() + ); + } + + @Override + public boolean check(Projectile projectile) { + if (projectile instanceof AbstractArrow abstractArrow) { + return abstractArrow.isCritical(); + } + warning("This projectile (" + EntityData.toString(projectile) + ") is not supported. Critical projectile state only applies to arrows and tridents."); + return isNegated(); + } + + protected String getPropertyName() { + return "critical"; + } + +} diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffAI.java b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffAI.java new file mode 100644 index 00000000000..b819beb7ece --- /dev/null +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffAI.java @@ -0,0 +1,70 @@ +package org.skriptlang.skript.bukkit.entity.elements.effects; + +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Example; +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.skript.lang.SyntaxStringBuilder; +import ch.njol.util.Kleenean; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.registration.SyntaxInfo; +import org.skriptlang.skript.registration.SyntaxRegistry; + +@Name("Entity AI") +@Description( + "Change whether an entity has AI. Entities without AI will not try to attack " + + "other entities and will not be able to move at all. This includes knockback " + + "from getting hit, falling due to gravity, getting pushed by entities/water, " + + "changing velocity with commands and any other form of movement. Accumulated " + + "knockback and velocity changes will be applied when ai is enabled again." +) +@Example("enable artificial intelligence of target entity") +@Example("disable ai of last spawned entity") +@Since("INSERT VERSION") +public class EffAI extends Effect { + + public static void register(SyntaxRegistry registry) { + registry.register( + SyntaxRegistry.EFFECT, + SyntaxInfo.builder(EffAI.class) + .addPatterns( + "(enable|:disable) [the] (ai|artificial intelligence) (of|for) %livingentities%", + "(enable|:disable) %livingentities%'s (ai|artificial intelligence)" + ) + .supplier(EffAI::new) + .build() + ); + } + + private Expression entities; + private boolean negated; + + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + //noinspection unchecked + entities = (Expression) expressions[0]; + negated = parseResult.hasTag("disable"); + return true; + } + + @Override + protected void execute(Event event) { + for (LivingEntity entity : entities.getArray(event)) { + entity.setAI(!negated); + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return new SyntaxStringBuilder(event, debug) + .append(negated ? "disable" : "enable") + .append("ai of", entities) + .toString(); + } + +} diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffGlowing.java b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffGlowing.java new file mode 100644 index 00000000000..d0d56e764f5 --- /dev/null +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffGlowing.java @@ -0,0 +1,70 @@ +package org.skriptlang.skript.bukkit.entity.elements.effects; + +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Example; +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.skript.lang.SyntaxStringBuilder; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.registration.SyntaxInfo; +import org.skriptlang.skript.registration.SyntaxRegistry; + +@Name("Entity Glow") +@Description( + "Change whether an entity is glowing. Glowing entites have outlines that can be " + + "seen through blocks. This will change the entity's glowing property (NBT). This " + + "is not related to the glowing potion effect." +) +@Example("make target entity glow") +@Example("make player stop glowing") +@Since("INSERT VERSION") +public class EffGlowing extends Effect { + + public static void register(SyntaxRegistry registry) { + registry.register( + SyntaxRegistry.EFFECT, + SyntaxInfo.builder(EffGlowing.class) + .addPatterns( + "make %entities% [negate:not] glow", + "make %entities% (negate:stop|start) glowing", + "stop %entities% from glowing" + ) + .supplier(EffGlowing::new) + .build() + ); + } + + private Expression entities; + private boolean negated; + + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + //noinspection unchecked + entities = (Expression) expressions[0]; + negated = (parseResult.hasTag("negate") || matchedPattern == 2); + return true; + } + + @Override + protected void execute(Event event) { + for (Entity entity : entities.getArray(event)) { + entity.setGlowing(!negated); + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return new SyntaxStringBuilder(event, debug) + .append("make", entities) + .appendIf(negated, "not") + .append("glow") + .toString(); + } + +} diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffGravity.java b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffGravity.java new file mode 100644 index 00000000000..3cb283c4c50 --- /dev/null +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffGravity.java @@ -0,0 +1,67 @@ +package org.skriptlang.skript.bukkit.entity.elements.effects; + +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Example; +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.skript.lang.SyntaxStringBuilder; +import ch.njol.util.Kleenean; +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.registration.SyntaxInfo; +import org.skriptlang.skript.registration.SyntaxRegistry; + +@Name("Entity Gravity") +@Description( + "Change whether an entity is affected by gravity. This will override any effects " + + "from the gravity attribute or potions like slow falling." +) +@Example("enable gravity of target entity") +@Example("disable last spawned entity's gravity") +@Since("INSERT VERSION") +public class EffGravity extends Effect { + + public static void register(SyntaxRegistry registry) { + registry.register( + SyntaxRegistry.EFFECT, + SyntaxInfo.builder(EffGravity.class) + .addPatterns( + "(enable|:disable) [the] gravity (of|for) %entities%", + "(enable|:disable) %entities%'s gravity" + ) + .supplier(EffGravity::new) + .build() + ); + } + + private Expression entities; + private boolean negated; + + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + //noinspection unchecked + entities = (Expression) expressions[0]; + negated = parseResult.hasTag("disable"); + return true; + } + + @Override + protected void execute(Event event) { + for (Entity entity : entities.getArray(event)) { + entity.setGravity(!negated); + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return new SyntaxStringBuilder(event, debug) + .append(negated ? "disable" : "enable") + .append("gravity of", entities) + .toString(); + } + +} diff --git a/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffProjectileCriticalState.java b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffProjectileCriticalState.java new file mode 100644 index 00000000000..7c158239248 --- /dev/null +++ b/src/main/java/org/skriptlang/skript/bukkit/entity/elements/effects/EffProjectileCriticalState.java @@ -0,0 +1,76 @@ +package org.skriptlang.skript.bukkit.entity.elements.effects; + +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Example; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.entity.EntityData; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.SyntaxStringBuilder; +import ch.njol.util.Kleenean; +import org.bukkit.entity.AbstractArrow; +import org.bukkit.entity.Projectile; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.registration.SyntaxInfo; +import org.skriptlang.skript.registration.SyntaxRegistry; + +@Name("Projectile Critical State") +@Description(""" + Change whether a projectile is in its critical state. When in critical state \ + the projectile will have a trail of particles and deal more damage. + Currently this only applies to arrows and tridents. + """) +@Example(""" + on shoot: + make event-projectile crit + """) +@Since("INSERT VERSION") +public class EffProjectileCriticalState extends Effect { + + public static void register(SyntaxRegistry registry) { + registry.register( + SyntaxRegistry.EFFECT, + SyntaxInfo.builder(EffProjectileCriticalState.class) + .addPatterns( + "make %projectiles% [negate:not] crit[ical]" + ) + .supplier(EffProjectileCriticalState::new) + .build() + ); + } + + private Expression projectiles; + private boolean negated; + + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + //noinspection unchecked + projectiles = (Expression) expressions[0]; + negated = parseResult.hasTag("negate"); + return true; + } + + @Override + protected void execute(Event event) { + for (Projectile projectile : projectiles.getArray(event)) { + if (projectile instanceof AbstractArrow abstractArrow) { + abstractArrow.setCritical(!negated); + } else { + warning("This projectile (" + EntityData.toString(projectile) + ") is not supported. This only applies to arrows and tridents."); + } + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return new SyntaxStringBuilder(event, debug) + .append("make", projectiles) + .appendIf(negated, "not") + .append("crit") + .toString(); + } + +} diff --git a/src/test/skript/tests/bukkit/entity/EffAi.sk b/src/test/skript/tests/bukkit/entity/EffAi.sk new file mode 100644 index 00000000000..4222dfcadf9 --- /dev/null +++ b/src/test/skript/tests/bukkit/entity/EffAi.sk @@ -0,0 +1,19 @@ +test "Entity AI Effect": + spawn pig at test-location: + assert entity has ai with "Spawned pig didn't have ai" + disable ai of entity + assert entity doesn't have ai with "Failed to disable ai of pig" + enable artificial intelligence of entity + assert entity has ai with "Failed to enable ai of pig" + delete entity + +test "Entity AI Effect with multiple entities": + spawn 2 pigs at test-location: + add entity to {_pigs::*} + + assert {_pigs::*} have ai with "Spawned pigs didn't have ai" + disable ai of {_pigs::*} + assert {_pigs::*} don't have ai with "Failed to disable ai of 2 pigs" + enable artificial intelligence of {_pigs::*} + assert {_pigs::*} have ai with "Failed to enable ai of 2 pigs" + delete entities within {_pigs::*} diff --git a/src/test/skript/tests/bukkit/entity/EffGlowing.sk b/src/test/skript/tests/bukkit/entity/EffGlowing.sk new file mode 100644 index 00000000000..daf308c9501 --- /dev/null +++ b/src/test/skript/tests/bukkit/entity/EffGlowing.sk @@ -0,0 +1,53 @@ +test "Entity Glowing": + spawn pig at test location: + assert entity isn't glowing with "Spawned pig is already glowing" + make entity start glowing + assert entity is glowing with "Failed to make pig start glowing" + stop entity from glowing + assert entity is not glowing with "Failed to stop pig from glowing" + make entity glow + assert entity is glowing with "Failed to make pig glow" + make entity not glow + assert entity is not glowing with "Failed to make pig not glow" + delete entity + + spawn dropped apple at test-location: + assert entity isn't glowing with "Spawned dropped item is already glowing" + make entity start glowing + assert entity is glowing with "Failed to make dropped item start glowing" + stop entity from glowing + assert entity is not glowing with "Failed to stop dropped item from glowing" + make entity glow + assert entity is glowing with "Failed to make dropped item glow" + make entity not glow + assert entity is not glowing with "Failed to make dropped item not glow" + delete entity + +test "Entity Glowing for multiple entities": + spawn 2 pigs at test-location: + add entity to {_pigs::*} + + assert {_pigs::*} aren't glowing with "Spawned pigs were already glowing" + make {_pigs::*} start glowing + assert {_pigs::*} are glowing with "Failed to make 2 pigs start glowing" + stop {_pigs::*} from glowing + assert {_pigs::*} are not glowing with "Failed to stop 2 pigs from glowing" + make {_pigs::*} glow + assert {_pigs::*} are glowing with "Failed to make 2 pigs glow" + make {_pigs::*} not glow + assert {_pigs::*} are not glowing with "Failed to make 2 pigs not glow" + delete entities within {_pigs::*} + + spawn 2 dropped apples at test-location: + add entity to {_dropped items::*} + + assert {_dropped items::*} aren't glowing with "Spawned dropped items were already glowing" + make {_dropped items::*} start glowing + assert {_dropped items::*} is glowing with "Failed to make 2 dropped items start glowing" + stop {_dropped items::*} from glowing + assert {_dropped items::*} is not glowing with "Failed to stop 2 dropped items from glowing" + make {_dropped items::*} glow + assert {_dropped items::*} is glowing with "Failed to make 2 dropped items glow" + make {_dropped items::*} not glow + assert {_dropped items::*} is not glowing with "Failed to make 2 dropped items not glow" + delete entities within {_dropped items::*} diff --git a/src/test/skript/tests/bukkit/entity/EffGravity.sk b/src/test/skript/tests/bukkit/entity/EffGravity.sk new file mode 100644 index 00000000000..f2fed93ee7c --- /dev/null +++ b/src/test/skript/tests/bukkit/entity/EffGravity.sk @@ -0,0 +1,19 @@ +test "Entity Gravity Effect": + spawn pig at test-location: + assert entity experiences gravity with "Spawned pig didn't have gravity" + disable entity's gravity + assert entity doesn't experience gravity with "Failed to disable gravity of pig" + enable gravity of entity + assert entity is affected by gravity with "Failed to enable gravity of pig" + delete entity + +test "Entity Gravity Effect with multiple entities": + spawn 2 pigs at test-location: + add entity to {_pigs::*} + + assert {_pigs::*} experience gravity with "Spawned pigs didn't have ai" + disable gravity of {_pigs::*} + assert {_pigs::*} aren't affected by gravity with "Failed to disable gravity of 2 pigs" + enable {_pigs::*}'s gravity + assert {_pigs::*} are affected by gravity with "Failed to enable gravity of 2 pigs" + delete entities within {_pigs::*} diff --git a/src/test/skript/tests/bukkit/entity/EffProjectileCriticalState.sk b/src/test/skript/tests/bukkit/entity/EffProjectileCriticalState.sk new file mode 100644 index 00000000000..0644e145956 --- /dev/null +++ b/src/test/skript/tests/bukkit/entity/EffProjectileCriticalState.sk @@ -0,0 +1,45 @@ +using error catching + +test "Projectile Critical State Effect": + shoot arrow from test-location: + assert event-projectile won't crit with "A normally shot arrow shouldn't crit" + make event-projectile crit + assert event-projectile will crit with "Failed to make arrow crit" + make event-projectile not crit + assert event-projectile won't crit with "Failed to make the arrow not crit" + delete event-projectile + + shoot trident from test-location: + assert event-projectile won't crit with "A normally shot trident shouldn't crit" + make event-projectile crit + assert event-projectile will crit with "Failed to make the trident crit" + make event-projectile not crit + assert event-projectile won't crit with "Failed to make the trident not crit" + delete event-projectile + + shoot snowball from test-location: + catch runtime errors: + make event-projectile crit + set {_error} to "This projectile (snowball) is not supported. This only applies to arrows and tridents." + assert last caught runtime errors contains {_error} with "Making a snowball crit did not trigger the runtime error" + +test "Projectile Critical State Effect with multiple projectiles": + shoot arrow and arrow from test-location: + add event-projectile to {_arrows::*} + + assert {_arrows::*} won't crit with "Normally shot arrows shouldn't crit" + make {_arrows::*} crit + assert {_arrows::*} will crit with "Failed to make the 2 arrows crit" + make {_arrows::*} not crit + assert {_arrows::*} won't crit with "Failed to make the 2 arrows not crit" + delete {_arrows::*} + + shoot trident and trident from test-location: + add event-projectile to {_tridents::*} + + assert {_tridents::*} won't crit with "Normally shot tridents shouldn't crit" + make {_tridents::*} crit + assert {_tridents::*} will crit with "Failed to make the 2 tridents crit" + make {_tridents::*} not crit + assert {_tridents::*} won't crit with "Failed to make the 2 tridents not crit" + delete {_tridents::*}