Skip to content

Commit

Permalink
Fix dLocation bug with .add[x,y,z].
Browse files Browse the repository at this point in the history
  • Loading branch information
aufdemrand committed Jul 5, 2013
1 parent d7c87ed commit d6fe9fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 34 deletions.
Expand Up @@ -302,7 +302,7 @@ public String getAttribute(Attribute attribute) {
if ((aH.matchesDouble(ints[0]) || aH.matchesInteger(ints[0]))
&& (aH.matchesDouble(ints[1]) || aH.matchesInteger(ints[1]))
&& (aH.matchesDouble(ints[2]) || aH.matchesInteger(ints[2])))
return new dLocation(this.add(Double.valueOf(ints[0]),
return new dLocation(this.clone().add(Double.valueOf(ints[0]),
Double.valueOf(ints[1]),
Double.valueOf(ints[2]))).getAttribute(attribute.fulfill(1));
}
Expand Down
Expand Up @@ -79,13 +79,15 @@ public String doEvents(List<String> eventNames, dNPC npc, Player player, Map<Str

String determination = "none";

// dB.log("Fired for '" + eventNames.toString() + "'");

for (WorldScriptContainer script : world_scripts.values()) {

if (script == null) continue;

for (String eventName : eventNames) {
if (!script.contains("EVENTS.ON " + eventName.toUpperCase())) continue;

if (!script.contains("EVENTS.ON " + eventName.toUpperCase())) continue;

// Fetch script from Event
List<ScriptEntry> entries = script.getEntries(new dPlayer(player), npc, "events.on " + eventName);
Expand Down
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import net.aufdemrand.denizen.exceptions.RequirementCheckException;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.containers.core.ItemScriptContainer;
import net.aufdemrand.denizen.scripts.requirements.AbstractRequirement;
Expand All @@ -14,42 +15,29 @@

public class ItemRequirement extends AbstractRequirement {

Integer quantity = 1;
ItemStack item = null;
ItemScriptContainer itemContainer = null;

@Override
public boolean check(RequirementsContext context, List<String> args)
throws RequirementCheckException {
for (String arg : args) {
if (aH.matchesQuantity(arg)) {
quantity = aH.getIntegerFrom(arg);
dB.echoDebug("...QTY set: " + quantity);
continue;

} else if (aH.matchesItem(arg)) {
if (ScriptRegistry.getScriptContainerAs(aH.getStringFrom(arg), ItemScriptContainer.class) != null) {
item = ScriptRegistry.getScriptContainerAs(aH.getStringFrom(arg), ItemScriptContainer.class).getItemFrom(context.getPlayer(), context.getNPC()).getItemStack();
dB.echoDebug("...ITEM set from script");
continue;
} else {
item = aH.getItemFrom(arg).getItemStack();
dB.echoDebug("...ITEM set");
continue;
}
} else if (aH.matchesItem("item:" + arg)) {
item = aH.getItemFrom("item:" + arg).getItemStack();
dB.echoDebug("...ITEM set");
continue;

} else throw new RequirementCheckException ("Invalid argument specified!");
}

if (context.getPlayer().getPlayerEntity().getInventory().containsAtLeast(item, quantity)) {
dB.echoDebug("...player has item");

dItem contains = null;
int quantity = 1;

for (aH.Argument arg : aH.interpret(args)) {

if (contains == null
&& arg.matchesArgumentType(dItem.class))
contains = arg.asType(dItem.class);

else if (arg.matchesPrimitive(aH.PrimitiveType.Integer))
quantity = aH.getIntegerFrom(arg.getValue());
}

if (context.getPlayer().getPlayerEntity().getInventory().containsAtLeast(contains.getItemStack(), quantity)) {
dB.echoDebug("...player has " + contains.identify() + ".");
return true;

} else {
dB.echoDebug("...player doesn't have item");
dB.echoDebug("...player doesn't have " + contains.identify() + ".");
return false;
}
}
Expand Down

0 comments on commit d6fe9fd

Please sign in to comment.