From 86011a0d0dc3cf636d05409328d7e4c350f94187 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Tue, 20 Mar 2012 17:53:15 -0700 Subject: [PATCH] Fixed handling of double chests and cleaned WorldEditListener up a bit --- .../sk89q/worldedit/bukkit/BukkitWorld.java | 10 +++++++ .../worldedit/bukkit/WorldEditListener.java | 30 +++++++------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index ebed268cd..6681aa500 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -27,6 +27,7 @@ import com.sk89q.worldedit.util.TreeGenerator; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.block.Chest; import org.bukkit.block.Furnace; import org.bukkit.block.CreatureSpawner; import org.bukkit.block.Sign; @@ -388,6 +389,9 @@ public boolean clearContainerBlockContents(Vector pt) { org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state; Inventory inven = chest.getInventory(); + if (chest instanceof Chest) { + inven = ((Chest) chest).getBlockInventory(); + } inven.clear(); return true; } @@ -697,6 +701,9 @@ private BaseItemStack[] getContainerBlockContents(Vector pt) { org.bukkit.inventory.InventoryHolder container = (org.bukkit.inventory.InventoryHolder) state; Inventory inven = container.getInventory(); + if (container instanceof Chest) { + inven = ((Chest) container).getBlockInventory(); + } int size = inven.getSize(); BaseItemStack[] contents = new BaseItemStack[size]; @@ -737,6 +744,9 @@ private boolean setContainerBlockContents(Vector pt, BaseItemStack[] contents) { org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state; Inventory inven = chest.getInventory(); + if (chest instanceof Chest) { + inven = ((Chest) chest).getBlockInventory(); + } int size = inven.getSize(); for (int i = 0; i < size; ++i) { diff --git a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java index fda9e5f8c..5582ce9f0 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/WorldEditListener.java @@ -44,20 +44,20 @@ * Handles all events thrown in relation to a Player */ public class WorldEditListener implements Listener { - + private WorldEditPlugin plugin; private boolean ignoreLeftClickAir = false; private final static Pattern cuipattern = Pattern.compile("u00a74u00a75u00a73u00a74([^\\|]*)\\|?(.*)"); /** * Called when a player plays an animation, such as an arm swing - * + * * @param event Relevant event details */ /** * Construct the object; - * + * * @param plugin */ public WorldEditListener(WorldEditPlugin plugin) { @@ -84,19 +84,15 @@ public void onPlayerQuit(PlayerQuitEvent event) { * * @param event Relevant event details */ - @EventHandler(priority = EventPriority.LOW) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { - if (event.isCancelled()) { - return; - } - String[] split = event.getMessage().split(" "); if (split.length > 0) { split = plugin.getWorldEdit().commandDetection(split); split[0] = "/" + split[0]; } - + final String newMessage = StringUtil.joinString(split, " "); if (!newMessage.equals(event.getMessage())) { @@ -104,7 +100,7 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { plugin.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { if (event.getMessage().length() > 0) { - plugin.getServer().dispatchCommand(event.getPlayer(), + plugin.getServer().dispatchCommand(event.getPlayer(), event.getMessage().substring(1)); } event.setCancelled(true); @@ -122,7 +118,7 @@ public void onPlayerInteract(PlayerInteractEvent event) { if (event.useItemInHand() == Result.DENY) { return; } - + final LocalPlayer player = plugin.wrapPlayer(event.getPlayer()); final LocalWorld world = player.getWorld(); final WorldEdit we = plugin.getWorldEdit(); @@ -181,25 +177,21 @@ public void run() { } } - @EventHandler + @EventHandler(ignoreCancelled = true) public void onPlayerChat(PlayerChatEvent event) { - if (event.isCancelled()) { - return; - } - Matcher matcher = cuipattern.matcher(event.getMessage()); if (matcher.find()) { String type = matcher.group(1); String args = matcher.group(2); - + if( type.equals("v") ) { try { plugin.getSession(event.getPlayer()).setCUIVersion(Integer.parseInt(args)); event.setCancelled(true); - } catch( NumberFormatException e ) { + } catch(NumberFormatException ignore) { } } - + } } }