Skip to content

Commit

Permalink
third-pass: update runWithCheck and calls to it
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 18, 2019
1 parent 1d50612 commit ae93530
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
@@ -1,9 +1,11 @@
package net.aufdemrand.denizen.events;

import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -90,15 +92,22 @@ public boolean tryLocation(dLocation location, String comparedto) {
return loc.getBlock().equals(location.getBlock());
}

@Deprecated
public boolean runWithCheck(ScriptContainer scriptContainer, String s, String lower, dItem held) {
String with = getSwitch(lower, "with");
return runWithCheck(new ScriptPath(scriptContainer, s), held);
}

public static TagContext noDebugTagContext = new BukkitTagContext(null, null, false, null, false, null);

public boolean runWithCheck(ScriptPath path, dItem held) {
String with = path.switches.get("with");
if (with != null) {
if (with.equals("item")) {
return true;
}
dItem it = dItem.valueOf(with);
dItem it = dItem.valueOf(with, noDebugTagContext);
if (it == null) {
dB.echoError("Invalid WITH item in " + getName() + " for '" + s + "' in " + scriptContainer.getName());
dB.echoError("Invalid WITH item in " + getName() + " for '" + path.event + "' in " + path.container.getName());
return false;
}
if (held == null || !tryItem(held, with)) {
Expand Down
Expand Up @@ -118,7 +118,7 @@ public boolean matches(ScriptPath path) {
return false;
}

if (!runWithCheck(scriptContainer, s, lower, held)) {
if (!runWithCheck(path, held)) {
return false;
}

Expand Down
Expand Up @@ -76,7 +76,7 @@ public boolean matches(ScriptPath path) {
if (!runInCheck(path, location)) {
return false;
}
if (!runWithCheck(scriptContainer, s, lower, new dItem(event.getPlayer().getItemInHand()))) {
if (!runWithCheck(path, new dItem(event.getPlayer().getItemInHand()))) {
return false;
}
// Deprecated in favor of with: format
Expand Down
Expand Up @@ -148,7 +148,7 @@ public boolean matches(ScriptPath path) {
return false;
}

if (!runWithCheck(scriptContainer, s, lower, new dItem(event.getItem()))) {
if (!runWithCheck(path, new dItem(event.getItem()))) {
return false;
}

Expand Down
Expand Up @@ -66,7 +66,7 @@ public boolean matches(ScriptPath path) {
if (!runInCheck(path, event.getPlayer().getLocation())) {
return false;
}
if (!runWithCheck(scriptContainer, s, lower, new dItem(event.getPlayer().getItemInHand()))) {
if (!runWithCheck(path, new dItem(event.getPlayer().getItemInHand()))) {
return false;
}
// Deprecated in favor of with: format
Expand Down
Expand Up @@ -68,7 +68,7 @@ public boolean matches(ScriptPath path) {
if (!runInCheck(path, event.getPlayer().getLocation())) {
return false;
}
if (!runWithCheck(scriptContainer, s, lower, new dItem(event.getPlayer().getItemInHand()))) {
if (!runWithCheck(path, new dItem(event.getPlayer().getItemInHand()))) {
return false;
}
// Deprecated in favor of with: format
Expand Down

0 comments on commit ae93530

Please sign in to comment.