/[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 1167 by torben, Sat Oct 16 13:54:50 2010 UTC miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java revision 1175 by torben, Tue Oct 19 17:56:15 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 AIRBLOCK = 0; //block id = 0 is air
26    
# Line 64  public class Setpos extends Plugin { Line 64  public class Setpos extends Plugin {
64    
65                  @Override                  @Override
66                  public boolean onCommand(Player player, java.lang.String[] split) {                  public boolean onCommand(Player player, java.lang.String[] split) {
67                          if( split[0].equals("/setpos") ) {                          if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) {
68                                  setPos(player, split);                                  setPos(player, split);
69                                  return true;                                  return true;
70                          } else if ( split[0].equals("/whereis" ) ) {                          } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) {
71                                  whereIs(player, split);                                  whereIs(player, split);
72                                  return true;                                  return true;
73                            } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) {
74                                    levelArea(player, split);
75                                    return true;
76                            } else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) {
77                                    setSurface(player,split);
78                                    return true;
79                          } else {                          } else {
80                                  return false;                                  return false;
81                          }                          }
82                    
83                  }                  }
84    
85                    private void setSurface(Player player, String[] split) {
86                            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} ;
87    
88                            final int BLOCK_MAX = 86;
89    
90                            if (split.length != 3) {
91                                    player.sendMessage("Usage /setsurface <radius> <blockID>");
92                                    return;
93                            }
94    
95    
96                            int radius;
97                            try {
98                                    radius = Integer.parseInt(split[1]);
99                            } catch (Exception e) {
100                                    player.sendMessage("setsurface: radius must be an integer");
101                                    return;
102                            }
103    
104                            if (radius > 20) {
105                                    player.sendMessage("setsurface: radius may not exceed 20");
106                                    return;
107                            }
108    
109    
110                            int blockid;
111                            try {
112                                    blockid = Integer.parseInt(split[2]);
113                            } catch (Exception e) {
114                                    player.sendMessage("setsurface: blockid must be an integer");
115                                    return;
116                            }
117    
118                            boolean validblock = false;
119                            for (int i=0; i<valid_block_array.length; i++) {
120                                    if (valid_block_array[i] == blockid) {
121                                            validblock = true;
122                                            break;
123                                    }
124                            }
125    
126                            if ( !validblock ) {
127                                    player.sendMessage("setsurface: block now allowed");
128                                    return;
129                            }
130    
131                            int playerX = (int) player.getX();
132                            int playerY = (int) player.getY();
133                            int playerZ = (int) player.getZ();
134    
135                            if(playerY <= 2 && blockid != 7) {
136                                    player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");
137                                    return;
138                            }
139                            
140                            Server srv = etc.getServer();
141    
142                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
143                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
144                                            int y = getGroundLevel(x,z) - 1;
145                                            srv.setBlockAt(blockid, x, y, z);
146                                    }
147                            }
148                    }
149    
150                    private void levelArea(Player player, String[] split) {
151                            if (split.length != 2) {
152                                    player.sendMessage("Usage: /levelarea <radius>");
153                                    return;
154                            }
155                            
156                            int radius;
157                            try {
158                                    radius = Integer.parseInt(split[1]);
159                            } catch (Exception e) {
160                                    player.sendMessage("levelarea: radius must be an integer");
161                                    return;
162                            }
163    
164                            if (radius > 20) {
165                                    player.sendMessage("levelarea: radius may not exceed 20");
166                                    return;
167                            }
168    
169    
170    
171                            System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
172                            
173    
174                            int playerX = (int) player.getX();
175                            int playerY = (int) player.getY();
176                            int playerZ = (int) player.getZ();
177                            
178                            Server srv = etc.getServer();
179    
180                            int count = 0;
181                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
182                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
183    
184                                            //for (int y=playerY; y<=playerY+radius; y++) {
185                                            for (int y=playerY; y<=128; y++) {
186                                                    count++;
187                                                    srv.setBlockAt(0, x, y, z);
188                                            }
189    
190                                    }
191    
192                            }
193                    }
194    
195    
196    
197           double roundToPlaces(double value, int places) {           double roundToPlaces(double value, int places) {

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

  ViewVC Help
Powered by ViewVC 1.1.20