/[projects]/miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java
ViewVC logotype

Diff of /miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1175 by torben, Tue Oct 19 17:56:15 2010 UTC revision 1177 by torben, Fri Oct 22 13:49:02 2010 UTC
# Line 22  public class HoerupUtils extends Plugin Line 22  public class HoerupUtils extends Plugin
22    
23          public static class HoerupUtilsPlugin extends PluginListener {          public static class HoerupUtilsPlugin extends PluginListener {
24                  final static String USAGE = "Usage: /setpos <x> <z> [height]";                  final static String USAGE = "Usage: /setpos <x> <z> [height]";
25                  final static int AIRBLOCK = 0; //block id = 0 is air                  final static int BLOCK_AIR = 0; //block id = 0 is air
26                    final static int BLOCK_GRASS = 2;
27                    final static int BLOCK_DIRT = 3;
28    
29                    
30    
# Line 57  public class HoerupUtils extends Plugin Line 59  public class HoerupUtils extends Plugin
59                  private boolean isFree(int x, int y, int z) {                  private boolean isFree(int x, int y, int z) {
60                          Server srv = etc.getServer();                          Server srv = etc.getServer();
61    
62                          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);
63                  }                  }
64    
65    
# Line 71  public class HoerupUtils extends Plugin Line 73  public class HoerupUtils extends Plugin
73                                  whereIs(player, split);                                  whereIs(player, split);
74                                  return true;                                  return true;
75                          } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) {                          } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) {
76                                  levelArea(player, split);                                  if (validateLevelOrFill(player,split)) {
77                                            levelArea(player, split);
78                                    }
79                                    return true;
80                            } else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) {
81                                    if (validateLevelOrFill(player,split)) {
82                                            fillArea(player, split);
83                                    }
84                                  return true;                                  return true;
85                          } else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) {                          } else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) {
86                                  setSurface(player,split);                                  setSurface(player,split);
# Line 82  public class HoerupUtils extends Plugin Line 91  public class HoerupUtils extends Plugin
91                    
92                  }                  }
93    
94                    int roundPos(double input) {
95                            int result = (int) input;
96                            if (input < 0.0) {
97                                    result--;
98                            }
99    
100                            return result;
101                    }
102    
103                  private void setSurface(Player player, String[] split) {                  private void setSurface(Player player, String[] split) {
104                          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, 46, 48, 49, 56, 57, 73, 74, 79, 80, 82} ;
105    
# Line 128  public class HoerupUtils extends Plugin Line 146  public class HoerupUtils extends Plugin
146                                  return;                                  return;
147                          }                          }
148    
149                          int playerX = (int) player.getX();                          int playerX = roundPos( player.getX() );
150                          int playerY = (int) player.getY();                          int playerY = (int) player.getY();
151                          int playerZ = (int) player.getZ();                          int playerZ = roundPos( player.getZ() );
152    
153                          if(playerY <= 2 && blockid != 7) {                          if(playerY <= 2 && blockid != 7) {
154                                  player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");                                  player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");
# Line 147  public class HoerupUtils extends Plugin Line 165  public class HoerupUtils extends Plugin
165                          }                          }
166                  }                  }
167    
168                  private void levelArea(Player player, String[] split) {                  private boolean validateLevelOrFill(Player player, String[] split) {
169                          if (split.length != 2) {                          if (split.length != 2) {
170                                  player.sendMessage("Usage: /levelarea <radius>");                                  player.sendMessage("Usage: " + split[0] + " <radius>");
171                                  return;                                  return false;
172                          }                          }
173                                                    
174                          int radius;                          int radius;
175                          try {                          try {
176                                  radius = Integer.parseInt(split[1]);                                  radius = Integer.parseInt(split[1]);
177                          } catch (Exception e) {                          } catch (Exception e) {
178                                  player.sendMessage("levelarea: radius must be an integer");                                  player.sendMessage(split[0] + ": radius must be an integer");
179                                  return;                                  return false;
180                          }                          }
181    
182                          if (radius > 20) {                          if (radius > 20) {
183                                  player.sendMessage("levelarea: radius may not exceed 20");                                  player.sendMessage(split[0] + ": radius may not exceed 20");
184                                  return;                                  return false;
185                            }
186    
187                            return true;
188                    }
189    
190                    private void fillArea(Player player, String[] split) {
191                            int radius = Integer.parseInt(split[1]);
192    
193                            System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
194                            
195    
196                            int playerX = roundPos( player.getX() );
197                            int playerY = (int) player.getY();
198                            int playerZ = roundPos( player.getZ() );
199                            
200                            Server srv = etc.getServer();
201    
202                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
203                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
204    
205                                            for (int y=getGroundLevel(x,z); y<playerY; y++) {
206                                                    srv.setBlockAt(BLOCK_DIRT, x, y, z);
207                                            }
208    
209                                    }
210    
211                          }                          }
212                    }
213    
214                    private void levelArea(Player player, String[] split) {
215    
216                            int radius = Integer.parseInt(split[1]);
217    
218                          System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);                          System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
219                                                    
220    
221                          int playerX = (int) player.getX();                          int playerX = roundPos( player.getX() );
222                          int playerY = (int) player.getY();                          int playerY = (int) player.getY();
223                          int playerZ = (int) player.getZ();                          int playerZ = roundPos( player.getZ() );
224                                                    
225                          Server srv = etc.getServer();                          Server srv = etc.getServer();
226    
# Line 184  public class HoerupUtils extends Plugin Line 231  public class HoerupUtils extends Plugin
231                                          //for (int y=playerY; y<=playerY+radius; y++) {                                          //for (int y=playerY; y<=playerY+radius; y++) {
232                                          for (int y=playerY; y<=128; y++) {                                          for (int y=playerY; y<=128; y++) {
233                                                  count++;                                                  count++;
234                                                  srv.setBlockAt(0, x, y, z);                                                  srv.setBlockAt(BLOCK_AIR, x, y, z);
235                                          }                                          }
236    
237                                  }                                  }

Legend:
Removed from v.1175  
changed lines
  Added in v.1177

  ViewVC Help
Powered by ViewVC 1.1.20