--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/creative/GeneralContractorCommands.java 2012/03/13 08:45:07 1731 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/creative/GeneralContractorCommands.java 2017/05/29 13:03:52 3196 @@ -11,6 +11,8 @@ import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; public class GeneralContractorCommands implements CommandExecutor{ @@ -24,13 +26,52 @@ } final static int Y_MAX = 255; - 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[] = { + Material.STONE, + Material.GRASS, + Material.DIRT, + Material.COBBLESTONE, + Material.WOOD, + Material.BEDROCK, + Material.WATER, + Material.SAND, + Material.GRAVEL, + Material.GOLD_ORE, + Material.IRON_ORE, + Material.COAL_ORE, + Material.LOG, + Material.LEAVES, + Material.GLASS, + Material.LAPIS_ORE, + Material.LAPIS_BLOCK, + Material.SANDSTONE, + Material.WOOL, + Material.GOLD_BLOCK, + Material.IRON_BLOCK, + Material.BRICK, + Material.MOSSY_COBBLESTONE, + Material.OBSIDIAN, + Material.DIAMOND_ORE, + Material.DIAMOND_BLOCK, + Material.ICE, + Material.SNOW, + Material.CLAY, + Material.NETHERRACK, + Material.SOUL_SAND + }; +//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 Set valid_materials = new HashSet(); HashMap commands = new HashMap(); public GeneralContractorCommands() { Arrays.sort(valid_block_array); + + for (Material mat : valid_block_array) { + valid_materials.add( mat ); + } } //@Override @@ -68,6 +109,12 @@ return true; } + if ( label.equals("createcave") ) { + if (validateLevelOrFill(player, label, args) ) { + createCave(player, loc, args); + } + return true; + } if ( label.equals("fillarea") ) { if (validateLevelOrFill(player, label, args) ) { @@ -75,6 +122,16 @@ } return true; } + + if (label.equals("levelandfillarea") ) { + if (validateLevelOrFill(player, label, args) ) { + + levelArea(player, loc, args); + fillArea(player, loc, args); + setSurface(player, loc, args); + + } + } if ( label.equals("slopearea") ) { slopeArea(player, loc, args); @@ -91,6 +148,15 @@ platform(player,loc,args); return true; } + + if (label.equals("cylinder") ) { + if (validateLevelOrFill(player, label, args) ) { + cylinder(player,loc,args); + } + return true; + } + + return false; @@ -137,7 +203,7 @@ private void platform(Player player, Location loc, String[] split) { if (split.length != 2) { - player.sendMessage("Usage /platform [radius] [blockID]"); + player.sendMessage("Usage /platform [radius] [material]"); return; } @@ -149,16 +215,14 @@ return; } - if (radius > 20) { - player.sendMessage("platform: radius may not exceed 20"); + if (radius > 25) { + player.sendMessage("platform: radius may not exceed 25"); return; } - int blockid; - try { - blockid = Integer.parseInt(split[1]); - } catch (Exception e) { - player.sendMessage("platform: blockid must be an integer"); + Material material = Material.matchMaterial( split[1] ); + if (material == null) { + player.sendMessage("platform: unknown material: " + split[1] ); return; } /* @@ -186,7 +250,7 @@ for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { int y = playerY - 1; - world.getBlockAt(x, y, z).setTypeId(blockid); + world.getBlockAt(x, y, z).setType( material ); } } } @@ -206,23 +270,19 @@ return; } - if (radius > 20) { - player.sendMessage("setsurface: radius may not exceed 20"); + if (radius > 25) { + player.sendMessage("setsurface: radius may not exceed 25"); return; } - int blockid; - try { - blockid = Integer.parseInt(split[1]); - } catch (Exception e) { - player.sendMessage("setsurface: blockid must be an integer"); + Material material = Material.matchMaterial( split[1] ); + if (material == null) { + player.sendMessage("setsurface: unknown material: " + split[1] ); return; } //check if the blockid is in the array of valid blocks - boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0); - - if ( !validblock ) { + if ( ! valid_materials.contains(material) ) { player.sendMessage("setsurface: block now allowed"); return; } @@ -231,7 +291,7 @@ int playerY = loc.getBlockY(); int playerZ = loc.getBlockZ(); - if(playerY <= 2 && blockid != 7) { + if(playerY <= 2 && material != Material.BEDROCK ) { player.sendMessage("setsurface: at this level you may only use bedrock(id=7)"); return; } @@ -242,8 +302,9 @@ for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { //int y = getGroundLevel(x,z) - 1; int y = world.getHighestBlockYAt(x, z) ; + y -= 1; - world.getBlockAt(x, y, z).setTypeId(blockid); + world.getBlockAt(x, y, z).setType(material); } } } @@ -262,20 +323,18 @@ return false; } - if (radius > 20) { - player.sendMessage(label + ": radius may not exceed 20"); + if (radius > 25) { + player.sendMessage(label + ": radius may not exceed 25"); return false; } if (split.length == 2) { - int id; - try { - id = Integer.parseInt( split[1] ); - } catch (Exception e) { - player.sendMessage(label + ": id must be an integer"); + Material material = Material.matchMaterial( split[1] ); + if (material == null) { + player.sendMessage(label + ": unknown material: " + split[1] ); return false; } - if ( id == 46) { + if ( material == Material.TNT) { player.sendMessage("Sorry dave, i can't do that"); return false; } @@ -288,10 +347,15 @@ private void fillArea(Player player, Location loc, String[] split) { int radius = Integer.parseInt(split[0]); - int material = Material.DIRT.getId(); + Material material = Material.DIRT; + if (split.length == 2) { - material = Integer.parseInt( split[1] ); + material = Material.matchMaterial( split[1] ); + if (material == null) { + player.sendMessage("Unknown material: " + split[1] ); + return; + } } System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); @@ -309,7 +373,7 @@ for (int y=world.getHighestBlockYAt(x, z); y