From 1556c99abe035368bee7c540587f875fcb884351 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:33:11 +1000 Subject: [PATCH 01/10] Adds tame syntax --- .../njol/skript/conditions/CondIsTamed.java | 24 +++++++++++ .../java/ch/njol/skript/effects/EffTame.java | 42 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/main/java/ch/njol/skript/conditions/CondIsTamed.java create mode 100644 src/main/java/ch/njol/skript/effects/EffTame.java diff --git a/src/main/java/ch/njol/skript/conditions/CondIsTamed.java b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java new file mode 100644 index 00000000000..90f08a8143e --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java @@ -0,0 +1,24 @@ +package ch.njol.skript.conditions; + +import ch.njol.skript.conditions.base.PropertyCondition; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Tameable; + +public class CondIsTamed extends PropertyCondition { + + static { + register(CondIsTamed.class, "(tamed|domesticated)", "entities"); + } + + @Override + public boolean check(Entity entity) { + if (entity instanceof Tameable) + return ((Tameable) entity).isTamed(); + return false; + } + + @Override + protected String getPropertyName() { + return "tamed"; + } +} diff --git a/src/main/java/ch/njol/skript/effects/EffTame.java b/src/main/java/ch/njol/skript/effects/EffTame.java new file mode 100644 index 00000000000..2465b7d3dc8 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffTame.java @@ -0,0 +1,42 @@ +package ch.njol.skript.effects; + +import ch.njol.skript.Skript; +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.Entity; +import org.bukkit.entity.Tameable; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +public class EffTame extends Effect { + + static { + Skript.registerEffect(EffTame.class, "([un:(un|de)]tame|domesticate) %entities%"); + } + + private boolean tame; + private Expression entities; + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + tame = !parseResult.hasTag("un"); + entities = (Expression) exprs[0]; + return true; + } + + @Override + protected void execute(Event event) { + for (Entity entity : entities.getArray(event)) { + if (entity instanceof Tameable) + ((Tameable) entity).setTamed(tame); + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return (tame ? "tame " : "untame ") + entities.toString(event, debug); + } +} From 85bf5682468d90b9950189f43ed150c0ea45ab46 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:55:46 +1000 Subject: [PATCH 02/10] Adds test --- .../tests/syntaxes/conditions/CondIsTamed.sk | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk new file mode 100644 index 00000000000..ab2da590434 --- /dev/null +++ b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk @@ -0,0 +1,19 @@ +test "is tamed": + spawn a horse at (spawn of world "world") + set {_e} to last spawned horse + + assert {_e} is not tamed with "a normally spawned horse should not be tamed" + + tame {_e} + assert {_e} is tamed with "taming a horse should do exactly that" + + tame {_} + assert {_} is not tamed with "taming null should do nothing" + + spawn a zombie at (spawn of world "world") + set {_z} to last spawned zombie + tame {_z} + assert {_z} is not tamed with "taming an invalid entity should do nothing" + + kill value within {_e} + kill value within {_z} From 28fb9c63d1c39f3272dc20dedd8d9855786e1d76 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:37:35 +1000 Subject: [PATCH 03/10] Adds Skript doc annotations --- src/main/java/ch/njol/skript/conditions/CondIsTamed.java | 9 +++++++++ src/main/java/ch/njol/skript/effects/EffTame.java | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsTamed.java b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java index 90f08a8143e..35f9321f7c3 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsTamed.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java @@ -1,9 +1,18 @@ 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.Entity; import org.bukkit.entity.Tameable; +@Name("Is tamed") +@Description("Check if a tameable entity is tamed (horse, parrot, cat, etc.).") +@Examples({"send true if {_horse} is tamed", + "tame {_horse} if {_horse} is untamed"}) +@Since("INSERT VERSION") public class CondIsTamed extends PropertyCondition { static { diff --git a/src/main/java/ch/njol/skript/effects/EffTame.java b/src/main/java/ch/njol/skript/effects/EffTame.java index 2465b7d3dc8..7fa3d694fb3 100644 --- a/src/main/java/ch/njol/skript/effects/EffTame.java +++ b/src/main/java/ch/njol/skript/effects/EffTame.java @@ -1,6 +1,10 @@ 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; @@ -10,6 +14,11 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; +@Name("Tame / Untame") +@Description("Tame a tameable entity (horse, parrot, cat, etc.).") +@Examples({"tame {_horse}", + "untame {_horse}"}) +@Since("INSERT VERSION") public class EffTame extends Effect { static { From 755f35a2321f5d52bf770124469ade7a73ca0153 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Wed, 3 Jul 2024 17:27:16 +1000 Subject: [PATCH 04/10] NotSoDelayed Suggestions Co-authored-by: NotSoDelayed <72163224+NotSoDelayed@users.noreply.github.com> --- src/main/java/ch/njol/skript/conditions/CondIsTamed.java | 9 ++++++--- src/main/java/ch/njol/skript/effects/EffTame.java | 8 +++++--- src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsTamed.java b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java index 35f9321f7c3..366d81e64be 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsTamed.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java @@ -8,10 +8,12 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Tameable; -@Name("Is tamed") +@Name("Is Tamed") @Description("Check if a tameable entity is tamed (horse, parrot, cat, etc.).") -@Examples({"send true if {_horse} is tamed", - "tame {_horse} if {_horse} is untamed"}) +@Examples({ + "send true if {_horse} is tamed", + "tame {_horse} if {_horse} is untamed" +}) @Since("INSERT VERSION") public class CondIsTamed extends PropertyCondition { @@ -30,4 +32,5 @@ public boolean check(Entity entity) { protected String getPropertyName() { return "tamed"; } + } diff --git a/src/main/java/ch/njol/skript/effects/EffTame.java b/src/main/java/ch/njol/skript/effects/EffTame.java index 7fa3d694fb3..7af0e549d9e 100644 --- a/src/main/java/ch/njol/skript/effects/EffTame.java +++ b/src/main/java/ch/njol/skript/effects/EffTame.java @@ -16,8 +16,10 @@ @Name("Tame / Untame") @Description("Tame a tameable entity (horse, parrot, cat, etc.).") -@Examples({"tame {_horse}", - "untame {_horse}"}) +@Examples({ + "tame {_horse}", + "untame {_horse}" +}) @Since("INSERT VERSION") public class EffTame extends Effect { @@ -28,8 +30,8 @@ public class EffTame extends Effect { private boolean tame; private Expression entities; - @SuppressWarnings("unchecked") @Override + @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { tame = !parseResult.hasTag("un"); entities = (Expression) exprs[0]; diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk index ab2da590434..68198982801 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk @@ -17,3 +17,4 @@ test "is tamed": kill value within {_e} kill value within {_z} + From da4199b827aa2c02d00f3d450a6ec54ca1cc5ae8 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Wed, 3 Jul 2024 17:33:23 +1000 Subject: [PATCH 05/10] Suggestions - Removed 'de' as an option to untame a tameable entity - Adds untaming to test - Deletes value within variables instead of killing --- src/main/java/ch/njol/skript/effects/EffTame.java | 2 +- src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffTame.java b/src/main/java/ch/njol/skript/effects/EffTame.java index 7af0e549d9e..ec7128dbded 100644 --- a/src/main/java/ch/njol/skript/effects/EffTame.java +++ b/src/main/java/ch/njol/skript/effects/EffTame.java @@ -24,7 +24,7 @@ public class EffTame extends Effect { static { - Skript.registerEffect(EffTame.class, "([un:(un|de)]tame|domesticate) %entities%"); + Skript.registerEffect(EffTame.class, "[:un](tame|domesticate) %entities%"); } private boolean tame; diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk index 68198982801..823db46b540 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk @@ -7,6 +7,9 @@ test "is tamed": tame {_e} assert {_e} is tamed with "taming a horse should do exactly that" + untame {_e} + assert {_e} is not tamed with "untaming a horse should do exactly that" + tame {_} assert {_} is not tamed with "taming null should do nothing" @@ -15,6 +18,5 @@ test "is tamed": tame {_z} assert {_z} is not tamed with "taming an invalid entity should do nothing" - kill value within {_e} - kill value within {_z} - + delete value within {_e} + delete value within {_z} From 919aefcc61183aa630cb81750276ec6a0ad31c18 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Wed, 3 Jul 2024 21:29:26 +1000 Subject: [PATCH 06/10] Fixes test --- src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk index 823db46b540..5035038a2d6 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk @@ -18,5 +18,5 @@ test "is tamed": tame {_z} assert {_z} is not tamed with "taming an invalid entity should do nothing" - delete value within {_e} - delete value within {_z} + kill value within {_e} + kill value within {_z} From 8548ecf1d15d3754cd76308350231c0690343735 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:55:10 +1000 Subject: [PATCH 07/10] Changed tests slightly --- .../tests/syntaxes/conditions/CondIsTamed.sk | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk index 5035038a2d6..82f092e5cc4 100644 --- a/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk +++ b/src/test/skript/tests/syntaxes/conditions/CondIsTamed.sk @@ -1,6 +1,8 @@ test "is tamed": - spawn a horse at (spawn of world "world") - set {_e} to last spawned horse + spawn a horse at (spawn of world "world"): + set {_e} to entity + spawn an adult zombie at (spawn of world "world"): + set {_z} to entity assert {_e} is not tamed with "a normally spawned horse should not be tamed" @@ -11,12 +13,9 @@ test "is tamed": assert {_e} is not tamed with "untaming a horse should do exactly that" tame {_} - assert {_} is not tamed with "taming null should do nothing" - - spawn a zombie at (spawn of world "world") - set {_z} to last spawned zombie tame {_z} + assert {_} is not tamed with "taming null should do nothing" assert {_z} is not tamed with "taming an invalid entity should do nothing" - kill value within {_e} - kill value within {_z} + delete entity within {_e} + delete entity within {_z} From 1f58aa768daafdfc2f1d86bc01fcf702654c6d28 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:56:08 +1000 Subject: [PATCH 08/10] Auggestion Co-authored-by: NotSoDelayed <72163224+NotSoDelayed@users.noreply.github.com> --- src/main/java/ch/njol/skript/effects/EffTame.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ch/njol/skript/effects/EffTame.java b/src/main/java/ch/njol/skript/effects/EffTame.java index ec7128dbded..c499ccf535b 100644 --- a/src/main/java/ch/njol/skript/effects/EffTame.java +++ b/src/main/java/ch/njol/skript/effects/EffTame.java @@ -50,4 +50,5 @@ protected void execute(Event event) { public String toString(@Nullable Event event, boolean debug) { return (tame ? "tame " : "untame ") + entities.toString(event, debug); } + } From a0dd2f922d5bc901a5eae21f29ec10610270d036 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Mon, 22 Jul 2024 00:32:47 +1000 Subject: [PATCH 09/10] Suggestions --- src/main/java/ch/njol/skript/conditions/CondIsTamed.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsTamed.java b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java index 366d81e64be..a3e342deef6 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsTamed.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsTamed.java @@ -23,9 +23,7 @@ public class CondIsTamed extends PropertyCondition { @Override public boolean check(Entity entity) { - if (entity instanceof Tameable) - return ((Tameable) entity).isTamed(); - return false; + return (entity instanceof Tameable) && ((Tameable) entity).isTamed(); } @Override From 04035c94b2f4ae8fb339e16ccd57666902750117 Mon Sep 17 00:00:00 2001 From: cheeezburga <47320303+cheeezburga@users.noreply.github.com> Date: Mon, 22 Jul 2024 00:34:24 +1000 Subject: [PATCH 10/10] Changes to JetBrains nullable annotation --- src/main/java/ch/njol/skript/effects/EffTame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffTame.java b/src/main/java/ch/njol/skript/effects/EffTame.java index c499ccf535b..400f9e27d39 100644 --- a/src/main/java/ch/njol/skript/effects/EffTame.java +++ b/src/main/java/ch/njol/skript/effects/EffTame.java @@ -12,7 +12,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Tameable; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; @Name("Tame / Untame") @Description("Tame a tameable entity (horse, parrot, cat, etc.).")