/[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/setposplugin/src/Setpos.java revision 1170 by torben, Mon Oct 18 21:33:18 2010 UTC miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java revision 1183 by torben, Sat Oct 30 17:38:46 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 boolean adminDestroy = false;
9    
10            private void registerCommands() {
11                    etc e = etc.getInstance();
12                    e.addCommand("/setpos", "[x] [z] <height> - Teleports you to the given coordinates");
13                    e.addCommand("/whereis", "[player] - Tells you the position of another player");
14                    e.addCommand("/fillarea", "");
15                    e.addCommand("/levelarea", "");
16                    e.addCommand("/setsurface", "");
17            }
18                    
19          @Override          @Override
20          public void disable() {}          public void disable() {
21                    registerCommands();
22            }
23    
24          @Override          @Override
25          public void enable() {}          public void enable() {
26                    etc e = etc.getInstance();
27                    e.removeCommand("/setpos");
28                    e.removeCommand("/whereis");
29                    e.removeCommand("/fillarea");
30                    e.removeCommand("/levelarea");
31                    e.removeCommand("/setsurface");
32            }
33                    
34          @Override          @Override
35          public void initialize() {          public void initialize() {
36                  PluginLoader loader = etc.getLoader();                  PluginLoader loader = etc.getLoader();
37                  loader.addListener( PluginLoader.Hook.COMMAND, new RealSetposPlugin(), this, PluginListener.Priority.MEDIUM );                  loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM );
38                    loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM );
39    
40    
41                    registerCommands();
42          }          }
43    
44    
45            public class AdminDestroy  extends PluginListener {    
46                    public boolean onBlockDestroy(Player player, Block block) {
47                            if (adminDestroy == true && player.isAdmin() ) {
48    
49                                    block.setType(0);
50                                    etc.getServer().setBlock(block);
51    
52                                    return true;
53                            }
54                            return false;
55                    }
56            }
57    
58          public static class RealSetposPlugin extends PluginListener {          public class HoerupUtilsPlugin extends PluginListener {
59                  final static String USAGE = "Usage: /setpos <x> <z> [height]";                  final static String USAGE = "Usage: /setpos [x] [z] <height>";
60                  final static int AIRBLOCK = 0; //block id = 0 is air                  final static int BLOCK_AIR = 0; //block id = 0 is air
61                    final static int BLOCK_GRASS = 2;
62                    final static int BLOCK_DIRT = 3;
63    
64                    
65    
# Line 57  public class Setpos extends Plugin { Line 94  public class Setpos extends Plugin {
94                  private boolean isFree(int x, int y, int z) {                  private boolean isFree(int x, int y, int z) {
95                          Server srv = etc.getServer();                          Server srv = etc.getServer();
96    
97                          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);
98                  }                  }
99    
100    
101    
102                  @Override                  @Override
103                  public boolean onCommand(Player player, java.lang.String[] split) {                  public boolean onCommand(Player player, java.lang.String[] split) {
104                          if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) {                          if ( split[0].equals("/admindestroy") && player.canUseCommand("/admindestroy") ) {
105                                    adminDestroy = !adminDestroy;
106                                    player.sendMessage("Admindestroy enabled=" + adminDestroy);
107    
108                                    return true;
109                            } else if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) {
110                                  setPos(player, split);                                  setPos(player, split);
111                                  return true;                                  return true;
112                          } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) {                          } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) {
113                                  whereIs(player, split);                                  whereIs(player, split);
114                                  return true;                                  return true;
115                          } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) {                          } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) {
116                                  levelArea(player, split);                                  if (validateLevelOrFill(player,split)) {
117                                            levelArea(player, split);
118                                    }
119                                    return true;
120                            } else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) {
121                                    if (validateLevelOrFill(player,split)) {
122                                            fillArea(player, split);
123                                    }
124                                    return true;
125                            } else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) {
126                                    setSurface(player,split);
127                                  return true;                                  return true;
128                          } else {                          } else {
129                                  return false;                                  return false;
# Line 79  public class Setpos extends Plugin { Line 131  public class Setpos extends Plugin {
131                    
132                  }                  }
133    
134                  private void levelArea(Player player, String[] split) {                  int roundPos(double input) {
135                          if (split.length != 2) {                          int result = (int) input;
136                                  player.sendMessage("Usage: /levelarea <radius>");                          if (input < 0.0) {
137                                    result--;
138                            }
139    
140                            return result;
141                    }
142    
143                    private void setSurface(Player player, String[] split) {
144                            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} ;
145    
146                            final int BLOCK_MAX = 86;
147    
148                            if (split.length != 3) {
149                                    player.sendMessage("Usage /setsurface [radius] [blockID]");
150                                  return;                                  return;
151                          }                          }
152                            
153    
154                          int radius;                          int radius;
155                          try {                          try {
156                                  radius = Integer.parseInt(split[1]);                                  radius = Integer.parseInt(split[1]);
157                          } catch (Exception e) {                          } catch (Exception e) {
158                                  player.sendMessage("levelarea: radius must be an integer");                                  player.sendMessage("setsurface: radius must be an integer");
159                                  return;                                  return;
160                          }                          }
161    
162                          if (radius > 20) {                          if (radius > 20) {
163                                  player.sendMessage("levelarea: radius may not exceed 20");                                  player.sendMessage("setsurface: radius may not exceed 20");
164                                    return;
165                            }
166    
167    
168                            int blockid;
169                            try {
170                                    blockid = Integer.parseInt(split[2]);
171                            } catch (Exception e) {
172                                    player.sendMessage("setsurface: blockid must be an integer");
173                                  return;                                  return;
174                          }                          }
175    
176                            boolean validblock = false;
177                            for (int i=0; i<valid_block_array.length; i++) {
178                                    if (valid_block_array[i] == blockid) {
179                                            validblock = true;
180                                            break;
181                                    }
182                            }
183    
184                            if ( !validblock ) {
185                                    player.sendMessage("setsurface: block now allowed");
186                                    return;
187                            }
188    
189                            int playerX = roundPos( player.getX() );
190                            int playerY = (int) player.getY();
191                            int playerZ = roundPos( player.getZ() );
192    
193                            if(playerY <= 2 && blockid != 7) {
194                                    player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");
195                                    return;
196                            }
197                            
198                            Server srv = etc.getServer();
199    
200                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
201                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
202                                            int y = getGroundLevel(x,z) - 1;
203                                            srv.setBlockAt(blockid, x, y, z);
204                                    }
205                            }
206                    }
207    
208                    private boolean validateLevelOrFill(Player player, String[] split) {
209                            if (split.length < 2 || split.length > 3) {
210                                    player.sendMessage("Usage: " + split[0] + " [radius]");
211                                    return false;
212                            }
213                            
214                            int radius;
215                            try {
216                                    radius = Integer.parseInt(split[1]);
217                            } catch (Exception e) {
218                                    player.sendMessage(split[0] + ": radius must be an integer");
219                                    return false;
220                            }
221    
222                            if (radius > 20) {
223                                    player.sendMessage(split[0] + ": radius may not exceed 20");
224                                    return false;
225                            }
226                            
227                            if (split.length == 3) {
228                                    try {
229                                            Integer.parseInt( split[2] );
230                                    } catch (Exception e) {
231                                            player.sendMessage(split[0] + ": radius must be an integer");
232                                            return false;
233                                    }
234                            }
235    
236                            return true;
237                    }
238    
239                    private void fillArea(Player player, String[] split) {
240                            int radius = Integer.parseInt(split[1]);
241                            
242                            int material = BLOCK_DIRT;
243                            if (split.length == 3) {
244                                    material = Integer.parseInt( split[2] );
245                            }
246    
247                            System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
248                            
249    
250                            int playerX = roundPos( player.getX() );
251                            int playerY = (int) player.getY();
252                            int playerZ = roundPos( player.getZ() );
253                            
254                            Server srv = etc.getServer();
255    
256                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
257                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
258    
259                                            for (int y=getGroundLevel(x,z); y<playerY; y++) {
260                                                    srv.setBlockAt(material, x, y, z);
261                                            }
262    
263                                    }
264    
265                            }
266                    }
267    
268                    private void levelArea(Player player, String[] split) {
269    
270                            int radius = Integer.parseInt(split[1]);
271    
272                          System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);                          System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
273                                                    
274    
275                          int playerX = (int) player.getX();                          int playerX = roundPos( player.getX() );
276                          int playerY = (int) player.getY();                          int playerY = (int) player.getY();
277                          int playerZ = (int) player.getZ();                          int playerZ = roundPos( player.getZ() );
278                                                    
279                          Server srv = etc.getServer();                          Server srv = etc.getServer();
280    
# Line 115  public class Setpos extends Plugin { Line 285  public class Setpos extends Plugin {
285                                          //for (int y=playerY; y<=playerY+radius; y++) {                                          //for (int y=playerY; y<=playerY+radius; y++) {
286                                          for (int y=playerY; y<=128; y++) {                                          for (int y=playerY; y<=128; y++) {
287                                                  count++;                                                  count++;
288                                                  srv.setBlockAt(0, x, y, z);                                                  srv.setBlockAt(BLOCK_AIR, x, y, z);
289                                          }                                          }
290    
291                                  }                                  }
# Line 157  public class Setpos extends Plugin { Line 327  public class Setpos extends Plugin {
327    
328          public void whereIs(Player p1, java.lang.String[] split) {          public void whereIs(Player p1, java.lang.String[] split) {
329                  if (split.length < 2 || split.length >3) {                  if (split.length < 2 || split.length >3) {
330                          p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" );                          p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" );
331                          return;                          return;
332                  }                  }
333    

Legend:
Removed from v.1170  
changed lines
  Added in v.1183

  ViewVC Help
Powered by ViewVC 1.1.20