From 02307a6cfde5d0b2254f96c3d433891eabe22877 Mon Sep 17 00:00:00 2001 From: sovde Date: Mon, 16 Jan 2023 20:51:08 -0500 Subject: [PATCH 1/7] CanPickUpItems Eff + Cond + Test --- .../skript/conditions/CondCanPickUpItems.java | 44 +++++++++++++ .../effects/EffToggleCanPickUpItems.java | 63 +++++++++++++++++++ .../effects/EffToggleCanPickUpItems.sk | 8 +++ 3 files changed, 115 insertions(+) create mode 100644 src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java create mode 100644 src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java create mode 100644 src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java new file mode 100644 index 00000000000..fa45084624e --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java @@ -0,0 +1,44 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.conditions; + +import ch.njol.skript.conditions.base.PropertyCondition; +import org.bukkit.entity.LivingEntity; + +public class CondCanPickUpItems extends PropertyCondition { + + static { + register(CondCanPickUpItems.class, PropertyType.CAN, "pick (up items|items up)", "livingentities"); + } + + @Override + public boolean check(LivingEntity livingEntity) { + return livingEntity.getCanPickupItems(); + } + + @Override + protected PropertyType getPropertyType() { + return PropertyType.CAN; + } + + @Override + protected String getPropertyName() { + return "pick up items"; + } +} diff --git a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java new file mode 100644 index 00000000000..22b5e3bdb49 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java @@ -0,0 +1,63 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +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; +import ch.njol.util.Kleenean; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +public class EffToggleCanPickUpItems extends Effect { + + static { + Skript.registerEffect(EffToggleCanPickUpItems.class, + "allow %livingentities% to pick (up items|items up)", + "[negated:(don't|do not)] let %livingentities% pick (up items|items up)", + "(forbid|disallow) %livingentities% (from|to) pick[ing] (up items|items up)"); + } + + private Expression entityExpr; + private boolean allowPickUp; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + entityExpr = (Expression) exprs[0]; + allowPickUp = !(matchedPattern == 2 || parseResult.hasTag("negated")); + return true; + } + + + @Override + protected void execute(Event event) { + for (LivingEntity entity : entityExpr.getArray(event)) + entity.setCanPickupItems(allowPickUp); + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + if (allowPickUp) + return "allow " + entityExpr.toString(event, debug) + " to pick up items"; + else + return "forbid " + entityExpr.toString(event, debug) + " from picking up items"; + } +} diff --git a/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk new file mode 100644 index 00000000000..607147e513d --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk @@ -0,0 +1,8 @@ +test "entity can pick up items": + spawn a zombie at spawn of "world" + set {_zombie} to last spawned zombie + let {_zombie} pick up items + assert {_zombie} can pick up items with "failed to allow zombie to pick up items" + forbid {_zombie} from picking items up + assert {_zombie} can't pick up items with "failed to disallow zombie to pick up items" + delete {_zombie} From 08791088f43b72c37f2dbeaf6f15065d39f778e8 Mon Sep 17 00:00:00 2001 From: sovde Date: Tue, 17 Jan 2023 11:40:52 -0500 Subject: [PATCH 2/7] Requested Changes --- .../skript/conditions/CondCanPickUpItems.java | 1 + .../skript/effects/EffToggleCanPickUpItems.java | 16 +++++++++------- .../syntaxes/effects/EffToggleCanPickUpItems.sk | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java index fa45084624e..0fe34444f7f 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java @@ -41,4 +41,5 @@ protected PropertyType getPropertyType() { protected String getPropertyName() { return "pick up items"; } + } diff --git a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java index 22b5e3bdb49..43ff59a8491 100644 --- a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java +++ b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java @@ -21,7 +21,7 @@ import ch.njol.skript.Skript; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Event; @@ -32,7 +32,6 @@ public class EffToggleCanPickUpItems extends Effect { static { Skript.registerEffect(EffToggleCanPickUpItems.class, "allow %livingentities% to pick (up items|items up)", - "[negated:(don't|do not)] let %livingentities% pick (up items|items up)", "(forbid|disallow) %livingentities% (from|to) pick[ing] (up items|items up)"); } @@ -40,24 +39,27 @@ public class EffToggleCanPickUpItems extends Effect { private boolean allowPickUp; @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { entityExpr = (Expression) exprs[0]; - allowPickUp = !(matchedPattern == 2 || parseResult.hasTag("negated")); + allowPickUp = matchedPattern == 0; return true; } @Override protected void execute(Event event) { - for (LivingEntity entity : entityExpr.getArray(event)) + for (LivingEntity entity : entityExpr.getArray(event)) { entity.setCanPickupItems(allowPickUp); + } } @Override public String toString(@Nullable Event event, boolean debug) { - if (allowPickUp) + if (allowPickUp) { return "allow " + entityExpr.toString(event, debug) + " to pick up items"; - else + } else { return "forbid " + entityExpr.toString(event, debug) + " from picking up items"; + } } + } diff --git a/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk index 607147e513d..931b7044d0e 100644 --- a/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk +++ b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk @@ -5,4 +5,4 @@ test "entity can pick up items": assert {_zombie} can pick up items with "failed to allow zombie to pick up items" forbid {_zombie} from picking items up assert {_zombie} can't pick up items with "failed to disallow zombie to pick up items" - delete {_zombie} + delete random entity of {_zombie} From ec95b5abfa040095ee9c36a40646efcf23d17d31 Mon Sep 17 00:00:00 2001 From: sovde Date: Tue, 17 Jan 2023 11:56:17 -0500 Subject: [PATCH 3/7] whoops! --- .../skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk index 931b7044d0e..7788de0776f 100644 --- a/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk +++ b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk @@ -1,7 +1,7 @@ test "entity can pick up items": spawn a zombie at spawn of "world" set {_zombie} to last spawned zombie - let {_zombie} pick up items + allow {_zombie} to pick up items assert {_zombie} can pick up items with "failed to allow zombie to pick up items" forbid {_zombie} from picking items up assert {_zombie} can't pick up items with "failed to disallow zombie to pick up items" From ff41a2fe934258abe490198bec9f1021fd5f98cb Mon Sep 17 00:00:00 2001 From: sovdeeth Date: Wed, 25 Jan 2023 12:40:23 -0500 Subject: [PATCH 4/7] Forgot Documentation --- .../skript/conditions/CondCanPickUpItems.java | 15 +++++++++++++++ .../skript/effects/EffToggleCanPickUpItems.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java index 0fe34444f7f..687bc0b11ec 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java @@ -19,8 +19,23 @@ 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.LivingEntity; +@Name("Can Pick Up Items") +@Description("Whether an entity is able to pick up items or not.") +@Examples({ + "if player can pick items up:", + "\tsend \"You can pick up items!\" to player", + "", + "on drop:", + "\tif player can't pick up items:", + "\t\tsend \"Be careful, you won't be able to pick that up!\" to player" +}) +@Since("INSERT VERSION") public class CondCanPickUpItems extends PropertyCondition { static { diff --git a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java index 43ff59a8491..ee66a74ad83 100644 --- a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java +++ b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java @@ -19,6 +19,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; @@ -27,6 +31,17 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; +@Name("Toggle Picking Up Items") +@Description("Determines whether an entity is able to pick up items or not.") +@Examples({ + "forbid player from picking up items", + "send \"You can no longer pick up items!\" to player", + "", + "on drop:", + "\tif player can't pick up items:", + "\t\tallow player to pick up items" +}) +@Since("INSERT VERSION") public class EffToggleCanPickUpItems extends Effect { static { From e74234b7a118fe265af38f521f69aff83abc3400 Mon Sep 17 00:00:00 2001 From: Sovde Date: Sat, 11 Feb 2023 19:08:27 -0500 Subject: [PATCH 5/7] Requested changes --- .../skript/conditions/CondCanPickUpItems.java | 4 ++-- .../effects/EffToggleCanPickUpItems.java | 20 +++++++++---------- .../effects/EffToggleCanPickUpItems.sk | 13 ++++++------ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java index 687bc0b11ec..d5a0aaaa591 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java +++ b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java @@ -26,7 +26,7 @@ import org.bukkit.entity.LivingEntity; @Name("Can Pick Up Items") -@Description("Whether an entity is able to pick up items or not.") +@Description("Whether living entities are able to pick up items off the ground or not.") @Examples({ "if player can pick items up:", "\tsend \"You can pick up items!\" to player", @@ -39,7 +39,7 @@ public class CondCanPickUpItems extends PropertyCondition { static { - register(CondCanPickUpItems.class, PropertyType.CAN, "pick (up items|items up)", "livingentities"); + register(CondCanPickUpItems.class, PropertyType.CAN, "pick([ ]up items| items up)", "livingentities"); } @Override diff --git a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java index ee66a74ad83..fe2e7b7e40f 100644 --- a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java +++ b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java @@ -32,30 +32,30 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Toggle Picking Up Items") -@Description("Determines whether an entity is able to pick up items or not.") +@Description("Determines whether living entities are able to pick up items or not") @Examples({ "forbid player from picking up items", "send \"You can no longer pick up items!\" to player", "", "on drop:", - "\tif player can't pick up items:", - "\t\tallow player to pick up items" + "\tif player can't pick up items:", + "\t\tallow player to pick up items" }) @Since("INSERT VERSION") public class EffToggleCanPickUpItems extends Effect { static { Skript.registerEffect(EffToggleCanPickUpItems.class, - "allow %livingentities% to pick (up items|items up)", - "(forbid|disallow) %livingentities% (from|to) pick[ing] (up items|items up)"); + "allow %livingentities% to pick([ ]up items| items up)", + "(forbid|disallow) %livingentities% (from|to) pick[ing]([ ]up items| items up)"); } - private Expression entityExpr; + private Expression entities; private boolean allowPickUp; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - entityExpr = (Expression) exprs[0]; + entities = (Expression) exprs[0]; allowPickUp = matchedPattern == 0; return true; } @@ -63,7 +63,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { - for (LivingEntity entity : entityExpr.getArray(event)) { + for (LivingEntity entity : entities.getArray(event)) { entity.setCanPickupItems(allowPickUp); } } @@ -71,9 +71,9 @@ protected void execute(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { if (allowPickUp) { - return "allow " + entityExpr.toString(event, debug) + " to pick up items"; + return "allow " + entities.toString(event, debug) + " to pick up items"; } else { - return "forbid " + entityExpr.toString(event, debug) + " from picking up items"; + return "forbid " + entities.toString(event, debug) + " from picking up items"; } } diff --git a/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk index 7788de0776f..3c19244aa8e 100644 --- a/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk +++ b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk @@ -1,8 +1,7 @@ test "entity can pick up items": - spawn a zombie at spawn of "world" - set {_zombie} to last spawned zombie - allow {_zombie} to pick up items - assert {_zombie} can pick up items with "failed to allow zombie to pick up items" - forbid {_zombie} from picking items up - assert {_zombie} can't pick up items with "failed to disallow zombie to pick up items" - delete random entity of {_zombie} + spawn a zombie at spawn of "world": + allow event-entity to pick up items + assert event-entity can pick up items with "failed to allow zombie to pick up items" + forbid event-entity from picking items up + assert event-entity can't pick up items with "failed to disallow zombie to pick up items" + delete event-entity \ No newline at end of file From 497f74f960379f7d8167f99f23cce17a6ea35b78 Mon Sep 17 00:00:00 2001 From: sovdee Date: Fri, 17 Feb 2023 13:08:33 -0500 Subject: [PATCH 6/7] Update src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java Co-authored-by: _tud --- .../java/ch/njol/skript/effects/EffToggleCanPickUpItems.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java index fe2e7b7e40f..1567d6050b5 100644 --- a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java +++ b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java @@ -39,7 +39,7 @@ "", "on drop:", "\tif player can't pick up items:", - "\t\tallow player to pick up items" + "\t\tallow player to pick up items" }) @Since("INSERT VERSION") public class EffToggleCanPickUpItems extends Effect { From 4403a1cb27d9c8de59af85727e6e7f76b0dc2221 Mon Sep 17 00:00:00 2001 From: Ethan Sovde Date: Fri, 17 Feb 2023 22:34:23 -0500 Subject: [PATCH 7/7] Requested changes --- .../java/ch/njol/skript/effects/EffToggleCanPickUpItems.java | 3 +-- .../skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java index 1567d6050b5..6c3b3926988 100644 --- a/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java +++ b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java @@ -47,7 +47,7 @@ public class EffToggleCanPickUpItems extends Effect { static { Skript.registerEffect(EffToggleCanPickUpItems.class, "allow %livingentities% to pick([ ]up items| items up)", - "(forbid|disallow) %livingentities% (from|to) pick[ing]([ ]up items| items up)"); + "(forbid|disallow) %livingentities% (from|to) pick([ing | ]up items|[ing] items up)"); } private Expression entities; @@ -60,7 +60,6 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye return true; } - @Override protected void execute(Event event) { for (LivingEntity entity : entities.getArray(event)) { diff --git a/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk index 3c19244aa8e..308a07261b3 100644 --- a/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk +++ b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk @@ -4,4 +4,4 @@ test "entity can pick up items": assert event-entity can pick up items with "failed to allow zombie to pick up items" forbid event-entity from picking items up assert event-entity can't pick up items with "failed to disallow zombie to pick up items" - delete event-entity \ No newline at end of file + delete event-entity