From 8c8c162a5480bb561777ed9dcf485efd37208368 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Fri, 2 Mar 2012 20:13:45 +0100 Subject: [PATCH] Replaced all usage of CreatureType by EntityType. --- .../worldguard/bukkit/WorldConfiguration.java | 10 ++-- .../bukkit/WorldGuardEntityListener.java | 10 ++-- .../protection/flags/CreatureTypeFlag.java | 54 ------------------- .../protection/flags/DefaultFlag.java | 4 +- 4 files changed, 13 insertions(+), 65 deletions(-) delete mode 100644 src/main/java/com/sk89q/worldguard/protection/flags/CreatureTypeFlag.java diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java index e50944cc..dd58fec5 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -32,7 +32,7 @@ import com.sk89q.util.yaml.YAMLFormat; import com.sk89q.util.yaml.YAMLProcessor; import org.bukkit.block.Block; -import org.bukkit.entity.CreatureType; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import com.sk89q.worldguard.blacklist.Blacklist; @@ -112,7 +112,7 @@ public class WorldConfiguration { public boolean useRegions; public boolean highFreqFlags; public int regionWand = 287; - public Set blockCreatureSpawn; + public Set blockCreatureSpawn; // public boolean useiConomy; // public boolean buyOnClaim; // public double buyOnClaimPrice; @@ -375,12 +375,14 @@ private void loadConfiguration() { // buyOnClaim = getBoolean("iconomy.buy-on-claim", false); // buyOnClaimPrice = getDouble("iconomy.buy-on-claim-price", 1.0); - blockCreatureSpawn = new HashSet(); + blockCreatureSpawn = new HashSet(); for (String creatureName : getStringList("mobs.block-creature-spawn", null)) { - CreatureType creature = CreatureType.fromName(creatureName); + EntityType creature = EntityType.fromName(creatureName); if (creature == null) { plugin.getLogger().warning("Unknown mob type '" + creatureName + "'"); + } else if (!creature.isAlive()) { + plugin.getLogger().warning("Entity type '" + creatureName + "' is not a creature"); } else { blockCreatureSpawn.add(creature); } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index 97a8f93e..691121c6 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -29,11 +29,11 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Creature; -import org.bukkit.entity.CreatureType; import org.bukkit.entity.Creeper; import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Enderman; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Fireball; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Painting; @@ -628,9 +628,9 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { } WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld()); - CreatureType creaType = event.getCreatureType(); + EntityType entityType = event.getEntityType(); - if (wcfg.blockCreatureSpawn.contains(creaType)) { + if (wcfg.blockCreatureSpawn.contains(entityType)) { event.setCancelled(true); return; } @@ -649,8 +649,8 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { return; } - Set creatureTypes = set.getFlag(DefaultFlag.DENY_SPAWN); - if (creatureTypes != null && creatureTypes.contains(creaType)) { + Set entityTypes = set.getFlag(DefaultFlag.DENY_SPAWN); + if (entityTypes != null && entityTypes.contains(entityType)) { event.setCancelled(true); return; } diff --git a/src/main/java/com/sk89q/worldguard/protection/flags/CreatureTypeFlag.java b/src/main/java/com/sk89q/worldguard/protection/flags/CreatureTypeFlag.java deleted file mode 100644 index 36c28774..00000000 --- a/src/main/java/com/sk89q/worldguard/protection/flags/CreatureTypeFlag.java +++ /dev/null @@ -1,54 +0,0 @@ -// $Id$ -/* - * WorldGuard - * 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.worldguard.protection.flags; - -import org.bukkit.entity.CreatureType; - -/** - * Represents a creature type. - * - * @author sk89q - */ -public class CreatureTypeFlag extends EnumFlag { - - public CreatureTypeFlag(String name, RegionGroup defaultGroup) { - super(name, CreatureType.class, defaultGroup); - } - - public CreatureTypeFlag(String name) { - super(name, CreatureType.class); - } - - @Override - public CreatureType detectValue(String input) { - CreatureType lowMatch = null; - - for (CreatureType type : CreatureType.values()) { - if (type.name().equalsIgnoreCase(input.trim())) { - return type; - } - - if (type.name().toLowerCase().startsWith(input.toLowerCase().trim())) { - lowMatch = type; - } - } - - return lowMatch; - } -} diff --git a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java index 6da7abb2..ce04d8f9 100644 --- a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -19,7 +19,7 @@ package com.sk89q.worldguard.protection.flags; -import org.bukkit.entity.CreatureType; +import org.bukkit.entity.EntityType; /** * @@ -64,7 +64,7 @@ public final class DefaultFlag { public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell", RegionGroup.ALL); public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter", RegionGroup.ALL); public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave", RegionGroup.ALL); - public static final SetFlag DENY_SPAWN = new SetFlag("deny-spawn", RegionGroup.ALL, new CreatureTypeFlag(null)); + public static final SetFlag DENY_SPAWN = new SetFlag("deny-spawn", RegionGroup.ALL, new EntityTypeFlag(null)); public static final IntegerFlag HEAL_DELAY = new IntegerFlag("heal-delay", RegionGroup.ALL); public static final IntegerFlag HEAL_AMOUNT = new IntegerFlag("heal-amount", RegionGroup.ALL); public static final IntegerFlag MIN_HEAL = new IntegerFlag("heal-min-health", RegionGroup.ALL);