Skip to content

Commit

Permalink
add 'main' and 'offhand' switches to swaps item event
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 9, 2020
1 parent eefeadd commit c74755e
Showing 1 changed file with 14 additions and 0 deletions.
Expand Up @@ -20,6 +20,9 @@ public class PlayerSwapsItemsScriptEvent extends BukkitScriptEvent implements Li
//
// @Regex ^on player swaps items$
//
// @Switch main:<item> to only process the event if the item being put into the main hand matches the input item.
// @Switch offhand:<item> to only process the event if the item being put into the off-hand matches the input item.
//
// @Cancellable true
//
// @Triggers when a player swaps the items in their main and off hands.
Expand Down Expand Up @@ -49,6 +52,17 @@ public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("player swaps items");
}

@Override
public boolean matches(ScriptPath path) {
if (path.switches.containsKey("main") && !tryItem(new ItemTag(event.getMainHandItem()), path.switches.get("main"))) {
return false;
}
if (path.switches.containsKey("offhand") && !tryItem(new ItemTag(event.getOffHandItem()), path.switches.get("offhand"))) {
return false;
}
return super.matches(path);
}

@Override
public String getName() {
return "PlayerSwapsItems";
Expand Down

0 comments on commit c74755e

Please sign in to comment.