package dk.thoerup.bukkit.hoeruputils.creative; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class GeneralContractorCommands implements CommandExecutor{ final static int Y_MAX = 255; //@Override public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { if (! (sender instanceof Player) ) { return false; } Player player = (Player) sender; Location loc = player.getLocation(); if ( ! loc.getWorld().getName().equals("creative")) { player.sendMessage( ChatColor.RED + "This command may only be used in creative world" ); return true; } //System.out.println( ">>" + label); //DEBUG if ( label.equals("levelarea") ) { if (validateLevelOrFill(player, args) ) { levelArea(player, loc, args); } return true; } if ( label.equals("fillarea") ) { if (validateLevelOrFill(player, args) ) { fillArea(player, loc, args); } return true; } if ( label.equals("slopearea") ) { slopeArea(player, loc, args); return true; } if ( label.equals("setsurface") ) { setSurface(player, loc, args); return true; } return false; } void slopeArea(Player player, Location loc, String[] args) { int radius = Integer.parseInt(args[1]); System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius); int playerX = loc.getBlockX(); int playerY = loc.getBlockY(); int playerZ = loc.getBlockZ(); World world = loc.getWorld(); for (int x=(playerX-radius); x<=(playerX+radius); x++) { for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { int xdist = Math.abs(playerX-x); int zdist = Math.abs(playerZ-z); int dist = Math.max(xdist,zdist); //for (int y=playerY; y<=playerY+radius; y++) { for (int y=(playerY+dist); y<=Y_MAX; y++) { world.getBlockAt(x, y, z).setType(Material.AIR); } } } } private void setSurface(Player player, Location loc, String[] split) { 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} ; if (split.length != 3) { player.sendMessage("Usage /setsurface [radius] [blockID]"); return; } int radius; try { radius = Integer.parseInt(split[1]); } catch (Exception e) { player.sendMessage("setsurface: radius must be an integer"); return; } if (radius > 20) { player.sendMessage("setsurface: radius may not exceed 20"); return; } int blockid; try { blockid = Integer.parseInt(split[2]); } catch (Exception e) { player.sendMessage("setsurface: blockid must be an integer"); return; } boolean validblock = false; for (int i=0; i 3) { player.sendMessage("Usage: " + split[0] + " [radius]"); return false; } int radius; try { radius = Integer.parseInt(split[1]); } catch (Exception e) { player.sendMessage(split[0] + ": radius must be an integer"); return false; } if (radius > 20) { player.sendMessage(split[0] + ": radius may not exceed 20"); return false; } if (split.length == 3) { int id; try { id = Integer.parseInt( split[2] ); } catch (Exception e) { player.sendMessage(split[0] + ": id must be an integer"); return false; } if ( id == 46) { player.sendMessage("Sorry dave, i can't do that"); return false; } } return true; } private void fillArea(Player player, Location loc, String[] split) { int radius = Integer.parseInt(split[1]); int material = Material.DIRT.getId(); if (split.length == 3) { material = Integer.parseInt( split[2] ); } System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); int playerX = loc.getBlockX(); int playerY = loc.getBlockY(); int playerZ = loc.getBlockZ(); World world = loc.getWorld(); for (int x=(playerX-radius); x<=(playerX+radius); x++) { for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { for (int y=world.getHighestBlockYAt(x, z); y