From 621535138d9df6d12f5642db786eba0d2b4697c9 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Sat, 5 Jul 2025 09:35:00 -0600 Subject: [PATCH 1/5] Make has potion effect types optional --- .../njol/skript/conditions/CondHasPotion.java | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java index b71b6298d27..9bc402dee6d 100644 --- a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java +++ b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java @@ -17,26 +17,33 @@ import org.jetbrains.annotations.Nullable; @Name("Has Potion") -@Description("Checks whether the given living entities have specific potion effects.") -@Examples({"if player has potion speed:", +@Description("Checks whether the given living entities have potion effects.") +@Examples({ + "if player has potion speed:", "\tsend \"You are sonic!\"", "", "if all players have potion effects speed and haste:", - "\tbroadcast \"You are ready to MINE!\""}) + "\tbroadcast \"You are ready to MINE!\"" +}) @Since("2.6.1") public class CondHasPotion extends Condition { static { - Skript.registerCondition(CondHasPotion.class, - "%livingentities% (has|have) potion[s] [effect[s]] %potioneffecttypes%", - "%livingentities% (doesn't|does not|do not|don't) have potion[s] [effect[s]] %potioneffecttypes%"); + Skript.registerCondition( + CondHasPotion.class, + PropertyCondition.getPatterns( + PropertyType.HAVE, + "livingentities", + "[any] potion[s] [effect[s]] [%-potioneffecttypes%]" + ) + ); } - - private Expression livingEntities; + private Expression potionEffects; + private Expression livingEntities; @Override - @SuppressWarnings({"unchecked", "null"}) + @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { livingEntities = (Expression) exprs[0]; potionEffects = (Expression) exprs[1]; @@ -45,17 +52,19 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } @Override - public boolean check(Event e) { - return livingEntities.check(e, - livingEntity -> potionEffects.check(e, - livingEntity::hasPotionEffect - ), isNegated()); + public boolean check(Event event) { + if (potionEffects == null) { + return livingEntities.check(event, entity -> !isNegated(), isNegated()); + } + return livingEntities.check(event, + entity -> potionEffects.check(event, entity::hasPotionEffect), + isNegated()); } @Override - public String toString(@Nullable Event e, boolean debug) { - return PropertyCondition.toString(this, PropertyType.HAVE, e, debug, livingEntities, - "potion " + potionEffects.toString(e, debug)); + public String toString(@Nullable Event event, boolean debug) { + String effects = (potionEffects == null) ? "any potion" : "potion " + potionEffects.toString(event, debug); + return PropertyCondition.toString(this, PropertyType.HAVE, event, debug, livingEntities, effects); } } From 08b153e7131afa1f82986ef360788894ab4a74d9 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Sat, 5 Jul 2025 10:14:36 -0600 Subject: [PATCH 2/5] Add tests --- src/main/java/ch/njol/skript/conditions/CondHasPotion.java | 4 ++-- src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java index 9bc402dee6d..9a51f86244a 100644 --- a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java +++ b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java @@ -33,8 +33,8 @@ public class CondHasPotion extends Condition { CondHasPotion.class, PropertyCondition.getPatterns( PropertyType.HAVE, - "livingentities", - "[any] potion[s] [effect[s]] [%-potioneffecttypes%]" + "([any] potion effect[s]|potion[s] [effect[s]] %-potioneffecttypes%)", + "livingentities" ) ); } diff --git a/src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk b/src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk new file mode 100644 index 00000000000..eebfe2b873e --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk @@ -0,0 +1,6 @@ +test "has potion": + spawn a pig at test-location + apply ambient strength of tier 5 to last spawned pig for 10 seconds + + assert last spawned pig has any potion effect with "pig has no potion effect" + assert last spawned pig has potion effect strength with "pig has strength potion effect" From 44d611c664bccc095bc21a0b7c2b25e94256a5a3 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Sat, 5 Jul 2025 10:15:45 -0600 Subject: [PATCH 3/5] Make has potion effect types optional --- src/main/java/ch/njol/skript/conditions/CondHasPotion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java index 9a51f86244a..684d8c84e1d 100644 --- a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java +++ b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java @@ -63,7 +63,7 @@ public boolean check(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - String effects = (potionEffects == null) ? "any potion" : "potion " + potionEffects.toString(event, debug); + String effects = (potionEffects == null) ? "any potion effect" : "potion " + potionEffects.toString(event, debug); return PropertyCondition.toString(this, PropertyType.HAVE, event, debug, livingEntities, effects); } From 0b60a8af4f5b7d02590fb622931cee53b8692fc6 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Sat, 5 Jul 2025 16:26:45 -0600 Subject: [PATCH 4/5] Changes requested --- src/main/java/ch/njol/skript/conditions/CondHasPotion.java | 4 +++- src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java index 684d8c84e1d..7201c6c6987 100644 --- a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java +++ b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java @@ -11,6 +11,8 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; + +import org.bukkit.Registry; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; import org.bukkit.potion.PotionEffectType; @@ -54,7 +56,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public boolean check(Event event) { if (potionEffects == null) { - return livingEntities.check(event, entity -> !isNegated(), isNegated()); + return livingEntities.check(event, entity -> !entity.getActivePotionEffects().isEmpty(), isNegated()); } return livingEntities.check(event, entity -> potionEffects.check(event, entity::hasPotionEffect), diff --git a/src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk b/src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk index eebfe2b873e..eee7b58b5fc 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondHasPotion.sk @@ -1,6 +1,8 @@ test "has potion": - spawn a pig at test-location + spawn a pig at event-location apply ambient strength of tier 5 to last spawned pig for 10 seconds assert last spawned pig has any potion effect with "pig has no potion effect" assert last spawned pig has potion effect strength with "pig has strength potion effect" + + clear last spawned pig From c3aec07e0130fd308d831dfe38db4130c822e39f Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Sat, 5 Jul 2025 16:27:25 -0600 Subject: [PATCH 5/5] Changes requested --- .../ch/njol/skript/conditions/CondHasPotion.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java index 7201c6c6987..cae83eafc60 100644 --- a/src/main/java/ch/njol/skript/conditions/CondHasPotion.java +++ b/src/main/java/ch/njol/skript/conditions/CondHasPotion.java @@ -4,7 +4,7 @@ import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.conditions.base.PropertyCondition.PropertyType; import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Example; import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Condition; @@ -12,7 +12,6 @@ import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; -import org.bukkit.Registry; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; import org.bukkit.potion.PotionEffectType; @@ -20,13 +19,12 @@ @Name("Has Potion") @Description("Checks whether the given living entities have potion effects.") -@Examples({ - "if player has potion speed:", - "\tsend \"You are sonic!\"", - "", - "if all players have potion effects speed and haste:", - "\tbroadcast \"You are ready to MINE!\"" -}) +@Example(""" + if player has potion speed: + send "You are sonic!" + if all players have potion effects speed and haste: + broadcast "You are ready to MINE!" +""") @Since("2.6.1") public class CondHasPotion extends Condition {