From 88048c15d84aa96accd0b6595fe3b4586f00b89c Mon Sep 17 00:00:00 2001 From: Robin Kupper Date: Tue, 21 Jun 2011 21:23:52 +0200 Subject: [PATCH] Added workaround for tool lookup of double chests --- src/de/diddiz/LogBlock/LBToolListener.java | 22 ++++++++++++++++++---- src/de/diddiz/LogBlock/QueryParams.java | 13 +++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/de/diddiz/LogBlock/LBToolListener.java b/src/de/diddiz/LogBlock/LBToolListener.java index 3eaec8f..9f7a68d 100644 --- a/src/de/diddiz/LogBlock/LBToolListener.java +++ b/src/de/diddiz/LogBlock/LBToolListener.java @@ -2,13 +2,17 @@ package de.diddiz.LogBlock; import java.util.Map; import org.bukkit.ChatColor; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerListener; +import com.sk89q.worldedit.bukkit.selections.CuboidSelection; class LBToolListener extends PlayerListener { + private final static BlockFace[] orientations = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}; private final CommandsHandler handler; private final LogBlock logblock; private final int toolID; @@ -33,14 +37,24 @@ class LBToolListener extends PlayerListener final Session session = logblock.getSession(player.getName()); if (type == toolID && session.toolEnabled && logblock.hasPermission(player, "logblock.tool") || type == toolblockID && session.toolBlockEnabled && logblock.hasPermission(player, "logblock.toolblock")) if (tables.get(player.getWorld().getName().hashCode()) != null) { - if (!(type == toolID && event.getClickedBlock().getTypeId() == 26)) + final Block block = event.getClickedBlock(); + if (!(type == toolID && block.getTypeId() == 26)) event.setCancelled(true); final QueryParams params = type == toolID ? session.toolQuery : session.toolBlockQuery; final ToolMode mode = type == toolID ? session.toolMode : session.toolBlockMode; + params.loc = null; + params.sel = null; if (type == toolblockID && action == Action.RIGHT_CLICK_BLOCK) - params.setLocation(event.getClickedBlock().getFace(event.getBlockFace()).getLocation()); - else - params.setLocation(event.getClickedBlock().getLocation()); + params.setLocation(block.getFace(event.getBlockFace()).getLocation()); + else if (event.getClickedBlock().getTypeId() != 54) + params.setLocation(block.getLocation()); + else { + for (final BlockFace face : orientations) + if (block.getFace(face).getTypeId() == 54) + params.setSelection(new CuboidSelection(player.getWorld(), block.getLocation(), block.getFace(face).getLocation())); + if (params.sel == null) + params.setLocation(block.getLocation()); + } try { if (mode == ToolMode.ROLLBACK) handler.new CommandRollback(player, params, true); diff --git a/src/de/diddiz/LogBlock/QueryParams.java b/src/de/diddiz/LogBlock/QueryParams.java index 121e603..eb29b93 100644 --- a/src/de/diddiz/LogBlock/QueryParams.java +++ b/src/de/diddiz/LogBlock/QueryParams.java @@ -249,12 +249,12 @@ public class QueryParams implements Cloneable final Plugin we = player.getServer().getPluginManager().getPlugin("WorldEdit"); if (we == null) throw new IllegalArgumentException("WorldEdit plugin not found"); - sel = ((WorldEditPlugin)we).getSelection(player); - if (sel == null) + final Selection selection = ((WorldEditPlugin)we).getSelection(player); + if (selection == null) throw new IllegalArgumentException("No selection defined"); - if (!(sel instanceof CuboidSelection)) + if (!(selection instanceof CuboidSelection)) throw new IllegalArgumentException("You have to define a cuboid selection"); - world = sel.getWorld(); + setSelection(selection); } else if (param.equals("time") || param.equals("since")) { if (values == null) minutes = logblock.getConfig().defaultTime; @@ -341,6 +341,11 @@ public class QueryParams implements Cloneable world = loc.getWorld(); } + public void setSelection(Selection sel) { + this.sel = sel; + world = sel.getWorld(); + } + public void setPlayer(String playerName) { players.clear(); players.add(playerName);