/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/creative/GeneralContractorCommands.java
ViewVC logotype

Contents of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/creative/GeneralContractorCommands.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1730 - (show annotations) (download)
Tue Mar 13 08:30:39 2012 UTC (12 years, 2 months ago) by torben
File size: 7940 byte(s)
added a platform command
1 package dk.thoerup.bukkit.hoeruputils.creative;
2
3 import org.bukkit.ChatColor;
4 import org.bukkit.Location;
5 import org.bukkit.Material;
6 import org.bukkit.World;
7 import org.bukkit.command.Command;
8 import org.bukkit.command.CommandExecutor;
9 import org.bukkit.command.CommandSender;
10 import org.bukkit.entity.Player;
11
12 import java.util.HashMap;
13
14 public class GeneralContractorCommands implements CommandExecutor{
15
16 class StoredCommand {
17 public StoredCommand(String l, String a[]) {
18 this.label = l;
19 this.args = a;
20 }
21 public String label;
22 public String args[];
23 }
24
25 final static int Y_MAX = 255;
26 final 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, 48, 49, 56, 57, 73, 74, 79, 80, 82} ;
27
28 HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>();
29
30
31
32 //@Override
33 public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
34
35 if (! (sender instanceof Player) ) {
36 return false;
37 }
38 Player player = (Player) sender;
39
40 Location loc = player.getLocation();
41
42 if ( ! loc.getWorld().getName().equals("creative")) {
43 player.sendMessage( ChatColor.RED + "This command may only be used in creative world" );
44 return true;
45 }
46
47
48 if ( command.getLabel().equals("replay") ) {
49 StoredCommand cmd = commands.get(player.getName() );
50 if (cmd != null) {
51 label = cmd.label;
52 args = cmd.args;
53 }
54 } else {
55 commands.put(player.getName(), new StoredCommand(label,args) );
56 }
57
58 //System.out.println( ">>" + label); //DEBUG
59
60 if ( label.equals("levelarea") ) {
61 if (validateLevelOrFill(player, label, args) ) {
62 levelArea(player, loc, args);
63 }
64 return true;
65 }
66
67
68 if ( label.equals("fillarea") ) {
69 if (validateLevelOrFill(player, label, args) ) {
70 fillArea(player, loc, args);
71 }
72 return true;
73 }
74
75 if ( label.equals("slopearea") ) {
76 slopeArea(player, loc, args);
77 return true;
78 }
79
80
81 if ( label.equals("setsurface") ) {
82 setSurface(player, loc, args);
83 return true;
84 }
85
86 if (label.equals("platform") ) {
87 platform(player,loc,args);
88 return true;
89 }
90
91
92 return false;
93 }
94
95
96 void slopeArea(Player player, Location loc, String[] split) {
97 int radius;
98 try {
99 radius = Integer.parseInt(split[0]);
100 } catch (Exception e) {
101 player.sendMessage("setsurface: radius must be an integer");
102 return;
103 }
104
105 System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius);
106
107
108 int playerX = loc.getBlockX();
109 int playerY = loc.getBlockY();
110 int playerZ = loc.getBlockZ();
111
112 World world = loc.getWorld();
113
114 for (int x=(playerX-radius); x<=(playerX+radius); x++) {
115 for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
116
117
118 int xdist = Math.abs(playerX-x);
119 int zdist = Math.abs(playerZ-z);
120
121 int dist = Math.max(xdist,zdist);
122
123 //for (int y=playerY; y<=playerY+radius; y++) {
124 for (int y=(playerY+dist); y<=Y_MAX; y++) {
125 world.getBlockAt(x, y, z).setType(Material.AIR);
126 }
127
128 }
129
130 }
131 }
132
133 private void platform(Player player, Location loc, String[] split) {
134
135 if (split.length != 2) {
136 player.sendMessage("Usage /platform [radius] [blockID]");
137 return;
138 }
139
140 int radius;
141 try {
142 radius = Integer.parseInt(split[0]);
143 } catch (Exception e) {
144 player.sendMessage("platform: radius must be an integer");
145 return;
146 }
147
148 if (radius > 20) {
149 player.sendMessage("platform: radius may not exceed 20");
150 return;
151 }
152
153 int blockid;
154 try {
155 blockid = Integer.parseInt(split[1]);
156 } catch (Exception e) {
157 player.sendMessage("platform: blockid must be an integer");
158 return;
159 }
160 /*
161 boolean validblock = false;
162 for (int i=0; i<valid_block_array.length; i++) {
163 if (valid_block_array[i] == blockid) {
164 validblock = true;
165 break;
166 }
167 }
168
169 if ( !validblock ) {
170 player.sendMessage("setsurface: block now allowed");
171 return;
172 }*/
173
174 int playerX = loc.getBlockX();
175 int playerY = loc.getBlockY();
176 int playerZ = loc.getBlockZ();
177
178
179 World world = loc.getWorld();
180
181 for (int x=(playerX-radius); x<=(playerX+radius); x++) {
182 for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
183 int y = playerY - 1;
184
185 world.getBlockAt(x, y, z).setTypeId(blockid);
186 }
187 }
188 }
189
190 private void setSurface(Player player, Location loc, String[] split) {
191
192 if (split.length != 2) {
193 player.sendMessage("Usage /setsurface [radius] [blockID]");
194 return;
195 }
196
197 int radius;
198 try {
199 radius = Integer.parseInt(split[0]);
200 } catch (Exception e) {
201 player.sendMessage("setsurface: radius must be an integer");
202 return;
203 }
204
205 if (radius > 20) {
206 player.sendMessage("setsurface: radius may not exceed 20");
207 return;
208 }
209
210 int blockid;
211 try {
212 blockid = Integer.parseInt(split[1]);
213 } catch (Exception e) {
214 player.sendMessage("setsurface: blockid must be an integer");
215 return;
216 }
217
218 boolean validblock = false;
219 for (int i=0; i<valid_block_array.length; i++) {
220 if (valid_block_array[i] == blockid) {
221 validblock = true;
222 break;
223 }
224 }
225
226 if ( !validblock ) {
227 player.sendMessage("setsurface: block now allowed");
228 return;
229 }
230
231 int playerX = loc.getBlockX();
232 int playerY = loc.getBlockY();
233 int playerZ = loc.getBlockZ();
234
235 if(playerY <= 2 && blockid != 7) {
236 player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");
237 return;
238 }
239
240 World world = loc.getWorld();
241
242 for (int x=(playerX-radius); x<=(playerX+radius); x++) {
243 for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
244 //int y = getGroundLevel(x,z) - 1;
245 int y = world.getHighestBlockYAt(x, z) ;
246
247 world.getBlockAt(x, y, z).setTypeId(blockid);
248 }
249 }
250 }
251
252 private boolean validateLevelOrFill(Player player, String label, String[] split) {
253 if (split.length < 1 || split.length > 2) {
254 player.sendMessage("Usage: " + label + " [radius]");
255 return false;
256 }
257
258 int radius;
259 try {
260 radius = Integer.parseInt(split[0]);
261 } catch (Exception e) {
262 player.sendMessage(label + ": radius must be an integer");
263 return false;
264 }
265
266 if (radius > 20) {
267 player.sendMessage(label + ": radius may not exceed 20");
268 return false;
269 }
270
271 if (split.length == 2) {
272 int id;
273 try {
274 id = Integer.parseInt( split[1] );
275 } catch (Exception e) {
276 player.sendMessage(label + ": id must be an integer");
277 return false;
278 }
279 if ( id == 46) {
280 player.sendMessage("Sorry dave, i can't do that");
281 return false;
282 }
283
284 }
285
286 return true;
287 }
288
289 private void fillArea(Player player, Location loc, String[] split) {
290 int radius = Integer.parseInt(split[0]);
291
292 int material = Material.DIRT.getId();
293
294 if (split.length == 2) {
295 material = Integer.parseInt( split[1] );
296 }
297
298 System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
299
300
301 int playerX = loc.getBlockX();
302 int playerY = loc.getBlockY();
303 int playerZ = loc.getBlockZ();
304
305 World world = loc.getWorld();
306
307 for (int x=(playerX-radius); x<=(playerX+radius); x++) {
308 for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
309
310
311
312 for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {
313 world.getBlockAt(x, y, z).setTypeId(material);
314 }
315
316 }
317
318 }
319 }
320
321 private void levelArea(Player player, Location loc, String[] split) {
322
323 int radius = Integer.parseInt(split[0]);
324
325 System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
326
327
328 int playerX = loc.getBlockX();
329 int playerY = loc.getBlockY();
330 int playerZ = loc.getBlockZ();
331
332
333 World world = loc.getWorld();
334
335 int count = 0;
336 for (int x=(playerX-radius); x<=(playerX+radius); x++) {
337 for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
338
339 //for (int y=playerY; y<=playerY+radius; y++) {
340 for (int y=playerY; y<=Y_MAX; y++) {
341 count++;
342 world.getBlockAt(x, y, z).setType(Material.AIR);
343
344 }
345
346 }
347
348 }
349 }
350
351
352 }

  ViewVC Help
Powered by ViewVC 1.1.20