--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java 2018/07/18 07:41:35 3238 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/TemplateCommand.java 2018/07/18 07:59:05 3239 @@ -7,6 +7,7 @@ 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; @@ -17,16 +18,6 @@ public class TemplateCommand implements CommandExecutor { - class Pair { - public int id; - public int subId; - - public Pair (int i, int s) { - id = i; - subId = s; - } - - } Plugin plugin; @@ -59,7 +50,7 @@ return true; } - Pair[][][] template; + Material[][][] template; try { template = parseFile(templateFile); @@ -82,7 +73,7 @@ - Pair[][][] parseFile(File templateFile) throws Exception { + Material[][][] parseFile(File templateFile) throws Exception { int lines = 0; @@ -111,7 +102,7 @@ int ysize = Integer.parseInt(dimensions[1]); int zsize = Integer.parseInt(dimensions[2]); - Pair[][][] array = new Pair[xsize][ysize][zsize]; + Material[][][] array = new Material[xsize][ysize][zsize]; int x = 0; int y = 0; @@ -137,31 +128,19 @@ } for (int i=0; i255) { - throw new Exception( "Template: invalid value on line " + lines + ": " + val ); - } - - if (element.length == 2) { - try { - subval = Integer.parseInt( element[1] ); - } catch (Exception e) { - throw new Exception( "Template: invalid value on line " + lines + ": " + element[1] ); - } - } - - array[x][y][i] = new Pair(val,subval); + + array[x][y][i] = m; } x++; @@ -186,7 +165,7 @@ } - void buildTemplate(Location loc, Pair[][][] template, int pass) { + void buildTemplate(Location loc, Material[][][] template, int pass) { World world = loc.getWorld(); @@ -222,29 +201,31 @@ } - int type = template[i][j][k].id; - byte data = (byte) template[i][j][k].subId; + - if (type == -1) { - continue; - } + Material mat = template[i][j][k]; //plugin.getLogger().info( String.format( "Setting typeid at %d,%d,%d to %d", x,y,z, type) ); + //TODO: rewrite this to build a Set of skipped matterials if (pass == 1) { - if ( type == 50 || type == 75 || type == 76) //torch / redstone torch + + if ( mat == Material.TORCH || mat == Material.REDSTONE_TORCH || mat == Material.REDSTONE_WALL_TORCH) //torch / redstone torch continue; - if (type == 64 || type==71) //door / irondoor + + if (mat == Material.ACACIA_DOOR || mat == Material.BIRCH_DOOR || mat == Material.DARK_OAK_DOOR ) //door / irondoor continue; - if (type == 68) // sign + + if (mat == Material.SIGN) // sign continue; - if (type == 65) // ladder + if (mat == Material.LADDER) // ladder continue; - if (type == 67) // steps + if (mat == Material.OAK_STAIRS) //TODO: need to take all star variants into account continue; } - world.getBlockAt(x, y, z).setTypeIdAndData(type, data, true); + + world.getBlockAt(x, y, z).setType(mat); } }