From c61c55031dfef74a065a4cf5d0e8d05edac7ac3c Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 13 May 2019 08:36:37 -0700 Subject: [PATCH] Core skill config is now converted --- .../java/com/gmail/nossr50/config/Config.java | 21 ++++-- .../gmail/nossr50/config/ConfigManager.java | 8 ++- .../nossr50/config/CoreSkillsConfig.java | 66 ------------------- .../java/com/gmail/nossr50/config/Unload.java | 8 --- .../skills/coreskills/ConfigCoreSkills.java | 24 +++++++ .../ConfigCoreSkillsAcrobatics.java | 25 +++++++ .../skills/subskills/AbstractSubSkill.java | 13 ---- .../skills/subskills/interfaces/SubSkill.java | 7 -- src/main/java/com/gmail/nossr50/mcMMO.java | 11 ++-- 9 files changed, 74 insertions(+), 109 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java delete mode 100644 src/main/java/com/gmail/nossr50/config/Unload.java create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/skills/coreskills/ConfigCoreSkills.java create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/skills/coreskills/ConfigCoreSkillsAcrobatics.java diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 9226d1437..fcc474e65 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -95,9 +95,18 @@ public abstract class Config implements VersionedConfig { } //Cleanup and backup registers +// registerUnload(); registerFileBackup(); } +// /** +// * Registers with the config managers unloader +// * The unloader runs when the plugin gets disabled which cleans up registries to make reloading safe +// */ +// private void registerUnload() { +// mcMMO.getConfigManager().registerUnloadable(this); +// } + /** * Registers with the config managers file list * Used for backing up configs with our zip library @@ -276,9 +285,9 @@ public abstract class Config implements VersionedConfig { * * @return the path to the defaults directory */ -// private String getDefaultConfigCopyRelativePath() { -// return getDefaultConfigFile().getPath(); -// } + private String getDefaultConfigCopyRelativePath() { + return getDefaultConfigFile().getPath(); + } /** * Grabs the File representation of the default config, which is stored on disk in a defaults folder @@ -286,9 +295,9 @@ public abstract class Config implements VersionedConfig { * * @return the copy of the default config file, stored in the defaults directory */ -// private File getDefaultConfigFile() { -// return new File(ConfigConstants.getDefaultsFolder(), FILE_RELATIVE_PATH); -// } + private File getDefaultConfigFile() { + return new File(ConfigConstants.getDefaultsFolder(), FILE_RELATIVE_PATH); + } /** * Creates the defaults directory diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 78ab6634a..cafef6ee9 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -24,6 +24,7 @@ import com.gmail.nossr50.config.hocon.skills.acrobatics.ConfigAcrobatics; import com.gmail.nossr50.config.hocon.skills.alchemy.ConfigAlchemy; import com.gmail.nossr50.config.hocon.skills.archery.ConfigArchery; import com.gmail.nossr50.config.hocon.skills.axes.ConfigAxes; +import com.gmail.nossr50.config.hocon.skills.coreskills.ConfigCoreSkills; import com.gmail.nossr50.config.hocon.skills.exampleconfigs.ConfigNameRegisterDefaults; import com.gmail.nossr50.config.hocon.skills.exampleconfigs.MinecraftMaterialWrapper; import com.gmail.nossr50.config.hocon.skills.excavation.ConfigExcavation; @@ -93,6 +94,7 @@ public final class ConfigManager { private SerializedConfigLoader configAdmin; private SerializedConfigLoader configMobs; private SerializedConfigLoader configExperience; + private SerializedConfigLoader configCoreSkills; private SerializedConfigLoader configDefaultExamples; private ConfigAcrobatics configAcrobatics; @@ -123,7 +125,6 @@ public final class ConfigManager { private ExcavationTreasureConfig excavationTreasureConfig; private HerbalismTreasureConfig herbalismTreasureConfig; private AdvancedConfig advancedConfig; - private CoreSkillsConfig coreSkillsConfig; private SoundConfig soundConfig; private RankConfig rankConfig; @@ -177,6 +178,7 @@ public final class ConfigManager { configAdmin = new SerializedConfigLoader<>(ConfigAdmin.class, "admin.conf", "Admin", null); configMobs = new SerializedConfigLoader<>(ConfigMobs.class, "creatures.conf", "Creatures", null); configExperience = new SerializedConfigLoader<>(ConfigExperience.class, "experience.conf", "Experience", null); + configCoreSkills = new SerializedConfigLoader<>(ConfigCoreSkills.class, "core_skills.conf", "Core-Skills", null); configDefaultExamples = new SerializedConfigLoader<>(ConfigNameRegisterDefaults.class, "minecraft_item_block_name_examples.conf", "Minecraft", null); initSerializedSkillConfigs(); @@ -326,8 +328,8 @@ public final class ConfigManager { return advancedConfig; } - public CoreSkillsConfig getCoreSkillsConfig() { - return coreSkillsConfig; + public ConfigCoreSkills getConfigCoreSkills() { + return configCoreSkills.getConfig(); } public SoundConfig getSoundConfig() { diff --git a/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java b/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java deleted file mode 100644 index 7715494cf..000000000 --- a/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.gmail.nossr50.config; - -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill; -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.util.StringUtils; -import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; - -@ConfigSerializable -public class CoreSkillsConfig extends Config { - public static final String ENABLED = "Enabled"; - //private static CoreSkillsConfig instance; - - public CoreSkillsConfig() { - //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml", true); - super("coreskills", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, true, true, true); - } - - /** - * This grabs an instance of the class from the Config Manager - * This method is deprecated and will be removed in the future - * - * @return the instance of this config - * @see mcMMO#getConfigManager() - * @deprecated Please use mcMMO.getConfigManager() to grab a specific config instead - */ - @Deprecated - public static CoreSkillsConfig getInstance() { - return mcMMO.getConfigManager().getCoreSkillsConfig(); - } - - /** - * The version of this config - * - * @return - */ - @Override - public double getConfigVersion() { - return 1; - } - - /* - * Skill Settings - */ - - /** - * Whether or not a skill is enabled - * Defaults true - * - * @param abstractSubSkill SubSkill definition to check - * @return true if subskill is enabled - */ - public boolean isSkillEnabled(AbstractSubSkill abstractSubSkill) { - return getBooleanValue(StringUtils.getCapitalized(abstractSubSkill.getPrimarySkill().toString()), abstractSubSkill.getConfigKeyName(), ENABLED); - } - - /** - * Whether or not this primary skill is enabled - * - * @param primarySkillType target primary skill - * @return true if enabled - */ - public boolean isPrimarySkillEnabled(PrimarySkillType primarySkillType) { - return getBooleanValue(StringUtils.getCapitalized(primarySkillType.toString()), ENABLED); - } -} diff --git a/src/main/java/com/gmail/nossr50/config/Unload.java b/src/main/java/com/gmail/nossr50/config/Unload.java deleted file mode 100644 index 8e672661f..000000000 --- a/src/main/java/com/gmail/nossr50/config/Unload.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.gmail.nossr50.config; - -/** - * Unloads values, sort of like a constructor - */ -public interface Unload { - void unload(); -} diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/coreskills/ConfigCoreSkills.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/coreskills/ConfigCoreSkills.java new file mode 100644 index 000000000..e5c09f6a7 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/coreskills/ConfigCoreSkills.java @@ -0,0 +1,24 @@ +package com.gmail.nossr50.config.hocon.skills.coreskills; + +import ninja.leaping.configurate.objectmapping.Setting; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +@ConfigSerializable +public class ConfigCoreSkills { + + @Setting(value = "Core Skills for Acrobatics" + + "\nCore skills are ones built into mcMMO") + private ConfigCoreSkillsAcrobatics configCoreSkillsAcrobatics = new ConfigCoreSkillsAcrobatics(); + + public boolean isRollEnabled() { + return configCoreSkillsAcrobatics.isRollEnabled(); + } + + public ConfigCoreSkillsAcrobatics getConfigCoreSkillsAcrobatics() { + return configCoreSkillsAcrobatics; + } + + public boolean isAcrobaticsEnabled() { + return getConfigCoreSkillsAcrobatics().isAcrobaticsEnabled(); + } +} diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/coreskills/ConfigCoreSkillsAcrobatics.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/coreskills/ConfigCoreSkillsAcrobatics.java new file mode 100644 index 000000000..378cd7d93 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/coreskills/ConfigCoreSkillsAcrobatics.java @@ -0,0 +1,25 @@ +package com.gmail.nossr50.config.hocon.skills.coreskills; + +import ninja.leaping.configurate.objectmapping.Setting; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +@ConfigSerializable +public class ConfigCoreSkillsAcrobatics { + + private static final boolean ROLL_DEFAULT = true; + public static final boolean ACROBATICS_MASTER_DEFAULT = true; + + @Setting(value = "Disable", comment = "Enable the primary skill Acrobatics") + private boolean enableAcrobatics = ACROBATICS_MASTER_DEFAULT; + + @Setting(value = "Roll", comment = "Enable or disable the Roll skill.") + private boolean enableRoll = ROLL_DEFAULT; + + public boolean isRollEnabled() { + return enableRoll; + } + + public boolean isAcrobaticsEnabled() { + return enableAcrobatics; + } +} diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java index 2f295fbfa..ddea1c65d 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.datatypes.skills.subskills; -import com.gmail.nossr50.config.CoreSkillsConfig; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.subskills.interfaces.Interaction; import com.gmail.nossr50.datatypes.skills.subskills.interfaces.Rank; @@ -33,18 +32,6 @@ public abstract class AbstractSubSkill implements SubSkill, Interaction, Rank, S return LocaleLoader.getString(getPrimaryKeyName() + ".SubSkill." + getConfigKeyName() + ".Description"); } - /** - * Whether or not this subskill is enabled - * - * @return true if enabled - */ - @Override - @Deprecated - public boolean isEnabled() { - //TODO: This might be troublesome... - return CoreSkillsConfig.getInstance().isSkillEnabled(this); - } - /** * Prints detailed info about this subskill to the player * diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/interfaces/SubSkill.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/interfaces/SubSkill.java index 952ca20e6..7aa166e0a 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/interfaces/SubSkill.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/interfaces/SubSkill.java @@ -72,13 +72,6 @@ public interface SubSkill extends Skill { */ void addStats(ComponentBuilder componentBuilder, Player player); - /** - * Whether or not this subskill is enabled - * - * @return true if enabled - */ - boolean isEnabled(); - /** * Prints detailed info about this subskill to the player * diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index d6e4ca1a9..eb48d08c4 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -1,7 +1,6 @@ package com.gmail.nossr50; import com.gmail.nossr50.config.ConfigManager; -import com.gmail.nossr50.config.CoreSkillsConfig; import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.config.hocon.database.ConfigSectionCleaning; import com.gmail.nossr50.config.hocon.database.ConfigSectionMySQL; @@ -14,7 +13,6 @@ import com.gmail.nossr50.core.MaterialMapStore; import com.gmail.nossr50.core.MetadataConstants; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManagerFactory; -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.subskills.acrobatics.Roll; import com.gmail.nossr50.listeners.*; import com.gmail.nossr50.party.PartyManager; @@ -508,13 +506,14 @@ public class mcMMO extends JavaPlugin { * Acrobatics skills */ - if (CoreSkillsConfig.getInstance().isPrimarySkillEnabled(PrimarySkillType.ACROBATICS)) { + if (mcMMO.getConfigManager().getConfigCoreSkills().isAcrobaticsEnabled()) { System.out.println("[mcMMO]" + " enabling Acrobatics Skills"); //TODO: Should do this differently - Roll roll = new Roll(); - CoreSkillsConfig.getInstance().isSkillEnabled(roll); - InteractionManager.registerSubSkill(new Roll()); + if(mcMMO.getConfigManager().getConfigCoreSkills().isRollEnabled()) + { + InteractionManager.registerSubSkill(new Roll()); + } } }