From 7b3a8402a157282f06670d3f31c9492d97bc72f0 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 19 Nov 2010 02:01:10 -0800 Subject: [PATCH] Added 'right click on' events to the blacklist. --- src/BlacklistEntry.java | 36 +++++++++++++++++++++++++++++++++++- src/WorldGuardListener.java | 8 +++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/BlacklistEntry.java b/src/BlacklistEntry.java index e9c0ea99..cce51751 100644 --- a/src/BlacklistEntry.java +++ b/src/BlacklistEntry.java @@ -54,6 +54,10 @@ public class BlacklistEntry { * List of actions to perform on right click. */ private String[] rightClickActions; + /** + * List of actions to perform on right click upon. + */ + private String[] rightClickOnActions; /** * @return the ignoreGroups @@ -115,6 +119,20 @@ public void setRightClickActions(String[] rightClickActions) { this.rightClickActions = rightClickActions; } + /** + * @return + */ + public String[] getRightClickOnActions() { + return rightClickOnActions; + } + + /** + * @param actions + */ + public void setRightClickOnActions(String[] actions) { + this.rightClickOnActions = actions; + } + /** * Returns true if this player should be ignored. * @@ -190,7 +208,7 @@ public boolean onLeftClick(int item, Player player) { } /** - * Called on right right. Returns true to let the action pass through. + * Called on right click. Returns true to let the action pass through. * * @param item * @param player @@ -205,6 +223,22 @@ public boolean onRightClick(int item, Player player) { return ret; } + /** + * Called on right click upon. Returns true to let the action pass through. + * + * @param item + * @param player + * @return + */ + public boolean onRightClickOn(Block block, Player player) { + if (rightClickOnActions == null) { + return true; + } + boolean ret = process(block.getType(), player, rightClickOnActions); + lastAffected.put(player.getName(), block.getType()); + return ret; + } + /** * Internal method to handle the actions. * diff --git a/src/WorldGuardListener.java b/src/WorldGuardListener.java index 61f21af5..5b910d87 100644 --- a/src/WorldGuardListener.java +++ b/src/WorldGuardListener.java @@ -229,7 +229,7 @@ public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicke int itemInHand) { if (blacklist != null) { BlacklistEntry entry = blacklist.get(itemInHand); - if (entry != null) { + if (entry != null) { if (!entry.onRightClick(itemInHand, player)) { // Water/lava bucket fix if (itemInHand == 326 || itemInHand == 327) { @@ -250,6 +250,10 @@ public void run() { } return true; } + + if (!entry.onRightClickOn(blockClicked, player)) { + return true; + } } } @@ -578,6 +582,8 @@ public Map loadBlacklist(File file) entry.setLeftClickActions(parts[1].split(",")); } else if(parts[0].equalsIgnoreCase("on-right")) { entry.setRightClickActions(parts[1].split(",")); + } else if(parts[0].equalsIgnoreCase("on-right-on")) { + entry.setRightClickOnActions(parts[1].split(",")); } else { unknownOption = true; }