Skip to content

Commit

Permalink
fix item move event match processing
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 13, 2019
1 parent 45233ab commit 7d32cbf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.events;

import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.objects.notable.NotableManager;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
Expand Down Expand Up @@ -288,6 +289,32 @@ public boolean equalityCheck(String input, String compared, String regexed) {
return input.equals(compared) || (regexed != null && input.matches(regexed));
}

public boolean tryInventory(dInventory inv, String comparedto) {
comparedto = CoreUtilities.toLowerCase(comparedto);
if (comparedto.equals("inventory")) {
return true;
}
if (comparedto.equals("notable")) {
return NotableManager.isSaved(inv);
}
String regexd = regexHandle(comparedto);
if (equalityCheck(inv.getInventoryType().name(), comparedto, regexd)) {
return true;
}
if (equalityCheck(inv.getIdType(), comparedto, regexd)) {
return true;
}
if (equalityCheck(inv.getIdHolder(), comparedto, regexd)) {
return true;
}
if (NotableManager.isSaved(inv)) {
if (equalityCheck(NotableManager.getSavedId(inv), comparedto, regexd)) {
return true;
}
}
return false;
}

public boolean tryItem(dItem item, String comparedto) {
if (comparedto == null || comparedto.isEmpty() || item == null) {
return false;
Expand Down
Expand Up @@ -12,7 +12,6 @@

public class ItemMoveScriptEvent extends BukkitScriptEvent implements Listener {

// TODO: in <area>
// <--[event]
// @Events
// item moves from inventory (to <inventory type>)
Expand All @@ -21,6 +20,7 @@ public class ItemMoveScriptEvent extends BukkitScriptEvent implements Listener {
// <item> moves from <inventory type> (to <inventory type>)
//
// @Regex ^on [^\s]+ moves from [^\s]+( to [^\s]+)?$
// @Switch in <area>
//
// @Cancellable true
//
Expand Down Expand Up @@ -58,24 +58,20 @@ public boolean couldMatch(ScriptContainer scriptContainer, String s) {

@Override
public boolean matches(ScriptPath path) {
String lower = path.eventLower;
String iCheck = CoreUtilities.getXthArg(0, lower);
String oCheck = CoreUtilities.getXthArg(3, lower);
String dCheck = CoreUtilities.getXthArg(5, lower);
String originType = CoreUtilities.toLowerCase(origin.getInventoryType().name());
String destinationType = CoreUtilities.toLowerCase(destination.getInventoryType().name());

if (!tryItem(item, iCheck)) {
if (!tryItem(item, CoreUtilities.getXthArg(0, path.eventLower))) {
return false;
}
if (!oCheck.equals(originType)) {
if (!tryInventory(origin, CoreUtilities.getXthArg(3, path.eventLower))) {
return false;
}
if (dCheck.length() > 0) {
if (!dCheck.equals(destinationType)) {
if (CoreUtilities.xthArgEquals(4, path.eventLower, "to")) {
if (!tryInventory(destination, CoreUtilities.getXthArg(5, path.eventLower))) {
return false;
}
}
if (!runInCheck(path, origin.getLocation())) {
return false;
}
return true;
}

Expand Down

0 comments on commit 7d32cbf

Please sign in to comment.