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..d5a0aaaa591 --- /dev/null +++ b/src/main/java/ch/njol/skript/conditions/CondCanPickUpItems.java @@ -0,0 +1,60 @@ +/** + * 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 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 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", + "", + "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 { + 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..6c3b3926988 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffToggleCanPickUpItems.java @@ -0,0 +1,79 @@ +/** + * 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.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; +import ch.njol.util.Kleenean; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Toggle Picking Up Items") +@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" +}) +@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|[ing] items up)"); + } + + private Expression entities; + private boolean allowPickUp; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + entities = (Expression) exprs[0]; + allowPickUp = matchedPattern == 0; + return true; + } + + @Override + protected void execute(Event event) { + for (LivingEntity entity : entities.getArray(event)) { + entity.setCanPickupItems(allowPickUp); + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + if (allowPickUp) { + return "allow " + entities.toString(event, debug) + " to pick up items"; + } else { + 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 new file mode 100644 index 00000000000..308a07261b3 --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffToggleCanPickUpItems.sk @@ -0,0 +1,7 @@ +test "entity can pick up items": + 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