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 |
|
//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} ; |
36 |
|
|
37 |
|
final Set<Material> valid_materials = new HashSet<Material>(); |
38 |
|
|
39 |
HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>(); |
HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>(); |
40 |
|
|
41 |
|
|
42 |
public GeneralContractorCommands() { |
public GeneralContractorCommands() { |
43 |
Arrays.sort(valid_block_array); |
Arrays.sort(valid_block_array); |
44 |
|
|
45 |
|
for (Material mat : valid_block_array) { |
46 |
|
valid_materials.add( mat ); |
47 |
|
} |
48 |
} |
} |
49 |
|
|
50 |
//@Override |
//@Override |
164 |
private void platform(Player player, Location loc, String[] split) { |
private void platform(Player player, Location loc, String[] split) { |
165 |
|
|
166 |
if (split.length != 2) { |
if (split.length != 2) { |
167 |
player.sendMessage("Usage /platform [radius] [blockID]"); |
player.sendMessage("Usage /platform [radius] [material]"); |
168 |
return; |
return; |
169 |
} |
} |
170 |
|
|
181 |
return; |
return; |
182 |
} |
} |
183 |
|
|
184 |
int blockid; |
Material material = Material.matchMaterial( split[1] ); |
185 |
try { |
if (material == null) { |
|
blockid = Integer.parseInt(split[1]); |
|
|
} catch (Exception e) { |
|
186 |
player.sendMessage("platform: blockid must be an integer"); |
player.sendMessage("platform: blockid must be an integer"); |
187 |
return; |
return; |
188 |
} |
} |
211 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
212 |
int y = playerY - 1; |
int y = playerY - 1; |
213 |
|
|
214 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setType( material ); |
215 |
} |
} |
216 |
} |
} |
217 |
} |
} |
236 |
return; |
return; |
237 |
} |
} |
238 |
|
|
239 |
int blockid; |
Material material = Material.matchMaterial( split[1] ); |
240 |
try { |
if (material == null) { |
241 |
blockid = Integer.parseInt(split[1]); |
player.sendMessage("platform: blockid must be an integer"); |
|
} catch (Exception e) { |
|
|
player.sendMessage("setsurface: blockid must be an integer"); |
|
242 |
return; |
return; |
243 |
} |
} |
244 |
|
|
245 |
//check if the blockid is in the array of valid blocks |
//check if the blockid is in the array of valid blocks |
246 |
boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0); |
if ( ! valid_materials.contains(material) ) { |
|
|
|
|
if ( !validblock ) { |
|
247 |
player.sendMessage("setsurface: block now allowed"); |
player.sendMessage("setsurface: block now allowed"); |
248 |
return; |
return; |
249 |
} |
} |
252 |
int playerY = loc.getBlockY(); |
int playerY = loc.getBlockY(); |
253 |
int playerZ = loc.getBlockZ(); |
int playerZ = loc.getBlockZ(); |
254 |
|
|
255 |
if(playerY <= 2 && blockid != 7) { |
if(playerY <= 2 && material != Material.BEDROCK ) { |
256 |
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)"); |
257 |
return; |
return; |
258 |
} |
} |
264 |
//int y = getGroundLevel(x,z) - 1; |
//int y = getGroundLevel(x,z) - 1; |
265 |
int y = world.getHighestBlockYAt(x, z) ; |
int y = world.getHighestBlockYAt(x, z) ; |
266 |
|
|
267 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setType(material); |
268 |
} |
} |
269 |
} |
} |
270 |
} |
} |
309 |
private void fillArea(Player player, Location loc, String[] split) { |
private void fillArea(Player player, Location loc, String[] split) { |
310 |
int radius = Integer.parseInt(split[0]); |
int radius = Integer.parseInt(split[0]); |
311 |
|
|
312 |
int material = Material.DIRT.getId(); |
Material material = Material.DIRT; |
313 |
|
|
314 |
|
|
315 |
if (split.length == 2) { |
if (split.length == 2) { |
316 |
material = Integer.parseInt( split[1] ); |
material = Material.matchMaterial( split[1] ); |
317 |
|
if (material == null) { |
318 |
|
player.sendMessage("Unknown material: " + split[1] ); |
319 |
|
return; |
320 |
|
} |
321 |
} |
} |
322 |
|
|
323 |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
335 |
|
|
336 |
|
|
337 |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
338 |
world.getBlockAt(x, y, z).setTypeId(material); |
world.getBlockAt(x, y, z).setType( material ); |
339 |
} |
} |
340 |
|
|
341 |
} |
} |
419 |
player.sendMessage("Usage: /cylinder [radius] [material] "); |
player.sendMessage("Usage: /cylinder [radius] [material] "); |
420 |
return; |
return; |
421 |
} |
} |
422 |
int material = Integer.parseInt( split[1] ); |
|
423 |
|
Material material = Material.matchMaterial( split[1] ); |
424 |
|
if ( material == null) { |
425 |
|
player.sendMessage("/cylinder: unknown material: " + split[1]); |
426 |
|
return; |
427 |
|
} |
428 |
|
|
429 |
int radius = Integer.parseInt(split[0]); |
int radius = Integer.parseInt(split[0]); |
430 |
int diameter = (radius*2) + 1; |
int diameter = (radius*2) + 1; |
453 |
drawMap( loc, map, material ); |
drawMap( loc, map, material ); |
454 |
} |
} |
455 |
|
|
456 |
private void drawMap(Location loc, boolean[][] map, int material) { |
private void drawMap(Location loc, boolean[][] map, Material material) { |
457 |
int playerX = loc.getBlockX(); |
int playerX = loc.getBlockX(); |
458 |
int playerY = loc.getBlockY(); |
int playerY = loc.getBlockY(); |
459 |
int playerZ = loc.getBlockZ(); |
int playerZ = loc.getBlockZ(); |
468 |
|
|
469 |
if (map[i][j] == true) { |
if (map[i][j] == true) { |
470 |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
471 |
world.getBlockAt(x, y, z).setTypeId(material); |
world.getBlockAt(x, y, z).setType(material); |
472 |
} |
} |
473 |
} |
} |
474 |
|
|