From 768adee389a9ea51196c79a3c46454f2178961ac Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 3 Nov 2013 19:34:46 +0100 Subject: [PATCH] Added a "hand" pseudo block type that uses the currently selected block. --- .../java/com/sk89q/worldedit/WorldEdit.java | 71 +++++++++++-------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 8bfd54059..3f1f2a751 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -397,44 +397,55 @@ public class WorldEdit { int data = -1; boolean parseDataValue = true; + if ("hand".equalsIgnoreCase(testID)) { + // Get the block type from the item in the user's hand. + final BaseBlock blockInHand = player.getBlockInHand(); + if (blockInHand.getClass() != BaseBlock.class) { + return blockInHand; + } - // Attempt to parse the item ID or otherwise resolve an item/block - // name to its numeric ID - try { - blockId = Integer.parseInt(testID); + blockId = blockInHand.getId(); blockType = BlockType.fromID(blockId); - } catch (NumberFormatException e) { - blockType = BlockType.lookup(testID); - if (blockType == null) { - int t = server.resolveItem(testID); - if (t > 0) { - blockType = BlockType.fromID(t); // Could be null - blockId = t; + data = blockInHand.getData(); + } else { + // Attempt to parse the item ID or otherwise resolve an item/block + // name to its numeric ID + try { + blockId = Integer.parseInt(testID); + blockType = BlockType.fromID(blockId); + } catch (NumberFormatException e) { + blockType = BlockType.lookup(testID); + if (blockType == null) { + int t = server.resolveItem(testID); + if (t > 0) { + blockType = BlockType.fromID(t); // Could be null + blockId = t; + } } } - } - if (blockId == -1 && blockType == null) { - // Maybe it's a cloth - ClothColor col = ClothColor.lookup(testID); - if (col == null) { - throw new UnknownItemException(arg); + if (blockId == -1 && blockType == null) { + // Maybe it's a cloth + ClothColor col = ClothColor.lookup(testID); + if (col == null) { + throw new UnknownItemException(arg); + } + + blockType = BlockType.CLOTH; + data = col.getID(); + + // Prevent overriding the data value + parseDataValue = false; } - blockType = BlockType.CLOTH; - data = col.getID(); + // Read block ID + if (blockId == -1) { + blockId = blockType.getID(); + } - // Prevent overriding the data value - parseDataValue = false; - } - - // Read block ID - if (blockId == -1) { - blockId = blockType.getID(); - } - - if (!player.getWorld().isValidBlockType(blockId)) { - throw new UnknownItemException(arg); + if (!player.getWorld().isValidBlockType(blockId)) { + throw new UnknownItemException(arg); + } } if (!allowNoData && data == -1) {