Skip to content

Commit

Permalink
type switch for clicks block/entity events too
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 15, 2021
1 parent 8abeb03 commit 9712ddd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Expand Up @@ -35,6 +35,7 @@ public class PlayerClicksBlockScriptEvent extends BukkitScriptEvent implements L
//
// @Switch with:<item> to only process the event if a specified item was held.
// @Switch using:hand/off_hand/either_hand to only process the event if the specified hand was used to click.
// @Switch type:<material> to only run if the block clicked matches the material input.
// @Location true
//
// @Triggers when a player clicks on a block or in the air.
Expand Down Expand Up @@ -143,6 +144,9 @@ public boolean matches(ScriptPath path) {
if (!runInCheck(path, location != null ? location : event.getPlayer().getLocation())) {
return false;
}
if (path.switches.containsKey("type") && !tryMaterial(blockMaterial, path.switches.get("type"))) {
return false;
}
return super.matches(path);
}

Expand Down
Expand Up @@ -26,6 +26,7 @@ public class PlayerRightClicksEntityScriptEvent extends BukkitScriptEvent implem
//
// @Location true
// @Switch with:<item> to only process the event when the player is holding a specified item.
// @Switch type:<entity> to only run if the entity clicked matches the entity input.
//
// @Warning this event may in some cases double-fire, requiring usage of the 'ratelimit' command (like 'ratelimit <player> 1t') to prevent doubling actions.
//
Expand Down Expand Up @@ -75,6 +76,9 @@ public boolean matches(ScriptPath path) {
if (path.eventArgLowerAt(isAt ? 5 : 4).equals("with") && !tryItem(item, path.eventArgLowerAt(isAt ? 6 : 5))) {
return false;
}
if (path.switches.containsKey("type") && !tryEntity(entity, path.switches.get("type"))) {
return false;
}
return super.matches(path);
}

Expand Down

0 comments on commit 9712ddd

Please sign in to comment.