From 46ba1c7f5b935bbecb72b770dabc7aea9eeabc04 Mon Sep 17 00:00:00 2001 From: md-5 Date: Tue, 6 Sep 2011 18:06:17 +1000 Subject: [PATCH] Added mob type enum and subsequently removed case sensitivity from //set with mobspawners. --- .../java/com/sk89q/worldedit/WorldEdit.java | 13 ++--- .../worldedit/blocks/MobSpawnerBlock.java | 4 +- .../com/sk89q/worldedit/blocks/MobType.java | 54 +++++++++++++++++++ 3 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/sk89q/worldedit/blocks/MobType.java diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 23b7224fb..0fef4f0f9 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -377,17 +377,18 @@ public class WorldEdit { } else if (blockType == BlockType.MOB_SPAWNER) { if (args0.length > 1) { String mobName = args0[1]; - if (mobName.length() > 1) { - mobName = mobName.substring(0, 1).toUpperCase() - + mobName.substring(1); + for (MobType mobType : MobType.values()){ + if (mobType.getName().toLowerCase().equals(mobName.toLowerCase())){ + mobName = mobType.getName(); + break; + } } - if (!server.isValidMobType(mobName)) { throw new InvalidItemException(arg, "Unknown mob type '" + mobName + "'"); } - return new MobSpawnerBlock(data, args0[1]); + return new MobSpawnerBlock(data, mobName); } else { - return new MobSpawnerBlock(data, "Pig"); + return new MobSpawnerBlock(data, MobType.PIG.getName()); } // Allow setting note diff --git a/src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java b/src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java index b9d58f976..afcbd3c3c 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java +++ b/src/main/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.HashMap; /** - * Represents chests. + * Represents mob spawners. * * @author sk89q */ @@ -45,7 +45,7 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock { */ public MobSpawnerBlock() { super(BlockID.MOB_SPAWNER); - this.mobType = "Pig"; + this.mobType = MobType.PIG.getName(); } /** diff --git a/src/main/java/com/sk89q/worldedit/blocks/MobType.java b/src/main/java/com/sk89q/worldedit/blocks/MobType.java new file mode 100644 index 000000000..78dbd0df3 --- /dev/null +++ b/src/main/java/com/sk89q/worldedit/blocks/MobType.java @@ -0,0 +1,54 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.blocks; + +/** + * Represents the possible types of mobs. + */ +public enum MobType { + CAVE_SPIDER("CaveSpider"), + CHICKEN("Chicken"), + COW("Cow"), + CREEPER("Creeper"), + ENDERMAN("Enderman"), + GHAST("Ghast"), + GIANT("Giant"), + MONSTER("Monster"), + PIG("Pig"), + PIG_ZOMBIE("PigZombie"), + SHEEP("Sheep"), + SILVERFISH("Silverfish"), + SKELETON("Skeleton"), + SLIME("Slime"), + SPIDER("Spider"), + SQUID("Squid"), + ZOMBIE("Zombie"), + WOLF("Wolf"); + + private String name; + + private MobType(String name) { + this.name = name; + } + + public String getName() { + return name; + } +}