/[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 1177 by torben, Fri Oct 22 13:49:02 2010 UTC revision 1184 by torben, Tue Nov 2 13:53:49 2010 UTC
# Line 1  Line 1 
1    
2  import java.util.logging.*;  import java.util.logging.*;
3    import java.util.*;
4    
5  public class HoerupUtils extends Plugin {  public class HoerupUtils extends Plugin {
6    
7          final static Logger log = Logger.getLogger("HoerupUtils");          final static Logger log = Logger.getLogger("HoerupUtils");
8    
9            //private boolean adminDestroy = false;
10            private Set<String> adminDestroyers = new HashSet<String>();
11    
12            private void registerCommands() {
13                    etc e = etc.getInstance();
14                    e.addCommand("/setpos", "[x] [z] <height> - Teleports you to the given coordinates");
15                    e.addCommand("/whereis", "[player] - Tells you the position of another player");
16                    e.addCommand("/fillarea", "");
17                    e.addCommand("/levelarea", "");
18                    e.addCommand("/setsurface", "");
19            }
20                    
21          @Override          @Override
22          public void disable() {}          public void disable() {
23                    registerCommands();
24            }
25    
26          @Override          @Override
27          public void enable() {}          public void enable() {
28                    etc e = etc.getInstance();
29                    e.removeCommand("/setpos");
30                    e.removeCommand("/whereis");
31                    e.removeCommand("/fillarea");
32                    e.removeCommand("/levelarea");
33                    e.removeCommand("/setsurface");
34            }
35                    
36          @Override          @Override
37          public void initialize() {          public void initialize() {
38                  PluginLoader loader = etc.getLoader();                  PluginLoader loader = etc.getLoader();
39                  loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM );                  loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM );
40                    loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM );
41    
42    
43                    registerCommands();
44          }          }
45    
46            final static int HAND_EMPTY = -1;
47    
48    
49          public static class HoerupUtilsPlugin extends PluginListener {          public class AdminDestroy  extends PluginListener {    
50                  final static String USAGE = "Usage: /setpos <x> <z> [height]";                  public boolean onBlockDestroy(Player player, Block block) {
51                            if (player.isAdmin() && adminDestroyers.contains(player.getName() ) ) {
52                                    if (player.getItemInHand() == HAND_EMPTY) {
53                                            block.setType(0);
54                                            etc.getServer().setBlock(block);
55                                            return true;
56                                    }
57                            }
58                            return false;
59                    }
60            }
61    
62            public class HoerupUtilsPlugin extends PluginListener {
63                    final static String USAGE = "Usage: /setpos [x] [z] <height>";
64                  final static int BLOCK_AIR = 0; //block id = 0 is air                  final static int BLOCK_AIR = 0; //block id = 0 is air
65                  final static int BLOCK_GRASS = 2;                  final static int BLOCK_GRASS = 2;
66                  final static int BLOCK_DIRT = 3;                  final static int BLOCK_DIRT = 3;
# Line 62  public class HoerupUtils extends Plugin Line 101  public class HoerupUtils extends Plugin
101                          return  (srv.getBlockIdAt(x,y,z) == BLOCK_AIR && srv.getBlockIdAt(x,y+1,z) == BLOCK_AIR);                          return  (srv.getBlockIdAt(x,y,z) == BLOCK_AIR && srv.getBlockIdAt(x,y+1,z) == BLOCK_AIR);
102                  }                  }
103    
104                    
105    
106                    public void adminDestroy(Player player, String[] split) {
107                            String name = player.getName();
108                            if (adminDestroyers.contains(name) ) {
109                                    adminDestroyers.remove(name);
110                                    player.sendMessage("Admindestroy disabled");
111                            } else {
112                                    adminDestroyers.add(name);
113                                    player.sendMessage("Admindestroy enabled");
114                            }
115                    }
116    
117    
118                  @Override                  @Override
119                  public boolean onCommand(Player player, java.lang.String[] split) {                  public boolean onCommand(Player player, java.lang.String[] split) {
120                          if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) {                          if ( split[0].equals("/admindestroy") && player.canUseCommand("/admindestroy") ) {
121                                    adminDestroy(player,split);
122                                    return true;
123                            } else if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) {
124                                  setPos(player, split);                                  setPos(player, split);
125                                  return true;                                  return true;
126                          } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) {                          } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) {
# Line 106  public class HoerupUtils extends Plugin Line 160  public class HoerupUtils extends Plugin
160                          final int BLOCK_MAX = 86;                          final int BLOCK_MAX = 86;
161    
162                          if (split.length != 3) {                          if (split.length != 3) {
163                                  player.sendMessage("Usage /setsurface <radius> <blockID>");                                  player.sendMessage("Usage /setsurface [radius] [blockID]");
164                                  return;                                  return;
165                          }                          }
166    
# Line 166  public class HoerupUtils extends Plugin Line 220  public class HoerupUtils extends Plugin
220                  }                  }
221    
222                  private boolean validateLevelOrFill(Player player, String[] split) {                  private boolean validateLevelOrFill(Player player, String[] split) {
223                          if (split.length != 2) {                          if (split.length < 2 || split.length > 3) {
224                                  player.sendMessage("Usage: " + split[0] + " <radius>");                                  player.sendMessage("Usage: " + split[0] + " [radius]");
225                                  return false;                                  return false;
226                          }                          }
227                                                    
# Line 183  public class HoerupUtils extends Plugin Line 237  public class HoerupUtils extends Plugin
237                                  player.sendMessage(split[0] + ": radius may not exceed 20");                                  player.sendMessage(split[0] + ": radius may not exceed 20");
238                                  return false;                                  return false;
239                          }                          }
240                            
241                            if (split.length == 3) {
242                                    try {
243                                            Integer.parseInt( split[2] );
244                                    } catch (Exception e) {
245                                            player.sendMessage(split[0] + ": radius must be an integer");
246                                            return false;
247                                    }
248                            }
249    
250                          return true;                          return true;
251                  }                  }
252    
253                  private void fillArea(Player player, String[] split) {                  private void fillArea(Player player, String[] split) {
254                          int radius = Integer.parseInt(split[1]);                          int radius = Integer.parseInt(split[1]);
255                            
256                            int material = BLOCK_DIRT;
257                            if (split.length == 3) {
258                                    material = Integer.parseInt( split[2] );
259                            }
260    
261                          System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);                          System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
262                                                    
# Line 203  public class HoerupUtils extends Plugin Line 271  public class HoerupUtils extends Plugin
271                                  for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {                                  for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
272    
273                                          for (int y=getGroundLevel(x,z); y<playerY; y++) {                                          for (int y=getGroundLevel(x,z); y<playerY; y++) {
274                                                  srv.setBlockAt(BLOCK_DIRT, x, y, z);                                                  srv.setBlockAt(material, x, y, z);
275                                          }                                          }
276    
277                                  }                                  }
# Line 273  public class HoerupUtils extends Plugin Line 341  public class HoerupUtils extends Plugin
341    
342          public void whereIs(Player p1, java.lang.String[] split) {          public void whereIs(Player p1, java.lang.String[] split) {
343                  if (split.length < 2 || split.length >3) {                  if (split.length < 2 || split.length >3) {
344                          p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" );                          p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" );
345                          return;                          return;
346                  }                  }
347    

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

  ViewVC Help
Powered by ViewVC 1.1.20