Skip to content

Commit

Permalink
Fix item script player/npc context in give/drop
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 8, 2013
1 parent a97426c commit f6acad6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.objects;

import net.aufdemrand.denizen.flags.FlagManager;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.Utilities;
Expand Down Expand Up @@ -162,7 +163,10 @@ public String[] toArray() {
}

// Return a list that includes only elements belonging to a certain class
public List<dObject> filter(Class<? extends dObject> dClass) {
public List<dObject> filter(Class<? extends dObject> dClass) {
return filter(dClass, null);
}
public List<dObject> filter(Class<? extends dObject> dClass, ScriptEntry entry) {

List<dObject> results = new ArrayList<dObject>();

Expand All @@ -171,7 +175,9 @@ public List<dObject> filter(Class<? extends dObject> dClass) {
try {
if ((Boolean) dClass.getMethod("matches", String.class).invoke(null, element)) {

dObject object = (dObject) dClass.getMethod("valueOf", String.class).invoke(null, element);
dObject object = (dObject) (dClass == dItem.class && entry != null ?
dItem.valueOf(element, entry.getPlayer(), entry.getNPC()):
dClass.getMethod("valueOf", String.class).invoke(null, element));

// Only add the object if it is not null, thus filtering useless
// list items
Expand Down
Expand Up @@ -64,7 +64,7 @@ else if (!scriptEntry.hasObject("engrave")
else if (!scriptEntry.hasObject("items")
&& !scriptEntry.hasObject("type")
&& arg.matchesArgumentList(dItem.class))
scriptEntry.addObject("items", dList.valueOf(arg.raw_value.replace("item:", "")).filter(dItem.class));
scriptEntry.addObject("items", dList.valueOf(arg.raw_value.replace("item:", "")).filter(dItem.class, scriptEntry));

else if (!scriptEntry.hasObject("inventory")
&& arg.matchesPrefix("t, to")
Expand Down
Expand Up @@ -50,7 +50,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
&& arg.matchesArgumentType(dItem.class)) {
// Item arg
scriptEntry.addObject("action", new Element(Action.DROP_ITEM.toString()).setPrefix("action"));
scriptEntry.addObject("item", arg.asType(dItem.class).setPrefix("item")); }
scriptEntry.addObject("item", dItem.valueOf(arg.getValue(), scriptEntry.getPlayer(), scriptEntry.getNPC()).setPrefix("item")); }


else if (!scriptEntry.hasObject("action")
Expand Down

0 comments on commit f6acad6

Please sign in to comment.