From b96337f29b8c041b8fee7a2bf5837c021625b702 Mon Sep 17 00:00:00 2001 From: riking Date: Tue, 3 Jun 2014 17:42:13 -0700 Subject: [PATCH] Refactor out initConfig method --- .../disguise/DisguiseConfig.java | 35 +++++++++++++++++++ .../libraryaddict/disguise/LibsDisguises.java | 34 ++---------------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index 9b9f3fa6..82bfbb31 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -1,6 +1,8 @@ package me.libraryaddict.disguise; import me.libraryaddict.disguise.utilities.PacketsManager; +import org.bukkit.ChatColor; +import org.bukkit.configuration.ConfigurationSection; public class DisguiseConfig { private static boolean animationEnabled; @@ -346,4 +348,37 @@ public class DisguiseConfig { private DisguiseConfig() { } + public static void initConfig(ConfigurationSection config) { + setSoundsEnabled(config.getBoolean("DisguiseSounds")); + setVelocitySent(config.getBoolean("SendVelocity")); + setViewDisguises(config.getBoolean("ViewSelfDisguises")); + setHearSelfDisguise(config.getBoolean("HearSelfDisguise")); + setHideArmorFromSelf(config.getBoolean("RemoveArmor")); + setHideHeldItemFromSelf(config.getBoolean("RemoveHeldItem")); + setAddEntityAnimations(config.getBoolean("AddEntityAnimations")); + setNameOfPlayerShownAboveDisguise(config.getBoolean("ShowNamesAboveDisguises")); + setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible")); + setModifyBoundingBox(config.getBoolean("ModifyBoundingBox")); + setMonstersIgnoreDisguises(config.getBoolean("MonstersIgnoreDisguises")); + setDisguiseBlownOnAttack(config.getBoolean("BlowDisguises")); + setDisguiseBlownMessage(ChatColor.translateAlternateColorCodes('&', + config.getString("BlownDisguiseMessage"))); + setKeepDisguiseOnPlayerDeath(config.getBoolean("KeepDisguises.PlayerDeath")); + setKeepDisguiseOnPlayerLogout(config.getBoolean("KeepDisguises.PlayerLogout")); + setKeepDisguiseOnEntityDespawn(config.getBoolean("KeepDisguises.EntityDespawn")); + setMiscDisguisesForLivingEnabled(config.getBoolean("MiscDisguisesForLiving")); + setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement")); + setWitherSkullPacketsEnabled(config.getBoolean("PacketsEnabled.WitherSkull")); + setEnquipmentPacketsEnabled(config.getBoolean("PacketsEnabled.Enquipment")); + setAnimationPacketsEnabled(config.getBoolean("PacketsEnabled.Animation")); + setBedPacketsEnabled(config.getBoolean("PacketsEnabled.Bed")); + setRidingPacketsEnabled(config.getBoolean("PacketsEnabled.Riding")); + setEntityStatusPacketsEnabled(config.getBoolean("PacketsEnabled.EntityStatus")); + setCollectPacketsEnabled(config.getBoolean("PacketsEnabled.Collect")); + setMetadataPacketsEnabled(config.getBoolean("PacketsEnabled.Metadata")); + setMaxHealthDeterminedByDisguisedEntity(config.getBoolean("MaxHealthDeterminedByEntity")); + setDisguiseEntityExpire(config.getInt("DisguiseEntityExpire")); + setDisguiseCloneExpire(config.getInt("DisguiseCloneExpire")); + setMaxClonedDisguises(config.getInt("DisguiseCloneSize")); + } } diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 95ea0688..9994516b 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -28,7 +28,6 @@ import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.DisguiseValues; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.entity.Ageable; import org.bukkit.entity.Damageable; import org.bukkit.entity.Entity; @@ -89,37 +88,8 @@ public class LibsDisguises extends JavaPlugin { PacketsManager.init(this); DisguiseUtilities.init(this); - DisguiseConfig.setSoundsEnabled(getConfig().getBoolean("DisguiseSounds")); - DisguiseConfig.setVelocitySent(getConfig().getBoolean("SendVelocity")); - DisguiseConfig.setViewDisguises(getConfig().getBoolean("ViewSelfDisguises")); - DisguiseConfig.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise")); - DisguiseConfig.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor")); - DisguiseConfig.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem")); - DisguiseConfig.setAddEntityAnimations(getConfig().getBoolean("AddEntityAnimations")); - DisguiseConfig.setNameOfPlayerShownAboveDisguise(getConfig().getBoolean("ShowNamesAboveDisguises")); - DisguiseConfig.setNameAboveHeadAlwaysVisible(getConfig().getBoolean("NameAboveHeadAlwaysVisible")); - DisguiseConfig.setModifyBoundingBox(getConfig().getBoolean("ModifyBoundingBox")); - DisguiseConfig.setMonstersIgnoreDisguises(getConfig().getBoolean("MonstersIgnoreDisguises")); - DisguiseConfig.setDisguiseBlownOnAttack(getConfig().getBoolean("BlowDisguises")); - DisguiseConfig.setDisguiseBlownMessage(ChatColor.translateAlternateColorCodes('&', - getConfig().getString("BlownDisguiseMessage"))); - DisguiseConfig.setKeepDisguiseOnPlayerDeath(getConfig().getBoolean("KeepDisguises.PlayerDeath")); - DisguiseConfig.setKeepDisguiseOnPlayerLogout(getConfig().getBoolean("KeepDisguises.PlayerLogout")); - DisguiseConfig.setKeepDisguiseOnEntityDespawn(getConfig().getBoolean("KeepDisguises.EntityDespawn")); - DisguiseConfig.setMiscDisguisesForLivingEnabled(getConfig().getBoolean("MiscDisguisesForLiving")); - DisguiseConfig.setMovementPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Movement")); - DisguiseConfig.setWitherSkullPacketsEnabled(getConfig().getBoolean("PacketsEnabled.WitherSkull")); - DisguiseConfig.setEnquipmentPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Enquipment")); - DisguiseConfig.setAnimationPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Animation")); - DisguiseConfig.setBedPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Bed")); - DisguiseConfig.setRidingPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Riding")); - DisguiseConfig.setEntityStatusPacketsEnabled(getConfig().getBoolean("PacketsEnabled.EntityStatus")); - DisguiseConfig.setCollectPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Collect")); - DisguiseConfig.setMetadataPacketsEnabled(getConfig().getBoolean("PacketsEnabled.Metadata")); - DisguiseConfig.setMaxHealthDeterminedByDisguisedEntity(getConfig().getBoolean("MaxHealthDeterminedByEntity")); - DisguiseConfig.setDisguiseEntityExpire(getConfig().getInt("DisguiseEntityExpire")); - DisguiseConfig.setDisguiseCloneExpire(getConfig().getInt("DisguiseCloneExpire")); - DisguiseConfig.setMaxClonedDisguises(getConfig().getInt("DisguiseCloneSize")); + DisguiseConfig.initConfig(getConfig()); + try { // Here I use reflection to set the plugin for Disguise.. // Kind of stupid but I don't want open API calls for a commonly used object.