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 |
191 |
private void platform(Player player, Location loc, String[] split) { |
private void platform(Player player, Location loc, String[] split) { |
192 |
|
|
193 |
if (split.length != 2) { |
if (split.length != 2) { |
194 |
player.sendMessage("Usage /platform [radius] [blockID]"); |
player.sendMessage("Usage /platform [radius] [material]"); |
195 |
return; |
return; |
196 |
} |
} |
197 |
|
|
208 |
return; |
return; |
209 |
} |
} |
210 |
|
|
211 |
int blockid; |
Material material = Material.matchMaterial( split[1] ); |
212 |
try { |
if (material == null) { |
213 |
blockid = Integer.parseInt(split[1]); |
player.sendMessage("platform: unknown material: " + split[1] ); |
|
} catch (Exception e) { |
|
|
player.sendMessage("platform: blockid must be an integer"); |
|
214 |
return; |
return; |
215 |
} |
} |
216 |
/* |
/* |
238 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
239 |
int y = playerY - 1; |
int y = playerY - 1; |
240 |
|
|
241 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setType( material ); |
242 |
} |
} |
243 |
} |
} |
244 |
} |
} |
263 |
return; |
return; |
264 |
} |
} |
265 |
|
|
266 |
int blockid; |
Material material = Material.matchMaterial( split[1] ); |
267 |
try { |
if (material == null) { |
268 |
blockid = Integer.parseInt(split[1]); |
player.sendMessage("setsurface: unknown material: " + split[1] ); |
|
} catch (Exception e) { |
|
|
player.sendMessage("setsurface: blockid must be an integer"); |
|
269 |
return; |
return; |
270 |
} |
} |
271 |
|
|
272 |
//check if the blockid is in the array of valid blocks |
//check if the blockid is in the array of valid blocks |
273 |
boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0); |
if ( ! valid_materials.contains(material) ) { |
|
|
|
|
if ( !validblock ) { |
|
274 |
player.sendMessage("setsurface: block now allowed"); |
player.sendMessage("setsurface: block now allowed"); |
275 |
return; |
return; |
276 |
} |
} |
279 |
int playerY = loc.getBlockY(); |
int playerY = loc.getBlockY(); |
280 |
int playerZ = loc.getBlockZ(); |
int playerZ = loc.getBlockZ(); |
281 |
|
|
282 |
if(playerY <= 2 && blockid != 7) { |
if(playerY <= 2 && material != Material.BEDROCK ) { |
283 |
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)"); |
284 |
return; |
return; |
285 |
} |
} |
290 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
291 |
//int y = getGroundLevel(x,z) - 1; |
//int y = getGroundLevel(x,z) - 1; |
292 |
int y = world.getHighestBlockYAt(x, z) ; |
int y = world.getHighestBlockYAt(x, z) ; |
293 |
|
y -= 1; |
294 |
|
|
295 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setType(material); |
296 |
} |
} |
297 |
} |
} |
298 |
} |
} |
317 |
} |
} |
318 |
|
|
319 |
if (split.length == 2) { |
if (split.length == 2) { |
320 |
int id; |
Material material = Material.matchMaterial( split[1] ); |
321 |
try { |
if (material == null) { |
322 |
id = Integer.parseInt( split[1] ); |
player.sendMessage(label + ": unknown material: " + split[1] ); |
|
} catch (Exception e) { |
|
|
player.sendMessage(label + ": id must be an integer"); |
|
323 |
return false; |
return false; |
324 |
} |
} |
325 |
if ( id == 46) { |
if ( material == Material.TNT) { |
326 |
player.sendMessage("Sorry dave, i can't do that"); |
player.sendMessage("Sorry dave, i can't do that"); |
327 |
return false; |
return false; |
328 |
} |
} |
335 |
private void fillArea(Player player, Location loc, String[] split) { |
private void fillArea(Player player, Location loc, String[] split) { |
336 |
int radius = Integer.parseInt(split[0]); |
int radius = Integer.parseInt(split[0]); |
337 |
|
|
338 |
int material = Material.DIRT.getId(); |
Material material = Material.DIRT; |
339 |
|
|
340 |
|
|
341 |
if (split.length == 2) { |
if (split.length == 2) { |
342 |
material = Integer.parseInt( split[1] ); |
material = Material.matchMaterial( split[1] ); |
343 |
|
if (material == null) { |
344 |
|
player.sendMessage("Unknown material: " + split[1] ); |
345 |
|
return; |
346 |
|
} |
347 |
} |
} |
348 |
|
|
349 |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
361 |
|
|
362 |
|
|
363 |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
364 |
world.getBlockAt(x, y, z).setTypeId(material); |
world.getBlockAt(x, y, z).setType( material ); |
365 |
} |
} |
366 |
|
|
367 |
} |
} |
445 |
player.sendMessage("Usage: /cylinder [radius] [material] "); |
player.sendMessage("Usage: /cylinder [radius] [material] "); |
446 |
return; |
return; |
447 |
} |
} |
448 |
int material = Integer.parseInt( split[1] ); |
|
449 |
|
Material material = Material.matchMaterial( split[1] ); |
450 |
|
if ( material == null) { |
451 |
|
player.sendMessage("/cylinder: unknown material: " + split[1]); |
452 |
|
return; |
453 |
|
} |
454 |
|
|
455 |
int radius = Integer.parseInt(split[0]); |
int radius = Integer.parseInt(split[0]); |
456 |
int diameter = (radius*2) + 1; |
int diameter = (radius*2) + 1; |
479 |
drawMap( loc, map, material ); |
drawMap( loc, map, material ); |
480 |
} |
} |
481 |
|
|
482 |
private void drawMap(Location loc, boolean[][] map, int material) { |
private void drawMap(Location loc, boolean[][] map, Material material) { |
483 |
int playerX = loc.getBlockX(); |
int playerX = loc.getBlockX(); |
484 |
int playerY = loc.getBlockY(); |
int playerY = loc.getBlockY(); |
485 |
int playerZ = loc.getBlockZ(); |
int playerZ = loc.getBlockZ(); |
494 |
|
|
495 |
if (map[i][j] == true) { |
if (map[i][j] == true) { |
496 |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
497 |
world.getBlockAt(x, y, z).setTypeId(material); |
world.getBlockAt(x, y, z).setType(material); |
498 |
} |
} |
499 |
} |
} |
500 |
|
|