Skip to content

Commit

Permalink
Add Fill action to Inventory command.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Jul 2, 2013
1 parent 43aa640 commit 03d0f8f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dInventory.java
Expand Up @@ -134,6 +134,23 @@ public int count(ItemStack item, boolean stacks)
return qty;
}

/**
* Fill an inventory with an array of items by
* continuing to add the items to it over and
* over until there is no more room
*
* @param item The array of items
* @return The resulting dInventory
*
*/

public dInventory fill(ItemStack[] items) {

while (this.count(null, false) != this.add(items).count(null, false));

return this;
}

/**
* Remove an array of items from this inventory,
* and return the result
Expand Down
Expand Up @@ -166,7 +166,7 @@ public void registerCoreMembers() {
"IF", "if [comparable] (!)(operator) (compared_to) (bridge) (...) [command] (else) (command) +--> see documentation.", 2);

registerCoreMember(InventoryCommand.class,
"INVENTORY", "inventory [open/copy/move/swap/add/remove/clear] (origin:<entity>/<x,y,z,world>) [destination:<entity>/<x,y,z,world>]", 2);
"INVENTORY", "inventory [open/copy/move/swap/add/remove/fill/clear] (origin:<entity>/<x,y,z,world>) [destination:<entity>/<x,y,z,world>]", 2);

registerCoreMember(InvisibleCommand.class,
"INVISIBLE", "invisible [npc] [toggle:true|false|toggle]", 2);
Expand Down
Expand Up @@ -10,10 +10,12 @@
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;

import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

/**
* Lets you store and edit inventories.
Expand All @@ -23,7 +25,7 @@

public class InventoryCommand extends AbstractCommand {

private enum Action { OPEN, COPY, MOVE, SWAP, ADD, REMOVE, CLEAR }
private enum Action { OPEN, COPY, MOVE, SWAP, ADD, REMOVE, FILL, CLEAR }

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
Expand Down Expand Up @@ -160,6 +162,11 @@ else if (destinationEntity != null) {
destination.remove(origin.getContents());
return;

// Clear the content of the destination inventory
case FILL:
destination.fill(origin.getContents());
return;

// Clear the content of the destination inventory
case CLEAR:
destination.clear();
Expand Down

0 comments on commit 03d0f8f

Please sign in to comment.