From 6dfeb5f10a161e8cf9e235774aa51cb6cfcfefea Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 24 Nov 2013 07:29:13 +1300 Subject: [PATCH] Minor code cleanup --- .../libraryaddict/disguise/LibsDisguises.java | 16 ++++++---------- .../disguise/disguisetypes/Disguise.java | 17 ++++++++++------- .../disguise/disguisetypes/DisguiseType.java | 8 +++++--- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 76e5a662..d78134a4 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -3,8 +3,6 @@ package me.libraryaddict.disguise; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; -import java.util.List; - import me.libraryaddict.disguise.commands.*; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; @@ -38,19 +36,19 @@ public class LibsDisguises extends JavaPlugin { public void onEnable() { saveDefaultConfig(); FileConfiguration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml")); - boolean modified = false; + boolean needToSaveConfig = false; try { - for (String option : YamlConfiguration - .loadConfiguration(this.getClassLoader().getResource("config.yml").openStream()).getKeys(false)) { + for (String option : YamlConfiguration.loadConfiguration(getClassLoader().getResource("config.yml").openStream()) + .getKeys(false)) { if (!config.contains(option)) { config.set(option, getConfig().get(option)); - modified = true; + needToSaveConfig = true; } } } catch (IOException e) { e.printStackTrace(); } - if (modified) { + if (needToSaveConfig) { try { config.save(new File(getDataFolder(), "config.yml")); } catch (IOException e) { @@ -193,9 +191,7 @@ public class LibsDisguises extends JavaPlugin { } } DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize); - WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); - List watchers = dataWatcher.getWatchableObjects(); - for (WrappedWatchableObject watch : watchers) + for (WrappedWatchableObject watch : WrappedDataWatcher.getEntityWatcher(bukkitEntity).getWatchableObjects()) disguiseValues.setMetaValue(watch.getIndex(), watch.getValue()); DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); if (sound != null) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index d3bbecc5..7766e782 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -54,16 +54,16 @@ public abstract class Disguise { return; if (newType.getEntityType() == null) { throw new RuntimeException("DisguiseType " + newType - + " was attempted to construct a disguise, but this version of craftbukkit does not have that entity"); + + " was used to attempt to construct a disguise, but this version of craftbukkit does not have that entity"); } // Set the disguise type disguiseType = newType; // Set the option to replace the sounds setReplaceSounds(doSounds); // Get if they are a adult now.. - boolean isBaby = false; + boolean isAdult = true; if (this instanceof MobDisguise) { - isBaby = !((MobDisguise) this).isAdult(); + isAdult = ((MobDisguise) this).isAdult(); } try { // Construct the FlagWatcher from the stored class @@ -72,7 +72,7 @@ public abstract class Disguise { e.printStackTrace(); } // Set the disguise if its a baby or not - if (isBaby) { + if (!isAdult) { if (getWatcher() instanceof AgeableWatcher) { ((AgeableWatcher) getWatcher()).setAdult(false); } else if (getWatcher() instanceof ZombieWatcher) { @@ -80,11 +80,13 @@ public abstract class Disguise { } } // If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton - if (getType() == DisguiseType.WITHER_SKELETON) + if (getType() == DisguiseType.WITHER_SKELETON) { getWatcher().setValue(13, (byte) 1); + } // Else if its a zombie, but the disguise type is a zombie villager. Set the value. - else if (getType() == DisguiseType.ZOMBIE_VILLAGER) + else if (getType() == DisguiseType.ZOMBIE_VILLAGER) { getWatcher().setValue(13, (byte) 1); + } // Else if its a horse. Set the horse watcher type else if (getWatcher() instanceof HorseWatcher) { try { @@ -401,8 +403,9 @@ public abstract class Disguise { * Set the entity of the disguise. Only used for internal things. */ public void setEntity(org.bukkit.entity.Entity entity) { - if (this.entity != null) + if (this.entity != null) { throw new RuntimeException("This disguise is already in use! Try .clone()"); + } this.entity = entity; setupWatcher(); velocityRunnable.runTaskTimer(plugin, 1, 1); diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 1b13a462..911a2a95 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -129,6 +129,7 @@ public enum DisguiseType { ZOMBIE(), ZOMBIE_VILLAGER(); + static { for (DisguiseType type : values()) { try { @@ -160,6 +161,7 @@ public enum DisguiseType { type.setEntityType(entityType); } } catch (Throwable ex) { + // This version of craftbukkit doesn't have the disguise. } } } @@ -214,15 +216,15 @@ public enum DisguiseType { } public boolean isMisc() { - return !entityType.isAlive(); + return !getEntityType().isAlive(); } public boolean isMob() { - return entityType.isAlive() && entityType != EntityType.PLAYER; + return getEntityType().isAlive() && this != DisguiseType.PLAYER; } public boolean isPlayer() { - return entityType == EntityType.PLAYER; + return this == DisguiseType.PLAYER; } private void setEntityType(EntityType entityType) {