/[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

miscJava/minecraft-plugins/hoeruputils/src/Setpos.java revision 1173 by torben, Tue Oct 19 17:12:07 2010 UTC miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java revision 1178 by torben, Thu Oct 28 15:58:23 2010 UTC
# Line 1  Line 1 
1    
2  import java.util.logging.*;  import java.util.logging.*;
3    
4  public class Setpos extends Plugin {  public class HoerupUtils extends Plugin {
5    
6          final static Logger log = Logger.getLogger("SetposPlugin");          final static Logger log = Logger.getLogger("HoerupUtils");
7    
8            private void registerCommands() {
9                    etc e = etc.getInstance();
10                    e.addCommand("/setpos", "[x] [z] <height> - Teleports you to the given coordinates");
11                    e.addCommand("/whereis", "[player] - Tells you the position of another player");
12                    e.addCommand("/fillarea", "");
13                    e.addCommand("/levelarea", "");
14                    e.addCommand("/setsurface", "");
15            }
16                    
17          @Override          @Override
18          public void disable() {}          public void disable() {
19                    registerCommands();
20            }
21    
22          @Override          @Override
23          public void enable() {}          public void enable() {
24                    etc e = etc.getInstance();
25                    e.removeCommand("/setpos");
26                    e.removeCommand("/whereis");
27                    e.removeCommand("/fillarea");
28                    e.removeCommand("/levelarea");
29                    e.removeCommand("/setsurface");
30            }
31                    
32          @Override          @Override
33          public void initialize() {          public void initialize() {
34                  PluginLoader loader = etc.getLoader();                  PluginLoader loader = etc.getLoader();
35                  loader.addListener( PluginLoader.Hook.COMMAND, new RealSetposPlugin(), this, PluginListener.Priority.MEDIUM );                  loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM );
36    
37                    registerCommands();
38          }          }
39    
40    
41    
42          public static class RealSetposPlugin extends PluginListener {          public static class HoerupUtilsPlugin extends PluginListener {
43                  final static String USAGE = "Usage: /setpos <x> <z> [height]";                  final static String USAGE = "Usage: /setpos [x] [z] <height>";
44                  final static int AIRBLOCK = 0; //block id = 0 is air                  final static int BLOCK_AIR = 0; //block id = 0 is air
45                    final static int BLOCK_GRASS = 2;
46                    final static int BLOCK_DIRT = 3;
47    
48                    
49    
# Line 57  public class Setpos extends Plugin { Line 78  public class Setpos extends Plugin {
78                  private boolean isFree(int x, int y, int z) {                  private boolean isFree(int x, int y, int z) {
79                          Server srv = etc.getServer();                          Server srv = etc.getServer();
80    
81                          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);
82                  }                  }
83    
84    
# Line 71  public class Setpos extends Plugin { Line 92  public class Setpos extends Plugin {
92                                  whereIs(player, split);                                  whereIs(player, split);
93                                  return true;                                  return true;
94                          } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) {                          } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) {
95                                  levelArea(player, split);                                  if (validateLevelOrFill(player,split)) {
96                                            levelArea(player, split);
97                                    }
98                                    return true;
99                            } else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) {
100                                    if (validateLevelOrFill(player,split)) {
101                                            fillArea(player, split);
102                                    }
103                                    return true;
104                            } else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) {
105                                    setSurface(player,split);
106                                  return true;                                  return true;
107                          } else {                          } else {
108                                  return false;                                  return false;
# Line 79  public class Setpos extends Plugin { Line 110  public class Setpos extends Plugin {
110                    
111                  }                  }
112    
113                  private void levelArea(Player player, String[] split) {                  int roundPos(double input) {
114                          if (split.length != 2) {                          int result = (int) input;
115                                  player.sendMessage("Usage: /levelarea <radius>");                          if (input < 0.0) {
116                                    result--;
117                            }
118    
119                            return result;
120                    }
121    
122                    private void setSurface(Player player, String[] split) {
123                            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} ;
124    
125                            final int BLOCK_MAX = 86;
126    
127                            if (split.length != 3) {
128                                    player.sendMessage("Usage /setsurface [radius] [blockID]");
129                                  return;                                  return;
130                          }                          }
131                            
132    
133                          int radius;                          int radius;
134                          try {                          try {
135                                  radius = Integer.parseInt(split[1]);                                  radius = Integer.parseInt(split[1]);
136                          } catch (Exception e) {                          } catch (Exception e) {
137                                  player.sendMessage("levelarea: radius must be an integer");                                  player.sendMessage("setsurface: radius must be an integer");
138                                  return;                                  return;
139                          }                          }
140    
141                          if (radius > 20) {                          if (radius > 20) {
142                                  player.sendMessage("levelarea: radius may not exceed 20");                                  player.sendMessage("setsurface: radius may not exceed 20");
143                                    return;
144                            }
145    
146    
147                            int blockid;
148                            try {
149                                    blockid = Integer.parseInt(split[2]);
150                            } catch (Exception e) {
151                                    player.sendMessage("setsurface: blockid must be an integer");
152                                    return;
153                            }
154    
155                            boolean validblock = false;
156                            for (int i=0; i<valid_block_array.length; i++) {
157                                    if (valid_block_array[i] == blockid) {
158                                            validblock = true;
159                                            break;
160                                    }
161                            }
162    
163                            if ( !validblock ) {
164                                    player.sendMessage("setsurface: block now allowed");
165                                    return;
166                            }
167    
168                            int playerX = roundPos( player.getX() );
169                            int playerY = (int) player.getY();
170                            int playerZ = roundPos( player.getZ() );
171    
172                            if(playerY <= 2 && blockid != 7) {
173                                    player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");
174                                  return;                                  return;
175                          }                          }
176                            
177                            Server srv = etc.getServer();
178    
179                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
180                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
181                                            int y = getGroundLevel(x,z) - 1;
182                                            srv.setBlockAt(blockid, x, y, z);
183                                    }
184                            }
185                    }
186    
187                    private boolean validateLevelOrFill(Player player, String[] split) {
188                            if (split.length != 2) {
189                                    player.sendMessage("Usage: " + split[0] + " [radius]");
190                                    return false;
191                            }
192                            
193                            int radius;
194                            try {
195                                    radius = Integer.parseInt(split[1]);
196                            } catch (Exception e) {
197                                    player.sendMessage(split[0] + ": radius must be an integer");
198                                    return false;
199                            }
200    
201                            if (radius > 20) {
202                                    player.sendMessage(split[0] + ": radius may not exceed 20");
203                                    return false;
204                            }
205    
206                            return true;
207                    }
208    
209                    private void fillArea(Player player, String[] split) {
210                            int radius = Integer.parseInt(split[1]);
211    
212                            System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
213                            
214    
215                            int playerX = roundPos( player.getX() );
216                            int playerY = (int) player.getY();
217                            int playerZ = roundPos( player.getZ() );
218                            
219                            Server srv = etc.getServer();
220    
221                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
222                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
223    
224                                            for (int y=getGroundLevel(x,z); y<playerY; y++) {
225                                                    srv.setBlockAt(BLOCK_DIRT, x, y, z);
226                                            }
227    
228                                    }
229    
230                            }
231                    }
232    
233                    private void levelArea(Player player, String[] split) {
234    
235                            int radius = Integer.parseInt(split[1]);
236    
237                          System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);                          System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
238                                                    
239    
240                          int playerX = (int) player.getX();                          int playerX = roundPos( player.getX() );
241                          int playerY = (int) player.getY();                          int playerY = (int) player.getY();
242                          int playerZ = (int) player.getZ();                          int playerZ = roundPos( player.getZ() );
243                                                    
244                          Server srv = etc.getServer();                          Server srv = etc.getServer();
245    
# Line 115  public class Setpos extends Plugin { Line 250  public class Setpos extends Plugin {
250                                          //for (int y=playerY; y<=playerY+radius; y++) {                                          //for (int y=playerY; y<=playerY+radius; y++) {
251                                          for (int y=playerY; y<=128; y++) {                                          for (int y=playerY; y<=128; y++) {
252                                                  count++;                                                  count++;
253                                                  srv.setBlockAt(0, x, y, z);                                                  srv.setBlockAt(BLOCK_AIR, x, y, z);
254                                          }                                          }
255    
256                                  }                                  }
# Line 157  public class Setpos extends Plugin { Line 292  public class Setpos extends Plugin {
292    
293          public void whereIs(Player p1, java.lang.String[] split) {          public void whereIs(Player p1, java.lang.String[] split) {
294                  if (split.length < 2 || split.length >3) {                  if (split.length < 2 || split.length >3) {
295                          p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" );                          p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" );
296                          return;                          return;
297                  }                  }
298    

Legend:
Removed from v.1173  
changed lines
  Added in v.1178

  ViewVC Help
Powered by ViewVC 1.1.20