--- miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/11/20 08:42:06 1195 +++ miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/12/04 11:38:36 1201 @@ -6,8 +6,6 @@ final static Logger log = Logger.getLogger("HoerupUtils"); - //private boolean adminDestroy = false; - private Set adminDestroyers = new HashSet(); private void registerCommands() { etc e = etc.getInstance(); @@ -16,6 +14,8 @@ e.addCommand("/fillarea", ""); e.addCommand("/levelarea", ""); e.addCommand("/setsurface", ""); + e.addCommand("/slopearea", ""); + e.addCommand("/admindestroy",""); } @Override @@ -31,6 +31,8 @@ e.removeCommand("/fillarea"); e.removeCommand("/levelarea"); e.removeCommand("/setsurface"); + e.removeCommand("/slopearea"); + e.removeCommand("/admindestroy"); } @@ -38,7 +40,6 @@ 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 ); loader.addListener( PluginLoader.Hook.LOGIN, new ConnectedUsers(), this, PluginListener.Priority.MEDIUM ); Jail j = new Jail(); @@ -46,12 +47,15 @@ loader.addListener( PluginLoader.Hook.COMMAND, j, this, PluginListener.Priority.MEDIUM ); loader.addListener( PluginLoader.Hook.PLAYER_MOVE, j, this, PluginListener.Priority.MEDIUM ); + AdminDestroy adm = new AdminDestroy(); + loader.addListener( PluginLoader.Hook.COMMAND, adm, this, PluginListener.Priority.MEDIUM); + loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, adm, this, PluginListener.Priority.MEDIUM ); + loader.addListener( PluginLoader.Hook.DISCONNECT, adm, this, PluginListener.Priority.MEDIUM ); registerCommands(); } - final static int HAND_EMPTY = -1; class ConnectedUsers extends PluginListener { @@ -70,26 +74,6 @@ } } - public class AdminDestroy extends PluginListener { - public boolean onBlockDestroy(Player player, Block block) { - if (player.isAdmin() && adminDestroyers.contains(player.getName() ) ) { - if (player.getItemInHand() == HAND_EMPTY) { - - int oldType = block.getType(); - - block.setType(0); - etc.getServer().setBlock(block); - - if (oldType > 4 && oldType != 13) { //dont drop stone or dirt, gravel - etc.getServer().dropItem(block.getX(), block.getY(), block.getZ(), oldType); // diamond resource block should drop diamonds and not a new diamond resource block - } - - return true; - } - } - return false; - } - } public static String getBearingStr(int angle) { if (angle < 22) { @@ -150,6 +134,8 @@ final static int BLOCK_GRASS = 2; final static int BLOCK_DIRT = 3; + private HashMap commands = new HashMap(); + //http://www.minecraftforum.net/viewtopic.php?f=35&t=14739 @@ -186,24 +172,54 @@ return (srv.getBlockIdAt(x,y,z) == BLOCK_AIR && srv.getBlockIdAt(x,y+1,z) == BLOCK_AIR); } - + public void slopeArea(Player player, java.lang.String[] split) { + int radius = Integer.parseInt(split[1]); + + System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius); + + + int playerX = roundPos( player.getX() ); + int playerY = (int) player.getY(); + int playerZ = roundPos( player.getZ() ); + + Server srv = etc.getServer(); + + for (int x=(playerX-radius); x<=(playerX+radius); x++) { + for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { + + + int xdist = Math.abs(playerX-x); + int zdist = Math.abs(playerZ-z); + + int dist = Math.max(xdist,zdist); + + //for (int y=playerY; y<=playerY+radius; y++) { + for (int y=(playerY+dist); y<=128; y++) { + srv.setBlockAt(BLOCK_AIR, x, y, z); + } + + } - 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("/admindestroy") && player.canUseCommand("/admindestroy") ) { - adminDestroy(player,split); + if (! player.canUseCommand(split[0]) ) { + return false; + } + + if ( split[0].equals("/levelarea") || split[0].equals("/la") || split[0].equals("/slopearea") || split[0].equals("/fillarea") || split[0].equals("/setsurface") ) { + commands.put(player.getName(), split); + } + + if ( split[0].equals("//") ) { + String cmd[] = commands.get(player.getName() ); + if (cmd != null) { + onCommand(player, commands.get(player.getName() ) ); + } else { + player.sendMessage("//: no recorded command found"); + } return true; } else if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { setPos(player, split); @@ -211,11 +227,16 @@ } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { whereIs(player, split); return true; - } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) { + } else if ( (split[0].equals("/levelarea") || split[0].equals("/la")) && player.canUseCommand("/levelarea")) { if (validateLevelOrFill(player,split)) { levelArea(player, split); } return true; + } else if (split[0].equals("/slopearea") ) { + if (validateLevelOrFill(player,split)) { + slopeArea(player,split); + } + return true; } else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) { if (validateLevelOrFill(player,split)) { fillArea(player, split);