11 |
|
|
12 |
import java.util.Arrays; |
import java.util.Arrays; |
13 |
import java.util.HashMap; |
import java.util.HashMap; |
14 |
|
import java.util.HashSet; |
15 |
|
import java.util.Set; |
16 |
|
|
17 |
public class GeneralContractorCommands implements CommandExecutor{ |
public class GeneralContractorCommands implements CommandExecutor{ |
18 |
|
|
26 |
} |
} |
27 |
|
|
28 |
final static int Y_MAX = 255; |
final static int Y_MAX = 255; |
29 |
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} ; |
final Material valid_block_array[] = { |
30 |
|
Material.STONE, |
31 |
|
Material.GRASS, |
32 |
|
Material.DIRT, |
33 |
|
Material.COBBLESTONE, |
34 |
|
|
35 |
|
//Material.WOOD, |
36 |
|
Material.ACACIA_WOOD, |
37 |
|
Material.BIRCH_WOOD, |
38 |
|
Material.DARK_OAK_WOOD, |
39 |
|
Material.JUNGLE_WOOD, |
40 |
|
Material.OAK_WOOD, |
41 |
|
Material.SPRUCE_WOOD, |
42 |
|
|
43 |
|
Material.BEDROCK, |
44 |
|
Material.WATER, |
45 |
|
Material.SAND, |
46 |
|
Material.GRAVEL, |
47 |
|
Material.GOLD_ORE, |
48 |
|
Material.IRON_ORE, |
49 |
|
Material.COAL_ORE, |
50 |
|
|
51 |
|
//Material.LOG, |
52 |
|
Material.ACACIA_LOG, |
53 |
|
Material.BIRCH_LOG, |
54 |
|
Material.DARK_OAK_LOG, |
55 |
|
Material.JUNGLE_LOG, |
56 |
|
Material.OAK_LOG, |
57 |
|
Material.SPRUCE_LOG, |
58 |
|
//Material.LEAVES, |
59 |
|
Material.ACACIA_LEAVES, |
60 |
|
Material.BIRCH_LEAVES, |
61 |
|
Material.DARK_OAK_LEAVES, |
62 |
|
Material.JUNGLE_LEAVES, |
63 |
|
Material.OAK_LEAVES, |
64 |
|
Material.SPRUCE_LEAVES, |
65 |
|
|
66 |
|
Material.GLASS, |
67 |
|
Material.LAPIS_ORE, |
68 |
|
Material.LAPIS_BLOCK, |
69 |
|
Material.SANDSTONE, |
70 |
|
//Material.WOOL, |
71 |
|
Material.BLACK_WOOL, |
72 |
|
Material.WHITE_WOOL, |
73 |
|
Material.GRAY_WOOL, |
74 |
|
|
75 |
|
Material.GOLD_BLOCK, |
76 |
|
Material.IRON_BLOCK, |
77 |
|
Material.BRICK, |
78 |
|
Material.MOSSY_COBBLESTONE, |
79 |
|
Material.OBSIDIAN, |
80 |
|
Material.DIAMOND_ORE, |
81 |
|
Material.DIAMOND_BLOCK, |
82 |
|
Material.ICE, |
83 |
|
Material.SNOW, |
84 |
|
Material.CLAY, |
85 |
|
Material.NETHERRACK, |
86 |
|
Material.SOUL_SAND |
87 |
|
}; |
88 |
|
//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} ; |
89 |
|
|
90 |
|
final Set<Material> valid_materials = new HashSet<Material>(); |
91 |
|
|
92 |
HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>(); |
HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>(); |
93 |
|
|
94 |
|
|
95 |
public GeneralContractorCommands() { |
public GeneralContractorCommands() { |
96 |
Arrays.sort(valid_block_array); |
Arrays.sort(valid_block_array); |
97 |
|
|
98 |
|
for (Material mat : valid_block_array) { |
99 |
|
valid_materials.add( mat ); |
100 |
|
} |
101 |
} |
} |
102 |
|
|
103 |
//@Override |
//@Override |
148 |
} |
} |
149 |
return true; |
return true; |
150 |
} |
} |
151 |
|
|
152 |
|
if (label.equals("levelandfillarea") ) { |
153 |
|
if (validateLevelOrFill(player, label, args) ) { |
154 |
|
|
155 |
|
levelArea(player, loc, args); |
156 |
|
fillArea(player, loc, args); |
157 |
|
setSurface(player, loc, args); |
158 |
|
|
159 |
|
} |
160 |
|
} |
161 |
|
|
162 |
if ( label.equals("slopearea") ) { |
if ( label.equals("slopearea") ) { |
163 |
slopeArea(player, loc, args); |
slopeArea(player, loc, args); |
181 |
} |
} |
182 |
return true; |
return true; |
183 |
} |
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
return false; |
return false; |
229 |
private void platform(Player player, Location loc, String[] split) { |
private void platform(Player player, Location loc, String[] split) { |
230 |
|
|
231 |
if (split.length != 2) { |
if (split.length != 2) { |
232 |
player.sendMessage("Usage /platform [radius] [blockID]"); |
player.sendMessage("Usage /platform [radius] [material]"); |
233 |
return; |
return; |
234 |
} |
} |
235 |
|
|
241 |
return; |
return; |
242 |
} |
} |
243 |
|
|
244 |
if (radius > 20) { |
if (radius > 25) { |
245 |
player.sendMessage("platform: radius may not exceed 20"); |
player.sendMessage("platform: radius may not exceed 25"); |
246 |
return; |
return; |
247 |
} |
} |
248 |
|
|
249 |
int blockid; |
Material material = Material.matchMaterial( split[1] ); |
250 |
try { |
if (material == null) { |
251 |
blockid = Integer.parseInt(split[1]); |
player.sendMessage("platform: unknown material: " + split[1] ); |
|
} catch (Exception e) { |
|
|
player.sendMessage("platform: blockid must be an integer"); |
|
252 |
return; |
return; |
253 |
} |
} |
254 |
/* |
/* |
276 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
277 |
int y = playerY - 1; |
int y = playerY - 1; |
278 |
|
|
279 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setType( material ); |
280 |
} |
} |
281 |
} |
} |
282 |
} |
} |
296 |
return; |
return; |
297 |
} |
} |
298 |
|
|
299 |
if (radius > 20) { |
if (radius > 25) { |
300 |
player.sendMessage("setsurface: radius may not exceed 20"); |
player.sendMessage("setsurface: radius may not exceed 25"); |
301 |
return; |
return; |
302 |
} |
} |
303 |
|
|
304 |
int blockid; |
Material material = Material.matchMaterial( split[1] ); |
305 |
try { |
if (material == null) { |
306 |
blockid = Integer.parseInt(split[1]); |
player.sendMessage("setsurface: unknown material: " + split[1] ); |
|
} catch (Exception e) { |
|
|
player.sendMessage("setsurface: blockid must be an integer"); |
|
307 |
return; |
return; |
308 |
} |
} |
309 |
|
|
310 |
//check if the blockid is in the array of valid blocks |
//check if the blockid is in the array of valid blocks |
311 |
boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0); |
if ( ! valid_materials.contains(material) ) { |
|
|
|
|
if ( !validblock ) { |
|
312 |
player.sendMessage("setsurface: block now allowed"); |
player.sendMessage("setsurface: block now allowed"); |
313 |
return; |
return; |
314 |
} |
} |
317 |
int playerY = loc.getBlockY(); |
int playerY = loc.getBlockY(); |
318 |
int playerZ = loc.getBlockZ(); |
int playerZ = loc.getBlockZ(); |
319 |
|
|
320 |
if(playerY <= 2 && blockid != 7) { |
if(playerY <= 2 && material != Material.BEDROCK ) { |
321 |
player.sendMessage("setsurface: at this level you may only use bedrock(id=7)"); |
player.sendMessage("setsurface: at this level you may only use bedrock(id=7)"); |
322 |
return; |
return; |
323 |
} |
} |
328 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
329 |
//int y = getGroundLevel(x,z) - 1; |
//int y = getGroundLevel(x,z) - 1; |
330 |
int y = world.getHighestBlockYAt(x, z) ; |
int y = world.getHighestBlockYAt(x, z) ; |
331 |
|
y -= 1; |
332 |
|
|
333 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setType(material); |
334 |
} |
} |
335 |
} |
} |
336 |
} |
} |
349 |
return false; |
return false; |
350 |
} |
} |
351 |
|
|
352 |
if (radius > 20) { |
if (radius > 25) { |
353 |
player.sendMessage(label + ": radius may not exceed 20"); |
player.sendMessage(label + ": radius may not exceed 25"); |
354 |
return false; |
return false; |
355 |
} |
} |
356 |
|
|
357 |
if (split.length == 2) { |
if (split.length == 2) { |
358 |
int id; |
Material material = Material.matchMaterial( split[1] ); |
359 |
try { |
if (material == null) { |
360 |
id = Integer.parseInt( split[1] ); |
player.sendMessage(label + ": unknown material: " + split[1] ); |
|
} catch (Exception e) { |
|
|
player.sendMessage(label + ": id must be an integer"); |
|
361 |
return false; |
return false; |
362 |
} |
} |
363 |
if ( id == 46) { |
if ( material == Material.TNT) { |
364 |
player.sendMessage("Sorry dave, i can't do that"); |
player.sendMessage("Sorry dave, i can't do that"); |
365 |
return false; |
return false; |
366 |
} |
} |
373 |
private void fillArea(Player player, Location loc, String[] split) { |
private void fillArea(Player player, Location loc, String[] split) { |
374 |
int radius = Integer.parseInt(split[0]); |
int radius = Integer.parseInt(split[0]); |
375 |
|
|
376 |
int material = Material.DIRT.getId(); |
Material material = Material.DIRT; |
377 |
|
|
378 |
|
|
379 |
if (split.length == 2) { |
if (split.length == 2) { |
380 |
material = Integer.parseInt( split[1] ); |
material = Material.matchMaterial( split[1] ); |
381 |
|
if (material == null) { |
382 |
|
player.sendMessage("Unknown material: " + split[1] ); |
383 |
|
return; |
384 |
|
} |
385 |
} |
} |
386 |
|
|
387 |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
399 |
|
|
400 |
|
|
401 |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
402 |
world.getBlockAt(x, y, z).setTypeId(material); |
world.getBlockAt(x, y, z).setType( material ); |
403 |
} |
} |
404 |
|
|
405 |
} |
} |
421 |
|
|
422 |
World world = loc.getWorld(); |
World world = loc.getWorld(); |
423 |
|
|
424 |
int count = 0; |
|
425 |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
426 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
427 |
|
|
428 |
int y_max = playerY+radius; |
int y_max = playerY+radius; |
429 |
//for (int y=playerY; y<=playerY+radius; y++) { |
//for (int y=playerY; y<=playerY+radius; y++) { |
430 |
for (int y=playerY; y<=y_max; y++) { |
for (int y=playerY; y<=y_max; y++) { |
431 |
count++; |
|
432 |
world.getBlockAt(x, y, z).setType(Material.AIR); |
world.getBlockAt(x, y, z).setType(Material.AIR); |
433 |
|
|
434 |
} |
} |
452 |
|
|
453 |
World world = loc.getWorld(); |
World world = loc.getWorld(); |
454 |
|
|
|
int count = 0; |
|
455 |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
456 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
457 |
|
|
458 |
//for (int y=playerY; y<=playerY+radius; y++) { |
//for (int y=playerY; y<=playerY+radius; y++) { |
459 |
for (int y=playerY; y<=Y_MAX; y++) { |
for (int y=playerY; y<=Y_MAX; y++) { |
|
count++; |
|
460 |
world.getBlockAt(x, y, z).setType(Material.AIR); |
world.getBlockAt(x, y, z).setType(Material.AIR); |
461 |
|
|
462 |
} |
} |
481 |
player.sendMessage("Usage: /cylinder [radius] [material] "); |
player.sendMessage("Usage: /cylinder [radius] [material] "); |
482 |
return; |
return; |
483 |
} |
} |
484 |
int material = Integer.parseInt( split[1] ); |
|
485 |
|
Material material = Material.matchMaterial( split[1] ); |
486 |
|
if ( material == null) { |
487 |
|
player.sendMessage("/cylinder: unknown material: " + split[1]); |
488 |
|
return; |
489 |
|
} |
490 |
|
|
491 |
int radius = Integer.parseInt(split[0]); |
int radius = Integer.parseInt(split[0]); |
492 |
int diameter = (radius*2) + 1; |
int diameter = (radius*2) + 1; |
515 |
drawMap( loc, map, material ); |
drawMap( loc, map, material ); |
516 |
} |
} |
517 |
|
|
518 |
private void drawMap(Location loc, boolean[][] map, int material) { |
private void drawMap(Location loc, boolean[][] map, Material material) { |
519 |
int playerX = loc.getBlockX(); |
int playerX = loc.getBlockX(); |
520 |
int playerY = loc.getBlockY(); |
int playerY = loc.getBlockY(); |
521 |
int playerZ = loc.getBlockZ(); |
int playerZ = loc.getBlockZ(); |
530 |
|
|
531 |
if (map[i][j] == true) { |
if (map[i][j] == true) { |
532 |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
533 |
world.getBlockAt(x, y, z).setTypeId(material); |
world.getBlockAt(x, y, z).setType(material); |
534 |
} |
} |
535 |
} |
} |
536 |
|
|