Skip to content

Commit

Permalink
add inventory.contains.material[mat]
Browse files Browse the repository at this point in the history
a quick tag for https://github.com/aufdemrand/Denizen/issues/554

Also add a missing Chat command argument
  • Loading branch information
mcmonkey4eva committed Dec 12, 2013
1 parent 9f8a8c6 commit 87ccf75
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
38 changes: 38 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dInventory.java
Expand Up @@ -693,6 +693,44 @@ public String getAttribute(Attribute attribute) {
}
}

// <--[tag]
// @attribute <in@inventory.contains.material[<material>]>
// @returns Element(Boolean)
// @description
// Returns whether the inventory contains an item with the specified material.
// -->
if (attribute.startsWith("contains.material")) {
if (attribute.hasContext(2)) {
int qty = 1;
int attribs = 2;
dMaterial material = dMaterial.valueOf(attribute.getContext(2));

// <--[tag]
// @attribute <in@inventory.contains.material[<material>].qty[<#>]>
// @returns Element(Boolean)
// @description
// Returns whether the inventory contains a certain quantity of an item with the
// specified material.
// -->
if (attribute.getAttribute(3).startsWith("qty") &&
attribute.hasContext(3) &&
aH.matchesInteger(attribute.getContext(3))) {
qty = attribute.getIntContext(3);
attribs = 3;
}

int found_items = 0;

for (ItemStack item : getContents()) {
if (item != null && item.getType() == material.getMaterial())
found_items += item.getAmount();
}

return (found_items >= qty ? Element.TRUE.getAttribute(attribute.fulfill(attribs))
: Element.FALSE.getAttribute(attribute.fulfill(attribs)));
}
}

// <--[tag]
// @attribute <in@inventory.contains[<item>]>
// @returns Element(Boolean)
Expand Down
Expand Up @@ -510,7 +510,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name Chat
// @Syntax chat ["<text>"] (targets:<entity>|...)
// @Syntax chat ["<text>"] (no_target/targets:<entity>|...)
// @Required 1
// @Stable stable
// @Short Causes the NPC to send a chat message to nearby players.
Expand All @@ -520,7 +520,8 @@ public void registerCoreMembers() {
// Chat uses a NPCs SpeechController provided by Citizens2, typically inside 'interact' or 'task'
// script-containers. Typically there is already player and NPC context inside a queue that is using
// the 'chat' command. In this case, only a text string is required. Alternatively, target entities
// can be specified to have the NPC chat to a different target/targets.
// can be specified to have the NPC chat to a different target/targets, or specify 'no_target' to
// not send the message to any specific player.
//
// Chat from a NPC is formatted by the settings present in Citizens' config.yml. Players being chatted
// to see a slightly different message than surrounding players. By default, a 'chat' will allow other
Expand All @@ -532,7 +533,7 @@ public void registerCoreMembers() {
// 'Jack says to you, Hello!', however surrounding entities will see something along the lines of
// 'Jack says to aufdemrand, Hello!'. The format for this is configurable.
//
// If sending messages to the Player without any surrounding entities hearing the message is desireable,
// If sending messages to the Player without any surrounding entities hearing the message is desirable,
// it is often times recommended to instead use the 'narrate' command. Alternatively, on a server-wide scale,
// the configuration node for the 'max range' can be set to 0, however this is discouraged.

Expand All @@ -554,7 +555,7 @@ public void registerCoreMembers() {

// -->
registerCoreMember(ChatCommand.class,
"CHAT", "chat [\"<text>\"] (targets:<entity>|...)", 1);
"CHAT", "chat [\"<text>\"] (no_target/targets:<entity>|...)", 1);


// <--[command]
Expand Down

0 comments on commit 87ccf75

Please sign in to comment.