Minor code cleanup

This commit is contained in:
libraryaddict 2013-11-24 07:29:13 +13:00
parent d6fba4c402
commit 6dfeb5f10a
3 changed files with 21 additions and 20 deletions

View File

@ -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<WrappedWatchableObject> 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) {

View File

@ -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);

View File

@ -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) {