Skip to content

Commit

Permalink
Add "update" to Inventory command
Browse files Browse the repository at this point in the history
At the moment, only player inventories can be "updated", but it's a
needed feature.
  • Loading branch information
Morphan1 committed Dec 11, 2013
1 parent 4db29f2 commit a90ff79
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ public void setContents(ItemStack[] contents) {
inventory.setContents(contents);
}

public boolean update() {
if (idType.equals("player")) {
dPlayer.valueOf(idHolder).getPlayerEntity().updateInventory();
return true;
}
return false;
}

/////////////////////
// INVENTORY MANIPULATION
Expand Down Expand Up @@ -721,7 +728,7 @@ public String getAttribute(Attribute attribute) {
// @attribute <in@inventory.id_holder>
// @returns Element
// @description
// Returns Denizen's holder ID for this inventory
// Returns Denizen's holder ID for this inventory. (p@aufdemrand, l@123,321,123, etc.)
// -->
if (attribute.startsWith("id_holder")) {
return new Element(idHolder).getAttribute(attribute.fulfill(1));
Expand All @@ -731,7 +738,7 @@ public String getAttribute(Attribute attribute) {
// @attribute <in@inventory.id_type>
// @returns Element
// @description
// Returns Denizen's type ID for this inventory
// Returns Denizen's type ID for this inventory. (player, location, etc.)
// -->
if (attribute.startsWith("id_type")) {
return new Element(idType).getAttribute(attribute.fulfill(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name Inventory
// @Syntax inventory [open/copy/move/swap/add/remove/keep/exclude/fill/clear] (destination:<inventory>) (origin:<inventory>/<item>|...)
// @Syntax inventory [open/copy/move/swap/add/remove/keep/exclude/fill/clear/update] (destination:<inventory>) (origin:<inventory>/<item>|...)
// @Required 1
// @Stable stable
// @Short Edits the inventory of a player, NPC, or chest.
Expand All @@ -1336,7 +1336,7 @@ public void registerCoreMembers() {
// Todo
// -->
registerCoreMember(InventoryCommand.class,
"INVENTORY", "inventory [open/copy/move/swap/add/remove/keep/exclude/fill/clear] (destination:<inventory>) (origin:<inventory>/<item>|...)", 1);
"INVENTORY", "inventory [open/copy/move/swap/add/remove/keep/exclude/fill/clear/update] (destination:<inventory>) (origin:<inventory>/<item>|...)", 1);


// <--[command]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class InventoryCommand extends AbstractCommand {

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

@SuppressWarnings("unchecked")
@Override
Expand Down Expand Up @@ -138,6 +138,13 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
case CLEAR:
destination.clear();
break;

// If this is a player inventory, update it
case UPDATE:
if (!destination.update())
throw new CommandExecutionException("Only player inventories can be force-updated!");
break;

}
}
}
Expand Down

0 comments on commit a90ff79

Please sign in to comment.