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 |
|
Material.WOOD, |
35 |
|
Material.BEDROCK, |
36 |
|
Material.WATER, |
37 |
|
Material.SAND, |
38 |
|
Material.GRAVEL, |
39 |
|
Material.GOLD_ORE, |
40 |
|
Material.IRON_ORE, |
41 |
|
Material.COAL_ORE, |
42 |
|
Material.LOG, |
43 |
|
Material.LEAVES, |
44 |
|
Material.GLASS, |
45 |
|
Material.LAPIS_ORE, |
46 |
|
Material.LAPIS_BLOCK, |
47 |
|
Material.SANDSTONE, |
48 |
|
Material.WOOL, |
49 |
|
Material.GOLD_BLOCK, |
50 |
|
Material.IRON_BLOCK, |
51 |
|
Material.BRICK, |
52 |
|
Material.MOSSY_COBBLESTONE, |
53 |
|
Material.OBSIDIAN, |
54 |
|
Material.DIAMOND_ORE, |
55 |
|
Material.DIAMOND_BLOCK, |
56 |
|
Material.ICE, |
57 |
|
Material.SNOW, |
58 |
|
Material.CLAY, |
59 |
|
Material.NETHERRACK, |
60 |
|
Material.SOUL_SAND |
61 |
|
}; |
62 |
|
//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} ; |
63 |
|
|
64 |
|
final Set<Material> valid_materials = new HashSet<Material>(); |
65 |
|
|
66 |
HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>(); |
HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>(); |
67 |
|
|
68 |
|
|
69 |
public GeneralContractorCommands() { |
public GeneralContractorCommands() { |
70 |
Arrays.sort(valid_block_array); |
Arrays.sort(valid_block_array); |
71 |
|
|
72 |
|
for (Material mat : valid_block_array) { |
73 |
|
valid_materials.add( mat ); |
74 |
|
} |
75 |
} |
} |
76 |
|
|
77 |
//@Override |
//@Override |
122 |
} |
} |
123 |
return true; |
return true; |
124 |
} |
} |
125 |
|
|
126 |
|
if (label.equals("levelandfillarea") ) { |
127 |
|
if (validateLevelOrFill(player, label, args) ) { |
128 |
|
|
129 |
|
levelArea(player, loc, args); |
130 |
|
fillArea(player, loc, args); |
131 |
|
setSurface(player, loc, args); |
132 |
|
|
133 |
|
} |
134 |
|
} |
135 |
|
|
136 |
if ( label.equals("slopearea") ) { |
if ( label.equals("slopearea") ) { |
137 |
slopeArea(player, loc, args); |
slopeArea(player, loc, args); |
155 |
} |
} |
156 |
return true; |
return true; |
157 |
} |
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
return false; |
return false; |
203 |
private void platform(Player player, Location loc, String[] split) { |
private void platform(Player player, Location loc, String[] split) { |
204 |
|
|
205 |
if (split.length != 2) { |
if (split.length != 2) { |
206 |
player.sendMessage("Usage /platform [radius] [blockID]"); |
player.sendMessage("Usage /platform [radius] [material]"); |
207 |
return; |
return; |
208 |
} |
} |
209 |
|
|
215 |
return; |
return; |
216 |
} |
} |
217 |
|
|
218 |
if (radius > 20) { |
if (radius > 25) { |
219 |
player.sendMessage("platform: radius may not exceed 20"); |
player.sendMessage("platform: radius may not exceed 25"); |
220 |
return; |
return; |
221 |
} |
} |
222 |
|
|
223 |
int blockid; |
Material material = Material.matchMaterial( split[1] ); |
224 |
try { |
if (material == null) { |
225 |
blockid = Integer.parseInt(split[1]); |
player.sendMessage("platform: unknown material: " + split[1] ); |
|
} catch (Exception e) { |
|
|
player.sendMessage("platform: blockid must be an integer"); |
|
226 |
return; |
return; |
227 |
} |
} |
228 |
/* |
/* |
250 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
251 |
int y = playerY - 1; |
int y = playerY - 1; |
252 |
|
|
253 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setType( material ); |
254 |
} |
} |
255 |
} |
} |
256 |
} |
} |
270 |
return; |
return; |
271 |
} |
} |
272 |
|
|
273 |
if (radius > 20) { |
if (radius > 25) { |
274 |
player.sendMessage("setsurface: radius may not exceed 20"); |
player.sendMessage("setsurface: radius may not exceed 25"); |
275 |
return; |
return; |
276 |
} |
} |
277 |
|
|
278 |
int blockid; |
Material material = Material.matchMaterial( split[1] ); |
279 |
try { |
if (material == null) { |
280 |
blockid = Integer.parseInt(split[1]); |
player.sendMessage("setsurface: unknown material: " + split[1] ); |
|
} catch (Exception e) { |
|
|
player.sendMessage("setsurface: blockid must be an integer"); |
|
281 |
return; |
return; |
282 |
} |
} |
283 |
|
|
284 |
//check if the blockid is in the array of valid blocks |
//check if the blockid is in the array of valid blocks |
285 |
boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0); |
if ( ! valid_materials.contains(material) ) { |
|
|
|
|
if ( !validblock ) { |
|
286 |
player.sendMessage("setsurface: block now allowed"); |
player.sendMessage("setsurface: block now allowed"); |
287 |
return; |
return; |
288 |
} |
} |
291 |
int playerY = loc.getBlockY(); |
int playerY = loc.getBlockY(); |
292 |
int playerZ = loc.getBlockZ(); |
int playerZ = loc.getBlockZ(); |
293 |
|
|
294 |
if(playerY <= 2 && blockid != 7) { |
if(playerY <= 2 && material != Material.BEDROCK ) { |
295 |
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)"); |
296 |
return; |
return; |
297 |
} |
} |
302 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
303 |
//int y = getGroundLevel(x,z) - 1; |
//int y = getGroundLevel(x,z) - 1; |
304 |
int y = world.getHighestBlockYAt(x, z) ; |
int y = world.getHighestBlockYAt(x, z) ; |
305 |
|
y -= 1; |
306 |
|
|
307 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setType(material); |
308 |
} |
} |
309 |
} |
} |
310 |
} |
} |
323 |
return false; |
return false; |
324 |
} |
} |
325 |
|
|
326 |
if (radius > 20) { |
if (radius > 25) { |
327 |
player.sendMessage(label + ": radius may not exceed 20"); |
player.sendMessage(label + ": radius may not exceed 25"); |
328 |
return false; |
return false; |
329 |
} |
} |
330 |
|
|
331 |
if (split.length == 2) { |
if (split.length == 2) { |
332 |
int id; |
Material material = Material.matchMaterial( split[1] ); |
333 |
try { |
if (material == null) { |
334 |
id = Integer.parseInt( split[1] ); |
player.sendMessage(label + ": unknown material: " + split[1] ); |
|
} catch (Exception e) { |
|
|
player.sendMessage(label + ": id must be an integer"); |
|
335 |
return false; |
return false; |
336 |
} |
} |
337 |
if ( id == 46) { |
if ( material == Material.TNT) { |
338 |
player.sendMessage("Sorry dave, i can't do that"); |
player.sendMessage("Sorry dave, i can't do that"); |
339 |
return false; |
return false; |
340 |
} |
} |
347 |
private void fillArea(Player player, Location loc, String[] split) { |
private void fillArea(Player player, Location loc, String[] split) { |
348 |
int radius = Integer.parseInt(split[0]); |
int radius = Integer.parseInt(split[0]); |
349 |
|
|
350 |
int material = Material.DIRT.getId(); |
Material material = Material.DIRT; |
351 |
|
|
352 |
|
|
353 |
if (split.length == 2) { |
if (split.length == 2) { |
354 |
material = Integer.parseInt( split[1] ); |
material = Material.matchMaterial( split[1] ); |
355 |
|
if (material == null) { |
356 |
|
player.sendMessage("Unknown material: " + split[1] ); |
357 |
|
return; |
358 |
|
} |
359 |
} |
} |
360 |
|
|
361 |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
373 |
|
|
374 |
|
|
375 |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
376 |
world.getBlockAt(x, y, z).setTypeId(material); |
world.getBlockAt(x, y, z).setType( material ); |
377 |
} |
} |
378 |
|
|
379 |
} |
} |
457 |
player.sendMessage("Usage: /cylinder [radius] [material] "); |
player.sendMessage("Usage: /cylinder [radius] [material] "); |
458 |
return; |
return; |
459 |
} |
} |
460 |
int material = Integer.parseInt( split[1] ); |
|
461 |
|
Material material = Material.matchMaterial( split[1] ); |
462 |
|
if ( material == null) { |
463 |
|
player.sendMessage("/cylinder: unknown material: " + split[1]); |
464 |
|
return; |
465 |
|
} |
466 |
|
|
467 |
int radius = Integer.parseInt(split[0]); |
int radius = Integer.parseInt(split[0]); |
468 |
int diameter = (radius*2) + 1; |
int diameter = (radius*2) + 1; |
491 |
drawMap( loc, map, material ); |
drawMap( loc, map, material ); |
492 |
} |
} |
493 |
|
|
494 |
private void drawMap(Location loc, boolean[][] map, int material) { |
private void drawMap(Location loc, boolean[][] map, Material material) { |
495 |
int playerX = loc.getBlockX(); |
int playerX = loc.getBlockX(); |
496 |
int playerY = loc.getBlockY(); |
int playerY = loc.getBlockY(); |
497 |
int playerZ = loc.getBlockZ(); |
int playerZ = loc.getBlockZ(); |
506 |
|
|
507 |
if (map[i][j] == true) { |
if (map[i][j] == true) { |
508 |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
509 |
world.getBlockAt(x, y, z).setTypeId(material); |
world.getBlockAt(x, y, z).setType(material); |
510 |
} |
} |
511 |
} |
} |
512 |
|
|