--- miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/10/28 15:58:23 1178 +++ miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/11/02 13:53:49 1184 @@ -1,10 +1,14 @@ import java.util.logging.*; +import java.util.*; public class HoerupUtils extends Plugin { final static Logger log = Logger.getLogger("HoerupUtils"); + //private boolean adminDestroy = false; + private Set adminDestroyers = new HashSet(); + private void registerCommands() { etc e = etc.getInstance(); e.addCommand("/setpos", "[x] [z] - Teleports you to the given coordinates"); @@ -33,13 +37,29 @@ public void initialize() { PluginLoader loader = etc.getLoader(); loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); + loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM ); + registerCommands(); } + final static int HAND_EMPTY = -1; - public static class HoerupUtilsPlugin extends PluginListener { + public class AdminDestroy extends PluginListener { + public boolean onBlockDestroy(Player player, Block block) { + if (player.isAdmin() && adminDestroyers.contains(player.getName() ) ) { + if (player.getItemInHand() == HAND_EMPTY) { + block.setType(0); + etc.getServer().setBlock(block); + return true; + } + } + return false; + } + } + + public class HoerupUtilsPlugin extends PluginListener { final static String USAGE = "Usage: /setpos [x] [z] "; final static int BLOCK_AIR = 0; //block id = 0 is air final static int BLOCK_GRASS = 2; @@ -81,11 +101,26 @@ return (srv.getBlockIdAt(x,y,z) == BLOCK_AIR && srv.getBlockIdAt(x,y+1,z) == BLOCK_AIR); } + + + public void adminDestroy(Player player, String[] split) { + String name = player.getName(); + if (adminDestroyers.contains(name) ) { + adminDestroyers.remove(name); + player.sendMessage("Admindestroy disabled"); + } else { + adminDestroyers.add(name); + player.sendMessage("Admindestroy enabled"); + } + } @Override public boolean onCommand(Player player, java.lang.String[] split) { - if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { + if ( split[0].equals("/admindestroy") && player.canUseCommand("/admindestroy") ) { + adminDestroy(player,split); + return true; + } else if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { setPos(player, split); return true; } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { @@ -185,7 +220,7 @@ } private boolean validateLevelOrFill(Player player, String[] split) { - if (split.length != 2) { + if (split.length < 2 || split.length > 3) { player.sendMessage("Usage: " + split[0] + " [radius]"); return false; } @@ -202,12 +237,26 @@ player.sendMessage(split[0] + ": radius may not exceed 20"); return false; } + + if (split.length == 3) { + try { + Integer.parseInt( split[2] ); + } catch (Exception e) { + player.sendMessage(split[0] + ": radius must be an integer"); + return false; + } + } return true; } private void fillArea(Player player, String[] split) { int radius = Integer.parseInt(split[1]); + + int material = BLOCK_DIRT; + if (split.length == 3) { + material = Integer.parseInt( split[2] ); + } System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); @@ -222,7 +271,7 @@ for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { for (int y=getGroundLevel(x,z); y