--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/chests/AdvancedChest.java 2012/06/03 20:16:40 1808 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/chests/AdvancedChest.java 2012/10/02 16:40:56 1853 @@ -140,12 +140,18 @@ } if (cmd.equals("remove")) { - if (chest != null) { - player.sendMessage("[LockedChest] Removing protection from chest"); - removeChest(loc); - } else { - player.sendMessage("This chest is not protected"); + if (chest == null) { + player.sendMessage("This chest is not protected"); + return true; } + if (! chest.getOwner().equals( player.getName() ) ) { + player.sendMessage("You can not remove lock from a chest you don't own"); + return true; + } + + player.sendMessage("[LockedChest] Removing protection from chest"); + removeChest(loc); + return true; } @@ -154,6 +160,10 @@ player.sendMessage("This chest is not protected"); return true; } + if (! chest.getOwner().equals( player.getName() ) ) { + player.sendMessage("You can not add/remove players from a chest you don't own"); + return true; + } if (args.length != 2) { player.sendMessage("You need to specify which player to add or remove"); return true; @@ -216,6 +226,7 @@ } else { event.setCancelled(true); event.getPlayer().sendMessage("You can't destroy that chest"); + server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried breaking a chest owned by " + chest.getOwner() ); } } } @@ -264,7 +275,7 @@ void loadChests() { int count = loadChestsWorker(); - plugin.getLogger().info("[AdvancedChest] loaded " + count + " chests"); + server.getLogger().info("[AdvancedChest] loaded " + count + " chests"); } @@ -365,6 +376,7 @@ for (Block b : event.blockList() ) { ChestBean chest = chestMap.get( b.getLocation() ); if (chest != null) { + server.getLogger().info( "[AdvancedChest] Prevented an explosion from destroying chest owned by " + chest.getOwner() ); event.setCancelled( true ); return; } @@ -395,16 +407,13 @@ return; //chest is opened by it's owner } - if (chest.getModifyPlayers() != null && chest.getModifyPlayers().length()>0) { - String modplayers[] = chest.getModifyPlayers().split(","); - for (String p : modplayers) { - if ( player.getName().equals(p) ) { - return; //this player is on the whitelist so he may open - } - } + Set players = Util.stringToSet( chest.getModifyPlayers() ); + if ( players.contains(player.getName()) ) { + return; //this player is on the whitelist so he may open } - + + server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried opening a chest owned by " + chest.getOwner() ); player.sendMessage( ChatColor.BLUE + "Sorry but this chest is locked !"); event.setCancelled(true); } @@ -437,7 +446,12 @@ Player player = (Player) event.getPlayer(); if (player.getName().equals(chest.getOwner() )) { return; //chest is owned by it's own player - } + } + + Set players = Util.stringToSet( chest.getModifyPlayers() ); + if ( players.contains(player.getName()) ) { + return; //this player is on the whitelist so he may open + } ItemCount contents = countItems( event.getInventory().getContents() ); @@ -509,7 +523,7 @@ } - plugin.getLogger().info(msg); + server.getLogger().info( "[AdvancedChest]" + msg); plugin.getMessageWrapper().sendMessage("system", owner, msg); }