--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/SnitchingChest.java 2012/04/05 12:50:15 1775 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/SnitchingChest.java 2012/04/05 18:51:57 1780 @@ -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; @@ -91,13 +92,11 @@ } SnitchingChestBean chest1 = createChest(player.getName(), "", loc); - //chestMap.put(loc, chest1); addChest(loc, chest1); if (loc2 != null) { SnitchingChestBean chest2 = createChest (player.getName(), "", loc2); addChest(loc, chest2); - //chestMap.put(loc2, chest2 ); } player.sendMessage("[SnitchingChest] Chest is now under surveillance"); @@ -127,7 +126,9 @@ void removeChest(Location loc) { SnitchingChestBean chest = chestMap.remove(loc); - plugin.getDatabase().delete(chest); + if (chest != null) { + plugin.getDatabase().delete(chest); + } } void loadChests() { @@ -136,6 +137,8 @@ Location loc = getChestLocation(server, chest); chestMap.put(loc, chest); } + + plugin.getLogger().info("[SnitchingChest] loaded " + chestMap.size() + " chests"); } @@ -198,10 +201,35 @@ } else { loc = ( (DoubleChest)holder).getLocation(); } + + loc.setX( loc.getBlockX() ); //round to integer, since double chests apparently are placed at pos + 0.5 + loc.setZ( loc.getBlockZ() ); // -- // -- + return loc; } @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)) {