--- miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/11/28 18:58:26 1197 +++ miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/12/04 21:32:52 1202 @@ -14,6 +14,8 @@ e.addCommand("/fillarea", ""); e.addCommand("/levelarea", ""); e.addCommand("/setsurface", ""); + e.addCommand("/slopearea", ""); + e.addCommand("/admindestroy",""); } @Override @@ -29,6 +31,8 @@ e.removeCommand("/fillarea"); e.removeCommand("/levelarea"); e.removeCommand("/setsurface"); + e.removeCommand("/slopearea"); + e.removeCommand("/admindestroy"); } @@ -130,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 @@ -166,10 +172,56 @@ 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); + } + + } + + } + } @Override public boolean onCommand(Player player, java.lang.String[] split) { - if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { + 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); return true; } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { @@ -180,6 +232,11 @@ 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); @@ -204,7 +261,7 @@ } private void setSurface(Player player, String[] split) { - int valid_block_array[] = {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 35, 41, 42, 43, 44, 45, 46, 48, 49, 56, 57, 73, 74, 79, 80, 82} ; + int valid_block_array[] = {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 35, 41, 42, 43, 44, 45, 48, 49, 56, 57, 73, 74, 79, 80, 82} ; final int BLOCK_MAX = 86; @@ -288,12 +345,18 @@ } if (split.length == 3) { + int id; try { - Integer.parseInt( split[2] ); + id = Integer.parseInt( split[2] ); } catch (Exception e) { - player.sendMessage(split[0] + ": radius must be an integer"); + player.sendMessage(split[0] + ": id must be an integer"); + return false; + } + if ( id == 46) { + player.sendMessage("Sorry dave, i can't do that"); return false; } + } return true;