From 21ca317d2c01b7fcae058ce5a748a07b29231093 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 18 Feb 2011 16:24:56 -0800 Subject: [PATCH] Improved parsing of block pattern/data syntax. --- src/com/sk89q/worldedit/WorldEdit.java | 40 +++++++++++++++++--------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/com/sk89q/worldedit/WorldEdit.java b/src/com/sk89q/worldedit/WorldEdit.java index 31fc33926..85cf0d0b8 100644 --- a/src/com/sk89q/worldedit/WorldEdit.java +++ b/src/com/sk89q/worldedit/WorldEdit.java @@ -247,8 +247,14 @@ public class WorldEdit { // Allow setting mob spawn type } else if (blockType == BlockType.MOB_SPAWNER) { if (args0.length > 1) { - if (!server.isValidMobType(args0[1])) { - throw new InvalidItemException(arg, "Unknown mob type '" + args0[1] + "'"); + String mobName = args0[1]; + if (mobName.length() > 1) { + mobName = mobName.substring(0, 1).toUpperCase() + + mobName.substring(1); + } + + if (!server.isValidMobType(mobName)) { + throw new InvalidItemException(arg, "Unknown mob type '" + mobName + "'"); } return new MobSpawnerBlock(data, args0[1]); } else { @@ -303,20 +309,26 @@ public class WorldEdit { String[] items = list.split(","); - if (list.equals("#clipboard") || list.equals("#copy")) { - LocalSession session = getSession(player); - CuboidClipboard clipboard; - - try { - clipboard = session.getClipboard(); - } catch (EmptyClipboardException e) { - player.printError("Copy a selection first with //copy."); - throw new UnknownItemException("#clipboard"); + // Handle special block pattern types + if (list.charAt(0) == '#') { + if (list.equals("#clipboard") || list.equals("#copy")) { + LocalSession session = getSession(player); + CuboidClipboard clipboard; + + try { + clipboard = session.getClipboard(); + } catch (EmptyClipboardException e) { + player.printError("Copy a selection first with //copy."); + throw new UnknownItemException("#clipboard"); + } + + return new ClipboardPattern(clipboard); + } else { + throw new UnknownItemException(list); } - - return new ClipboardPattern(clipboard); } + // If it's only one block, then just return that single one if (items.length == 1) { return new SingleBlockPattern(getBlock(player, items[0])); } @@ -327,6 +339,8 @@ public class WorldEdit { BaseBlock block; double chance; + + // Parse special percentage syntax if (s.matches("[0-9]+(?:\\.(?:[0-9]+)?)?%.*")) { String[] p = s.split("%"); chance = Double.parseDouble(p[0]);