--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/chests/AdvancedChest.java 2012/06/28 10:19:26 1813 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/chests/AdvancedChest.java 2012/10/02 18:39:29 1854 @@ -76,7 +76,7 @@ if (args.length == 0) { player.sendMessage("Usage:"); - player.sendMessage("/chest (status|lock|snitch|remove|addplayer|removeplayer) [player]"); + player.sendMessage("/chest (status|lock|snitch|remove|addplayer|removeplayer|setowner) [player]"); return true; } @@ -140,12 +140,42 @@ } 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; + } + + if (cmd.equals("setowner")) { + if (chest == null) { + player.sendMessage("This chest is not protected"); + return true; + } + if (! chest.getOwner().equals( player.getName() ) ) { + player.sendMessage("You can not set new owner of a chest you dont own"); + return true; + } + if (args.length != 2) { + player.sendMessage("You need to specify which player should own this chest"); + return true; + } + OfflinePlayer p2 = server.getOfflinePlayer(args[1]); + if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) { + player.sendMessage("Unknown user: " + args[1] ); + return true; } + chest.setOwner( p2.getName() ); + plugin.getDatabase().save( chest ); + player.sendMessage("ok"); return true; } @@ -154,6 +184,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;