--- miscJava/minecraft-plugins/hoeruputils/src/Setpos.java 2010/10/19 17:12:07 1173 +++ miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/10/22 13:49:02 1177 @@ -1,9 +1,9 @@ import java.util.logging.*; -public class Setpos extends Plugin { +public class HoerupUtils extends Plugin { - final static Logger log = Logger.getLogger("SetposPlugin"); + final static Logger log = Logger.getLogger("HoerupUtils"); @Override @@ -15,14 +15,16 @@ @Override public void initialize() { PluginLoader loader = etc.getLoader(); - loader.addListener( PluginLoader.Hook.COMMAND, new RealSetposPlugin(), this, PluginListener.Priority.MEDIUM ); + loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); } - public static class RealSetposPlugin extends PluginListener { + 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,17 @@ 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); return true; } else { return false; @@ -79,32 +91,136 @@ } - private void levelArea(Player player, String[] split) { - if (split.length != 2) { - player.sendMessage("Usage: /levelarea "); + int roundPos(double input) { + int result = (int) input; + if (input < 0.0) { + result--; + } + + return result; + } + + 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} ; + + final int BLOCK_MAX = 86; + + if (split.length != 3) { + player.sendMessage("Usage /setsurface "); return; } - + + int radius; try { radius = Integer.parseInt(split[1]); } catch (Exception e) { - player.sendMessage("levelarea: radius must be an integer"); + player.sendMessage("setsurface: radius must be an integer"); return; } if (radius > 20) { - player.sendMessage("levelarea: radius may not exceed 20"); + player.sendMessage("setsurface: radius may not exceed 20"); + return; + } + + + int blockid; + try { + blockid = Integer.parseInt(split[2]); + } catch (Exception e) { + player.sendMessage("setsurface: blockid must be an integer"); + return; + } + + boolean validblock = false; + for (int i=0; i"); + return false; + } + + int radius; + try { + radius = Integer.parseInt(split[1]); + } catch (Exception e) { + player.sendMessage(split[0] + ": radius must be an integer"); + return false; + } + + if (radius > 20) { + 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 = 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++) { + + for (int y=getGroundLevel(x,z); y