From e20cca38fd5cb6f2895fe79afe4f900bf6dc4e59 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 4 Jun 2011 22:22:23 -0700 Subject: [PATCH] Change the block type check to be implementation-dependent. The Bukkit plugin now checks Bukkit's Material. --- .../java/com/sk89q/worldedit/EditSession.java | 2 +- .../java/com/sk89q/worldedit/LocalWorld.java | 10 ++++++++++ .../com/sk89q/worldedit/ServerInterface.java | 10 ++++++++++ .../java/com/sk89q/worldedit/WorldEdit.java | 19 +++++++++++++++---- .../bukkit/BukkitServerInterface.java | 5 +++++ .../sk89q/worldedit/bukkit/BukkitWorld.java | 12 ++++++++++++ 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index e02902c94..65ea0ed73 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -164,7 +164,7 @@ public class EditSession { } // No invalid blocks - if ((type > 32 && type < 35) || type == 36 || type == 29 || type > 96) { + if (!world.isValidBlockType(type)) { return false; } diff --git a/src/main/java/com/sk89q/worldedit/LocalWorld.java b/src/main/java/com/sk89q/worldedit/LocalWorld.java index 277f18e8a..9c6785644 100644 --- a/src/main/java/com/sk89q/worldedit/LocalWorld.java +++ b/src/main/java/com/sk89q/worldedit/LocalWorld.java @@ -304,6 +304,16 @@ public abstract class LocalWorld { * @return */ public abstract int removeEntities(EntityType type, Vector origin, int radius); + + /** + * Returns whether a block has a valid ID. + * + * @param type + * @return + */ + public boolean isValidBlockType(int type) { + return !((type > 32 && type < 35) || type == 36 || type == 29 || type > 96); + } /** * Compare if the other world is equal. diff --git a/src/main/java/com/sk89q/worldedit/ServerInterface.java b/src/main/java/com/sk89q/worldedit/ServerInterface.java index 112ffd8dd..f66e512ed 100644 --- a/src/main/java/com/sk89q/worldedit/ServerInterface.java +++ b/src/main/java/com/sk89q/worldedit/ServerInterface.java @@ -40,6 +40,16 @@ public abstract class ServerInterface { */ public abstract boolean isValidMobType(String type); + /** + * Returns whether a block has a valid ID. + * + * @param type + * @return + */ + public boolean isValidBlockType(int type) { + return !((type > 32 && type < 35) || type == 36 || type == 29 || type > 96); + } + /** * Reload WorldEdit configuration. */ diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 835f3f297..1111891b5 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -202,13 +202,15 @@ public class WorldEdit { String[] args0 = arg.split("\\|"); String[] args1 = args0[0].split(":", 2); String testID = args1[0]; + int blockId = -1; int data = -1; // Attempt to parse the item ID or otherwise resolve an item/block // name to its numeric ID try { - blockType = BlockType.fromID(Integer.parseInt(testID)); + blockId = Integer.parseInt(testID); + blockType = BlockType.fromID(blockId); } catch (NumberFormatException e) { blockType = BlockType.lookup(testID); if (blockType == null) { @@ -219,7 +221,7 @@ public class WorldEdit { } } - if (blockType == null) { + if (blockId == -1 && blockType == null) { // Maybe it's a cloth ClothColor col = ClothColor.lookup(testID); @@ -231,6 +233,15 @@ public class WorldEdit { } } + // Read block ID + if (blockId == -1) { + blockId = blockType.getID(); + } + + if (!server.isValidBlockType(blockId)) { + throw new UnknownItemException(arg); + } + if (data == -1) { // Block data not yet detected // Parse the block data (optional) try { @@ -274,7 +285,7 @@ public class WorldEdit { // Check if the item is allowed if (allAllowed || player.hasPermission("worldedit.anyblock") - || !config.disallowedBlocks.contains(blockType.getID())) { + || !config.disallowedBlocks.contains(blockId)) { // Allow special sign text syntax if (blockType == BlockType.SIGN_POST @@ -317,7 +328,7 @@ public class WorldEdit { } } - return new BaseBlock(blockType.getID(), data); + return new BaseBlock(blockId, data); } throw new DisallowedItemException(arg); diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index 32739e9f3..6cbcf4627 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -42,6 +42,11 @@ public class BukkitServerInterface extends ServerInterface { public boolean isValidMobType(String type) { return CreatureType.fromName(type) != null; } + + @Override + public boolean isValidBlockType(int type) { + return Material.getMaterial(type) != null; + } @Override public void reload() { diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index dce97468c..0b309d01b 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -39,6 +39,7 @@ import org.bukkit.entity.Wolf; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.TreeType; import org.bukkit.World; import com.sk89q.worldedit.EditSession; @@ -627,6 +628,17 @@ public class BukkitWorld extends LocalWorld { return true; } + + /** + * Returns whether a block has a valid ID. + * + * @param type + * @return + */ + @Override + public boolean isValidBlockType(int type) { + return Material.getMaterial(type) != null; + } @Override public boolean equals(Object other) {