From 996a0e914a6be4276603f9bfebf389c6d30f8fd2 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:16:37 +1000 Subject: [PATCH 1/5] Update CondIsCharged --- .../njol/skript/conditions/CondIsCharged.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsCharged.java b/src/main/java/ch/njol/skript/conditions/CondIsCharged.java index cf5992ef89b..dc43dace85d 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsCharged.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsCharged.java @@ -18,36 +18,38 @@ */ package ch.njol.skript.conditions; -import org.bukkit.entity.Creeper; -import org.bukkit.entity.LivingEntity; - 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.Creeper; +import org.bukkit.entity.Entity; +import org.bukkit.entity.WitherSkull; @Name("Is Charged") -@Description("Checks if a creeper is charged (powered).") +@Description("Checks if a creeper or wither skull is charged (powered).") @Examples({"if the last spawned creeper is charged:", - "\tbroadcast \"A charged creeper is at %location of last spawned creeper%\""}) -@Since("2.5") -public class CondIsCharged extends PropertyCondition { - + "\tbroadcast \"A charged creeper is at %location of last spawned creeper%\""}) +@Since("2.5, INSERT VERSION (wither skulls)") +public class CondIsCharged extends PropertyCondition { + static { - register(CondIsCharged.class, "(charged|powered)", "livingentities"); + register(CondIsCharged.class, "(charged|powered)", "entities"); } - + @Override - public boolean check(final LivingEntity e) { - if (e instanceof Creeper) - return ((Creeper) e).isPowered(); + public boolean check(Entity entity) { + if (entity instanceof Creeper) + return ((Creeper) entity).isPowered(); + else if (entity instanceof WitherSkull) + return ((WitherSkull) entity).isCharged(); return false; } - + @Override protected String getPropertyName() { return "charged"; } - + } From 28f1d87a87d29fd953b6e27263e03541f0e19c25 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Fri, 5 Jul 2024 02:54:53 +1000 Subject: [PATCH 2/5] Adds new test and updates effect - Also deletes old test --- .../{EffChargeCreeper.java => EffCharge.java} | 42 +++++++++++-------- .../syntaxes/conditions/CondIsCharged.sk | 31 ++++++++++++++ .../syntaxes/effects/EffChargeCreeper.sk | 8 ---- 3 files changed, 55 insertions(+), 26 deletions(-) rename src/main/java/ch/njol/skript/effects/{EffChargeCreeper.java => EffCharge.java} (62%) create mode 100644 src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk delete mode 100644 src/test/skript/tests/syntaxes/effects/EffChargeCreeper.sk diff --git a/src/main/java/ch/njol/skript/effects/EffChargeCreeper.java b/src/main/java/ch/njol/skript/effects/EffCharge.java similarity index 62% rename from src/main/java/ch/njol/skript/effects/EffChargeCreeper.java rename to src/main/java/ch/njol/skript/effects/EffCharge.java index 03a1fdaebdc..2ddac73c353 100644 --- a/src/main/java/ch/njol/skript/effects/EffChargeCreeper.java +++ b/src/main/java/ch/njol/skript/effects/EffCharge.java @@ -27,48 +27,54 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; - import org.bukkit.entity.Creeper; -import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Entity; +import org.bukkit.entity.WitherSkull; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; -@Name("Charge Creeper") -@Description("Charges or uncharges a creeper. A creeper is charged when it has been struck by lightning.") -@Examples({"on spawn of creeper:", - "\tcharge the event-entity"}) +@Name("Charge") +@Description("Charges or uncharges a creeper or wither skull. A creeper is charged when it has been struck by lightning.") +@Examples({ + "on spawn of creeper:", + "\tcharge the event-entity" +}) @Since("2.5") -public class EffChargeCreeper extends Effect { +public class EffCharge extends Effect { static { - Skript.registerEffect(EffChargeCreeper.class, - "make %livingentities% [a[n]] (charged|powered|1¦((un|non[-])charged|(un|non[-])powered)) [creeper[s]]", - "(charge|power|1¦(uncharge|unpower)) %livingentities%"); + Skript.registerEffect(EffCharge.class, + "make %entities% [un:(un|not |non[-| ])](charged|powered)", + "[:un](charge|power) %entities%"); } @SuppressWarnings("null") - private Expression entities; + private Expression entities; private boolean charge; @SuppressWarnings({"unchecked", "null"}) @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - entities = (Expression) exprs[0]; - charge = parseResult.mark != 1; + entities = (Expression) exprs[0]; + charge = !parseResult.hasTag("un"); return true; } @Override - protected void execute(Event e) { - for (LivingEntity le : entities.getArray(e)) { - if (le instanceof Creeper) - ((Creeper) le).setPowered(charge); + protected void execute(Event event) { + for (Entity entity : entities.getArray(event)) { + if (entity instanceof Creeper) { + ((Creeper) entity).setPowered(charge); + } else if (entity instanceof WitherSkull) { + ((WitherSkull) entity).setCharged(charge); + } } } @Override public String toString(@Nullable Event e, boolean debug) { - return "make " + entities.toString(e, debug) + (charge == true ? " charged" : " not charged"); + return "make " + entities.toString(e, debug) + (charge ? " charged" : " not charged"); } + } diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk b/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk new file mode 100644 index 00000000000..ba6034c9a24 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk @@ -0,0 +1,31 @@ +test "is charged": + spawn a creeper at (spawn of world "world"): + set {_e} to entity + spawn a wither skull at (spawn of world "world") ~ vector(0,10,0): + set {_w} to entity + + assert {_e} is not charged with "a normally spawned creeper should not be charged" + assert {_w} is not charged with "a normally spawned wither skull should not be charged" + + charge {_e} + charge {_w} + assert {_e} is charged with "charging a creeper should do exactly that" + assert {_w} is charged with "charging a wither skull should do exactly that" + + uncharge {_e} + uncharge {_w} + assert {_e} is not charged with "uncharging a creeper should do exactly that" + assert {_w} is not charged with "uncharging a wither skull should do exactly that" + + spawn an adult zombie at (spawn of world "world"): + set {_z} to entity + + assert {_z} is not charged with "a non-creeper/wither skull should never be charged" + charge {_z} + assert {_z} is not charged with "charging a non-creeper/wither skull should do nothing" + uncharge {_z} + assert {_z} is not charged with "uncharging a non-creeper/wither skull should do nothing" + + delete entity within {_e} + delete entity within {_w} + delete entity within {_z} diff --git a/src/test/skript/tests/syntaxes/effects/EffChargeCreeper.sk b/src/test/skript/tests/syntaxes/effects/EffChargeCreeper.sk deleted file mode 100644 index 47e9e8016af..00000000000 --- a/src/test/skript/tests/syntaxes/effects/EffChargeCreeper.sk +++ /dev/null @@ -1,8 +0,0 @@ -test "charge creeper effect/condition": - spawn a creeper at spawn of world "world" - assert last spawned creeper is not charged with "spawning a normal creeper shouldn't spawn a charged one" - charge the last spawned creeper - assert last spawned creeper is charged with "a creeper should be charged after it is set as charged" - uncharge the last spawned creeper - assert last spawned creeper is not charged with "uncharging a charged creeper should uncharge it" - delete last spawned creeper From 5ba53c4e7b66bf672aeca52edb074f3be794095e Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Sun, 7 Jul 2024 07:50:00 +1000 Subject: [PATCH 3/5] Fixes test - Wither skull wasn't spawning as I thought it was, changed to shoot effect --- src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk b/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk index ba6034c9a24..1362a3196a5 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsCharged.sk @@ -1,8 +1,8 @@ test "is charged": spawn a creeper at (spawn of world "world"): set {_e} to entity - spawn a wither skull at (spawn of world "world") ~ vector(0,10,0): - set {_w} to entity + shoot a wither skull from {_e} + set {_w} to last shot entity assert {_e} is not charged with "a normally spawned creeper should not be charged" assert {_w} is not charged with "a normally spawned wither skull should not be charged" From d231cbaaf1fd1f5913508ca44cee82d758005293 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Mon, 15 Jul 2024 00:34:08 +1000 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> --- src/main/java/ch/njol/skript/effects/EffCharge.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffCharge.java b/src/main/java/ch/njol/skript/effects/EffCharge.java index 2ddac73c353..38364fc2f6a 100644 --- a/src/main/java/ch/njol/skript/effects/EffCharge.java +++ b/src/main/java/ch/njol/skript/effects/EffCharge.java @@ -33,11 +33,11 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; -@Name("Charge") +@Name("Charge Entity") @Description("Charges or uncharges a creeper or wither skull. A creeper is charged when it has been struck by lightning.") @Examples({ "on spawn of creeper:", - "\tcharge the event-entity" + "\tcharge the event-entity" }) @Since("2.5") public class EffCharge extends Effect { From c8b60c33e696f32b1abe24ce70eadc7216152096 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Mon, 22 Jul 2024 01:10:33 +1000 Subject: [PATCH 5/5] Suggestions --- src/main/java/ch/njol/skript/effects/EffCharge.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffCharge.java b/src/main/java/ch/njol/skript/effects/EffCharge.java index 38364fc2f6a..54cccdca807 100644 --- a/src/main/java/ch/njol/skript/effects/EffCharge.java +++ b/src/main/java/ch/njol/skript/effects/EffCharge.java @@ -31,7 +31,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.WitherSkull; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; @Name("Charge Entity") @Description("Charges or uncharges a creeper or wither skull. A creeper is charged when it has been struck by lightning.") @@ -73,8 +73,8 @@ protected void execute(Event event) { } @Override - public String toString(@Nullable Event e, boolean debug) { - return "make " + entities.toString(e, debug) + (charge ? " charged" : " not charged"); + public String toString(@Nullable Event event, boolean debug) { + return "make " + entities.toString(event, debug) + (charge ? " charged" : " not charged"); } }