Skip to content

Commit

Permalink
New WITH: engine for damaged event and later other events. Also fix d…
Browse files Browse the repository at this point in the history
…amaged event
  • Loading branch information
mcmonkey4eva committed Jun 29, 2015
1 parent a250c08 commit f928bb7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dEllipsoid;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
Expand All @@ -13,7 +14,6 @@
public abstract class BukkitScriptEvent extends ScriptEvent {

public boolean runInCheck(ScriptContainer scriptContainer, String s, String lower, Location location) {

List<String> data = CoreUtilities.split(lower, ' ');

int index;
Expand Down Expand Up @@ -55,4 +55,42 @@ else if (dEllipsoid.matches(it)) {
return false;
}
}

public boolean runWithCheck(ScriptContainer scriptContainer, String s, String lower, dItem held) {
String with = getSwitch(s, "with");
if (with != null) {
dItem it = dItem.valueOf(with);
if (it == null) {
dB.echoError("Invalid WITH item in " + getName() + " for '" + s + "' in " + scriptContainer.getName());
return false;
}
if (held == null || !tryItem(held, with)) {
return false;
}
}
return true;
}

public boolean tryItem(dItem item, String comparedto) {
item = new dItem(item.getItemStack().clone());
item.setAmount(1);
if (item.identifyNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
if (item.identifyMaterialNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
if (item.identifySimpleNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
item.setDurability((short)0);
if (item.identifyNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
if (item.identifyMaterialNoIdentifier().equalsIgnoreCase(comparedto)) {
return true;
}
return false;
}

}
Expand Up @@ -5,7 +5,6 @@
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dObject;
Expand Down Expand Up @@ -126,16 +125,8 @@ public boolean matches(ScriptContainer scriptContainer, String s) {
return false;
}

String with = getSwitch(s, "with");
if (with != null) {
dItem it = dItem.valueOf(with);
if (it == null) {
dB.echoError("Invalid WITH item in " + getName() + " for '" + s + "' in " + scriptContainer.getName());
return false;
}
if (held == null || !it.identify().equalsIgnoreCase(held.identify())) {
return false;
}
if (!runWithCheck(scriptContainer, s, lower, held)) {
return false;
}

return true;
Expand Down Expand Up @@ -167,8 +158,8 @@ public boolean applyDetermination(ScriptContainer container, String determinatio

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(damager.isPlayer() ? damager.getDenizenPlayer() : entity.isPlayer() ? entity.getDenizenPlayer() : null,
damager.isCitizensNPC() ? damager.getDenizenNPC() : entity.isCitizensNPC() ? dEntity.getNPCFrom(event.getEntity()) : null);
return new BukkitScriptEntryData(damager != null && damager.isPlayer() ? damager.getDenizenPlayer() : entity.isPlayer() ? entity.getDenizenPlayer() : null,
damager != null && damager.isCitizensNPC() ? damager.getDenizenNPC() : entity.isCitizensNPC() ? dEntity.getNPCFrom(event.getEntity()) : null);
}

@Override
Expand Down

0 comments on commit f928bb7

Please sign in to comment.