--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/SnitchingChest.java 2012/04/05 20:50:00 1782 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/SnitchingChest.java 2012/04/06 09:51:01 1785 @@ -81,9 +81,6 @@ if (chest.getOwner().equals(player.getName())) { player.sendMessage("[SnitchingChest] Removing surveillance from chest"); removeChest(loc); - if (loc2 != null) { - removeChest(loc2); - } } else { player.sendMessage("[SnitchingChest] Chest is already under surveillance"); } @@ -91,13 +88,12 @@ return true; } - SnitchingChestBean chest1 = createChest(player.getName(), "", loc); - addChest(loc, chest1); + chest = createChest(player.getName(), "", loc); if (loc2 != null) { - - SnitchingChestBean chest2 = createChest (player.getName(), "", loc2); - addChest(loc, chest2); + chest.setDoublechest(true); } + addChest(loc, chest); + player.sendMessage("[SnitchingChest] Chest is now under surveillance"); @@ -121,24 +117,50 @@ } public void addChest(Location loc, SnitchingChestBean chest) { chestMap.put(loc, chest); + if (chest.isDoublechest()) { + Location loc2 = getNeighborChest(loc); + chestMap.put(loc2, chest); + } plugin.getDatabase().save(chest); + + reloadChests(); + } void removeChest(Location loc) { SnitchingChestBean chest = chestMap.remove(loc); - if (chest != null) { + if (chest != null) { + if (chest.isDoublechest()){ + Location loc2 = getNeighborChest(loc); + chestMap.remove(loc2); + } plugin.getDatabase().delete(chest); } } - void loadChests() { + int loadChestsWorker() { List chestlist = plugin.getDatabase().find( SnitchingChestBean.class).findList(); for (SnitchingChestBean chest : chestlist) { Location loc = getChestLocation(server, chest); chestMap.put(loc, chest); + + if (chest.isDoublechest()) { + Location loc2 = getNeighborChest(loc); + chestMap.put(loc2, chest); + } } - - plugin.getLogger().info("[SnitchingChest] loaded " + chestMap.size() + " chests"); + + return chestlist.size(); + } + + void reloadChests() { + chestMap.clear(); + loadChestsWorker(); + } + + void loadChests() { + int count = loadChestsWorker(); + plugin.getLogger().info("[SnitchingChest] loaded " + count + " chests"); } @@ -221,8 +243,13 @@ SnitchingChestBean chest = chestMap.get(chestloc); if (chest != null) { //the neighbor is a snitching chest - SnitchingChestBean newchest = createChest( chest.getOwner(), "", chestloc); - addChest(chestloc, newchest); + //SnitchingChestBean newchest = createChest( chest.getOwner(), "", chestloc); + //plugin.getDatabase().save(chest); + + chest.setDoublechest(true); + addChest(chestloc, chest); + + event.getPlayer().sendMessage( "[SnitchingChest] Chest has been expanded" ); } @@ -309,9 +336,9 @@ String msg = null; if (count > savedcount) { - msg = player.getName() + " added " + diff + " units of " + material + "(" +item + ") to " + owner.getName() + "'s chest"; + 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"; + msg = player.getName() + " removed " + diff + " units of " + material + "(" +item + ") from " + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ(); }