--- miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/10/19 17:56:15 1175 +++ miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/10/20 16:53:03 1176 @@ -22,7 +22,9 @@ public static class HoerupUtilsPlugin extends PluginListener { final static String USAGE = "Usage: /setpos [height]"; - final static int AIRBLOCK = 0; //block id = 0 is air + final static int BLOCK_AIR = 0; //block id = 0 is air + final static int BLOCK_GRASS = 2; + final static int BLOCK_DIRT = 3; @@ -57,7 +59,7 @@ private boolean isFree(int x, int y, int z) { Server srv = etc.getServer(); - return (srv.getBlockIdAt(x,y,z) == AIRBLOCK && srv.getBlockIdAt(x,y+1,z) == AIRBLOCK); + return (srv.getBlockIdAt(x,y,z) == BLOCK_AIR && srv.getBlockIdAt(x,y+1,z) == BLOCK_AIR); } @@ -71,7 +73,14 @@ whereIs(player, split); return true; } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) { - levelArea(player, split); + if (validateLevelOrFill(player,split)) { + levelArea(player, split); + } + return true; + } else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) { + if (validateLevelOrFill(player,split)) { + fillArea(player, split); + } return true; } else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) { setSurface(player,split); @@ -147,26 +156,55 @@ } } - private void levelArea(Player player, String[] split) { + private boolean validateLevelOrFill(Player player, String[] split) { if (split.length != 2) { - player.sendMessage("Usage: /levelarea "); - return; + player.sendMessage("Usage: " + split[0] + " "); + return false; } int radius; try { radius = Integer.parseInt(split[1]); } catch (Exception e) { - player.sendMessage("levelarea: radius must be an integer"); - return; + player.sendMessage(split[0] + ": radius must be an integer"); + return false; } if (radius > 20) { - player.sendMessage("levelarea: radius may not exceed 20"); - return; + player.sendMessage(split[0] + ": radius may not exceed 20"); + return false; + } + + return true; + } + + private void fillArea(Player player, String[] split) { + int radius = Integer.parseInt(split[1]); + + System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); + + + int playerX = (int) player.getX(); + int playerY = (int) player.getY(); + int playerZ = (int) player.getZ(); + + Server srv = etc.getServer(); + + for (int x=(playerX-radius); x<=(playerX+radius); x++) { + for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { + + for (int y=getGroundLevel(x,z); y