From 7d81303fea8ca56628eccbcfdc4bdb0c4fc34b84 Mon Sep 17 00:00:00 2001 From: sk89q Date: Thu, 10 Mar 2011 00:48:13 -0800 Subject: [PATCH] Added an alias for wool colors as though they were blocks, so you can now do //set blue, etc. --- src/com/sk89q/worldedit/WorldEdit.java | 76 +++++++++++++++----------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/src/com/sk89q/worldedit/WorldEdit.java b/src/com/sk89q/worldedit/WorldEdit.java index 6760d48e5..f35a780dc 100644 --- a/src/com/sk89q/worldedit/WorldEdit.java +++ b/src/com/sk89q/worldedit/WorldEdit.java @@ -198,7 +198,7 @@ public class WorldEdit { String[] args1 = args0[0].split(":", 2); String testID = args1[0]; - int data; + int data = -1; // Attempt to parse the item ID or otherwise resolve an item/block // name to its numeric ID @@ -215,45 +215,55 @@ public class WorldEdit { } if (blockType == null) { - throw new UnknownItemException(arg); + // Maybe it's a cloth + ClothColor col = ClothColor.lookup(testID); + + if (col != null) { + blockType = BlockType.fromID(35); + data = col.getID(); + } else { + throw new UnknownItemException(arg); + } } - // Parse the block data (optional) - try { - data = args1.length > 1 ? Integer.parseInt(args1[1]) : 0; - if (data > 15 || data < 0) { - data = 0; - } - } catch (NumberFormatException e) { - if (blockType == BlockType.CLOTH) { - ClothColor col = ClothColor.lookup(args1[1]); - - if (col != null) { - data = col.getID(); - } else { - throw new InvalidItemException(arg, "Unknown cloth color '" + args1[1] + "'"); + if (data == -1) { // Block data not yet detected + // Parse the block data (optional) + try { + data = args1.length > 1 ? Integer.parseInt(args1[1]) : 0; + if (data > 15 || data < 0) { + data = 0; } - } else if (blockType == BlockType.STEP - || blockType == BlockType.DOUBLE_STEP) { - BlockType dataType = BlockType.lookup(args1[1]); - - if (dataType != null) { - if (dataType == BlockType.STONE) { - data = 0; - } else if (dataType == BlockType.SANDSTONE) { - data = 1; - } else if (dataType == BlockType.WOOD) { - data = 2; - } else if (dataType == BlockType.COBBLESTONE) { - data = 3; + } catch (NumberFormatException e) { + if (blockType == BlockType.CLOTH) { + ClothColor col = ClothColor.lookup(args1[1]); + + if (col != null) { + data = col.getID(); } else { - throw new InvalidItemException(arg, "Invalid step type '" + args1[1] + "'"); + throw new InvalidItemException(arg, "Unknown cloth color '" + args1[1] + "'"); + } + } else if (blockType == BlockType.STEP + || blockType == BlockType.DOUBLE_STEP) { + BlockType dataType = BlockType.lookup(args1[1]); + + if (dataType != null) { + if (dataType == BlockType.STONE) { + data = 0; + } else if (dataType == BlockType.SANDSTONE) { + data = 1; + } else if (dataType == BlockType.WOOD) { + data = 2; + } else if (dataType == BlockType.COBBLESTONE) { + data = 3; + } else { + throw new InvalidItemException(arg, "Invalid step type '" + args1[1] + "'"); + } + } else { + throw new InvalidItemException(arg, "Unknown step type '" + args1[1] + "'"); } } else { - throw new InvalidItemException(arg, "Unknown step type '" + args1[1] + "'"); + throw new InvalidItemException(arg, "Unknown data value '" + args1[1] + "'"); } - } else { - throw new InvalidItemException(arg, "Unknown data value '" + args1[1] + "'"); } }