--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/SnitchingChest.java 2012/04/05 14:27:24 1779 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/SnitchingChest.java 2012/04/05 21:15:30 1784 @@ -22,6 +22,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.inventory.InventoryHolder; @@ -208,6 +209,27 @@ } @EventHandler + public void onChestPlaced(BlockPlaceEvent event) { + Block block = event.getBlock(); + + if (block.getType() != Material.CHEST) { + return; + } + + Location chestloc = getNeighborChest( block.getLocation() ); + if (chestloc != null) { + SnitchingChestBean chest = chestMap.get(chestloc); + + if (chest != null) { //the neighbor is a snitching chest + SnitchingChestBean newchest = createChest( chest.getOwner(), "", chestloc); + addChest(chestloc, newchest); + event.getPlayer().sendMessage( "[SnitchingChest] Chest has been expanded" ); + } + + } + } + + @EventHandler public void onChestOpen(InventoryOpenEvent event) { if (! (event.getPlayer() instanceof Player)) { @@ -281,15 +303,18 @@ int diff = Math.abs( savedcount - count); - String msg = null; - if (count > savedcount) { - msg = player.getName() + " added " + diff + " units of " + item + " to " + owner + "'s chest"; - } - if (count < savedcount) { - msg = player.getName() + " removed " + diff + " units of " + item + " from " + owner + "'s chest"; - } - if (msg != null) { + if (diff > 0) { + String material = Material.getMaterial(item).name(); + String msg = null; + + if (count > savedcount) { + msg = player.getName() + " added " + diff + " units of " + material + "(" +item + ") to " + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ(); + } else { //(count < savedcount) + msg = player.getName() + " removed " + diff + " units of " + material + "(" +item + ") from " + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ(); + } + + plugin.getLogger().info(msg); plugin.getMessageWrapper().sendMessage(owner, msg); }