/[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 1169 by torben, Mon Oct 18 21:20:41 2010 UTC miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java revision 1176 by torben, Wed Oct 20 16:53:03 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                    
9          @Override          @Override
# Line 15  public class Setpos extends Plugin { Line 15  public class Setpos extends Plugin {
15          @Override          @Override
16          public void initialize() {          public void initialize() {
17                  PluginLoader loader = etc.getLoader();                  PluginLoader loader = etc.getLoader();
18                  loader.addListener( PluginLoader.Hook.COMMAND, new RealSetposPlugin(), this, PluginListener.Priority.MEDIUM );                  loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM );
19          }          }
20    
21    
22    
23          public static class RealSetposPlugin 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 Setpos extends Plugin { Line 59  public class Setpos 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    
66    
67                  @Override                  @Override
68                  public boolean onCommand(Player player, java.lang.String[] split) {                  public boolean onCommand(Player player, java.lang.String[] split) {
69                          if( split[0].equals("/setpos") ) {                          if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) {
70                                  setPos(player, split);                                  setPos(player, split);
71                                  return true;                                  return true;
72                          } else if ( split[0].equals("/whereis" ) ) {                          } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) {
73                                  whereIs(player, split);                                  whereIs(player, split);
74                                  return true;                                  return true;
75                          } else if (split[0].equals("/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;
85                            } else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) {
86                                    setSurface(player,split);
87                                  return true;                                  return true;
88                          } else {                          } else {
89                                  return false;                                  return false;
# Line 79  public class Setpos extends Plugin { Line 91  public class Setpos extends Plugin {
91                    
92                  }                  }
93    
94                  private void levelArea(Player player, String[] split) {                  private void setSurface(Player player, String[] split) {
95                          if (split.length != 2) {                          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} ;
96                                  player.sendMessage("Usage: /levelarea <radius>");  
97                            final int BLOCK_MAX = 86;
98    
99                            if (split.length != 3) {
100                                    player.sendMessage("Usage /setsurface <radius> <blockID>");
101                                  return;                                  return;
102                          }                          }
103                            
104    
105                          int radius;                          int radius;
106                          try {                          try {
107                                  radius = Integer.parseInt(split[1]);                                  radius = Integer.parseInt(split[1]);
108                          } catch (Exception e) {                          } catch (Exception e) {
109                                  player.sendMessage("levelarea: radius must be an integer");                                  player.sendMessage("setsurface: radius must be an integer");
110                                  return;                                  return;
111                          }                          }
112    
113                          if (radius > 20) {                          if (radius > 20) {
114                                  player.sendMessage("levelarea: radius may not exceed 20");                                  player.sendMessage("setsurface: radius may not exceed 20");
115                                    return;
116                            }
117    
118    
119                            int blockid;
120                            try {
121                                    blockid = Integer.parseInt(split[2]);
122                            } catch (Exception e) {
123                                    player.sendMessage("setsurface: blockid must be an integer");
124                                    return;
125                            }
126    
127                            boolean validblock = false;
128                            for (int i=0; i<valid_block_array.length; i++) {
129                                    if (valid_block_array[i] == blockid) {
130                                            validblock = true;
131                                            break;
132                                    }
133                            }
134    
135                            if ( !validblock ) {
136                                    player.sendMessage("setsurface: block now allowed");
137                                  return;                                  return;
138                          }                          }
139    
140                            int playerX = (int) player.getX();
141                            int playerY = (int) player.getY();
142                            int playerZ = (int) player.getZ();
143    
144                            if(playerY <= 2 && blockid != 7) {
145                                    player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");
146                                    return;
147                            }
148                            
149                            Server srv = etc.getServer();
150    
151                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
152                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
153                                            int y = getGroundLevel(x,z) - 1;
154                                            srv.setBlockAt(blockid, x, y, z);
155                                    }
156                            }
157                    }
158    
159                    private boolean validateLevelOrFill(Player player, String[] split) {
160                            if (split.length != 2) {
161                                    player.sendMessage("Usage: " + split[0] + " <radius>");
162                                    return false;
163                            }
164                            
165                            int radius;
166                            try {
167                                    radius = Integer.parseInt(split[1]);
168                            } catch (Exception e) {
169                                    player.sendMessage(split[0] + ": radius must be an integer");
170                                    return false;
171                            }
172    
173                            if (radius > 20) {
174                                    player.sendMessage(split[0] + ": radius may not exceed 20");
175                                    return false;
176                            }
177    
178                            return true;
179                    }
180    
181                    private void fillArea(Player player, String[] split) {
182                            int radius = Integer.parseInt(split[1]);
183    
184                            System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
185                            
186    
187                            int playerX = (int) player.getX();
188                            int playerY = (int) player.getY();
189                            int playerZ = (int) player.getZ();
190                            
191                            Server srv = etc.getServer();
192    
193                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
194                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
195    
196                                            for (int y=getGroundLevel(x,z); y<playerY; y++) {
197                                                    srv.setBlockAt(BLOCK_DIRT, x, y, z);
198                                            }
199    
200                                    }
201    
202                            }
203                    }
204    
205                    private void levelArea(Player player, String[] split) {
206    
207                            int radius = Integer.parseInt(split[1]);
208    
209                          System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);                          System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
210                                                    
# Line 115  public class Setpos extends Plugin { Line 222  public class Setpos extends Plugin {
222                                          //for (int y=playerY; y<=playerY+radius; y++) {                                          //for (int y=playerY; y<=playerY+radius; y++) {
223                                          for (int y=playerY; y<=128; y++) {                                          for (int y=playerY; y<=128; y++) {
224                                                  count++;                                                  count++;
225                                                  srv.setBlockAt(0, x, y, z);                                                  srv.setBlockAt(BLOCK_AIR, x, y, z);
226                                          }                                          }
227    
228                                  }                                  }

Legend:
Removed from v.1169  
changed lines
  Added in v.1176

  ViewVC Help
Powered by ViewVC 1.1.20