--- miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/10/22 13:49:02 1177 +++ miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/10/30 17:38:46 1183 @@ -5,23 +5,58 @@ final static Logger log = Logger.getLogger("HoerupUtils"); + private boolean adminDestroy = false; + + private void registerCommands() { + etc e = etc.getInstance(); + e.addCommand("/setpos", "[x] [z] - Teleports you to the given coordinates"); + e.addCommand("/whereis", "[player] - Tells you the position of another player"); + e.addCommand("/fillarea", ""); + e.addCommand("/levelarea", ""); + e.addCommand("/setsurface", ""); + } @Override - public void disable() {} + public void disable() { + registerCommands(); + } @Override - public void enable() {} + public void enable() { + etc e = etc.getInstance(); + e.removeCommand("/setpos"); + e.removeCommand("/whereis"); + e.removeCommand("/fillarea"); + e.removeCommand("/levelarea"); + e.removeCommand("/setsurface"); + } @Override 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(); } + public class AdminDestroy extends PluginListener { + public boolean onBlockDestroy(Player player, Block block) { + if (adminDestroy == true && player.isAdmin() ) { + + block.setType(0); + etc.getServer().setBlock(block); - public static class HoerupUtilsPlugin extends PluginListener { - final static String USAGE = "Usage: /setpos [height]"; + 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; final static int BLOCK_DIRT = 3; @@ -66,7 +101,12 @@ @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 = !adminDestroy; + player.sendMessage("Admindestroy enabled=" + adminDestroy); + + 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")) { @@ -106,7 +146,7 @@ final int BLOCK_MAX = 86; if (split.length != 3) { - player.sendMessage("Usage /setsurface "); + player.sendMessage("Usage /setsurface [radius] [blockID]"); return; } @@ -166,8 +206,8 @@ } private boolean validateLevelOrFill(Player player, String[] split) { - if (split.length != 2) { - player.sendMessage("Usage: " + split[0] + " "); + if (split.length < 2 || split.length > 3) { + player.sendMessage("Usage: " + split[0] + " [radius]"); return false; } @@ -183,12 +223,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); @@ -203,7 +257,7 @@ for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { for (int y=getGroundLevel(x,z); y3) { - p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" ); + p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) " ); return; }