From d76a086846a75e1815cad9007a5cb6c61c2c474d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 2 Jul 2013 12:29:29 +0300 Subject: [PATCH] Add Remove action to Inventory command. --- .../denizen/objects/dInventory.java | 21 ++++++++++++++++++- .../commands/item/InventoryCommand.java | 8 ++++--- .../scripts/commands/world/SignCommand.java | 6 +++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/aufdemrand/denizen/objects/dInventory.java b/src/main/java/net/aufdemrand/denizen/objects/dInventory.java index f08e51b4c8..7d8ef82416 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dInventory.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dInventory.java @@ -77,7 +77,7 @@ public Inventory getInventory() { } /** - * Adds an array of items to this inventory, + * Add an array of items to this inventory * and return the result * * @param items The array of items @@ -134,6 +134,25 @@ public int count(ItemStack item, boolean stacks) return qty; } + /** + * Remove an array of items from this inventory, + * and return the result + * + * @param items The array of items + * @return The resulting dInventory + * + */ + + public dInventory remove(ItemStack[] items) { + + for (ItemStack item : items) { + + if (item != null) inventory.removeItem(item); + } + + return this; + } + /** * Replace another inventory with this one, * cropping it if necessary so that it fits. diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/item/InventoryCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/item/InventoryCommand.java index 9228dc0756..fe219cc3f9 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/item/InventoryCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/item/InventoryCommand.java @@ -154,14 +154,16 @@ else if (destinationEntity != null) { case ADD: destination.add(origin.getContents()); return; + + // Remove origin's contents from destination + case REMOVE: + destination.remove(origin.getContents()); + return; // Clear the content of the destination inventory case CLEAR: destination.clear(); return; - - case REMOVE: - return; default: return; diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SignCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SignCommand.java index e7bf0bb87f..a22f5ae385 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SignCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SignCommand.java @@ -61,10 +61,10 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept Block sign = location.getBlock(); - if (type.name().equals("WALL_SIGN")) - sign.setType(Material.valueOf("WALL_SIGN")); + if (type.equals(Type.WALL_SIGN)) + sign.setType(Material.WALL_SIGN); else - sign.setType(Material.valueOf("SIGN_POST")); + sign.setType(Material.SIGN_POST); BlockState signState = sign.getState();