From c91255c474d14e68da225a797b4dc61e3e804cea Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 18 Feb 2019 15:35:46 -0800 Subject: [PATCH] converting mainconfig pt 3 --- .../java/com/gmail/nossr50/config/Config.java | 7 ++ .../gmail/nossr50/config/ConfigManager.java | 13 +--- .../com/gmail/nossr50/config/MainConfig.java | 77 +++---------------- .../nossr50/config/mods/CustomToolConfig.java | 16 ---- .../config/party/ItemWeightConfig.java | 26 ++++--- .../nossr50/datatypes/player/McMMOPlayer.java | 1 - .../datatypes/skills/PrimarySkillType.java | 4 +- .../nossr50/skills/excavation/Excavation.java | 1 - .../skills/herbalism/HerbalismManager.java | 1 - .../gmail/nossr50/skills/mining/Mining.java | 1 - .../woodcutting/WoodcuttingManager.java | 2 - .../com/gmail/nossr50/util/MaterialUtils.java | 1 - 12 files changed, 38 insertions(+), 112 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 1a44181a4..03cac8f11 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -2,15 +2,18 @@ package com.gmail.nossr50.config; import com.gmail.nossr50.mcMMO; import com.google.common.io.Files; +import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.commented.CommentedConfigurationNode; import ninja.leaping.configurate.loader.ConfigurationLoader; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; import ninja.leaping.configurate.yaml.YAMLConfigurationLoader; import org.yaml.snakeyaml.DumperOptions; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.List; /** * Handles loading and cacheing configuration settings from a configurable compatible config file @@ -370,4 +373,8 @@ public abstract class Config implements VersionedConfig, Unload { public boolean hasNode(String... path) { return (userRootNode.getNode(path) != null); } + + public List getStringValueList(String... path) throws ObjectMappingException { + return userRootNode.getList(TypeToken.of(String.class)); + } } diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index fe1f880dc..d4d280a5b 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -80,32 +80,23 @@ public final class ConfigManager { //TODO: Not sure about the order of MainConfig mainConfig = new MainConfig(); - unloadables.add(mainConfig); treasureConfig = new TreasureConfig(); - unloadables.add(treasureConfig); advancedConfig = new AdvancedConfig(); - unloadables.add(advancedConfig); //TODO: Not sure about the order of experience config experienceConfig = new ExperienceConfig(); - unloadables.add(experienceConfig); potionConfig = new PotionConfig(); - unloadables.add(potionConfig); coreSkillsConfig = new CoreSkillsConfig(); - unloadables.add(coreSkillsConfig); soundConfig = new SoundConfig(); - unloadables.add(soundConfig); rankConfig = new RankConfig(); - unloadables.add(rankConfig); itemWeightConfig = new ItemWeightConfig(); - unloadables.add(itemWeightConfig); /*if (MainConfig.getInstance().getToolModsEnabled()) { new ToolConfigManager(); @@ -244,4 +235,8 @@ public final class ConfigManager { public ExperienceConfig getExperienceConfig() { return experienceConfig; } + + public ItemWeightConfig getItemWeightConfig() { + return itemWeightConfig; + } } diff --git a/src/main/java/com/gmail/nossr50/config/MainConfig.java b/src/main/java/com/gmail/nossr50/config/MainConfig.java index 05f3f6acd..3ec08c328 100644 --- a/src/main/java/com/gmail/nossr50/config/MainConfig.java +++ b/src/main/java/com/gmail/nossr50/config/MainConfig.java @@ -9,12 +9,10 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; import org.bukkit.Material; import org.bukkit.block.data.BlockData; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.EntityType; import java.util.ArrayList; import java.util.List; -import java.util.Set; public class MainConfig extends ConfigValidated { @@ -248,7 +246,7 @@ public class MainConfig extends ConfigValidated { /* MySQL Settings */ for (SQLDatabaseManager.PoolIdentifier identifier : SQLDatabaseManager.PoolIdentifier.values()) { if (getMySQLMaxConnections(identifier) <= 0) { - reason.add(MY_SQL + "." + DATABASE + "." + MAX_CONNECTIONS + "." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 0!"); + reason.add(MY_SQL + "." + DATABASE, MAX_CONNECTIONS + "." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 0!"); } if (getMySQLMaxPoolSize(identifier) <= 0) { reason.add(MY_SQL + "." + DATABASE + "." + MAX_POOL_SIZE + "." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 0!"); @@ -474,22 +472,6 @@ public class MainConfig extends ConfigValidated { return getIntValue(GENERAL, SAVE_INTERVAL); } - public boolean getStatsTrackingEnabled() { - return getBooleanValue(GENERAL, STATS_TRACKING); - } - - public boolean getUpdateCheckEnabled() { - return getBooleanValue(GENERAL, UPDATE_CHECK); - } - - public boolean getPreferBeta() { - return getBooleanValue(GENERAL, PREFER_BETA); - } - - public boolean getVerboseLoggingEnabled() { - return getBooleanValue(GENERAL, VERBOSE_LOGGING); - } - public String getPartyChatPrefix() { return getStringValue(COMMANDS, PARTYCHAT, CHAT_PREFIX_FORMAT); } @@ -738,18 +720,10 @@ public class MainConfig extends ConfigValidated { return getBooleanValue(HARDCORE, DEATH_STAT_LOSS, ENABLED, StringUtils.getCapitalized(primarySkillType.toString())); } - /*public void setHardcoreStatLossEnabled(PrimarySkillType primarySkillType, boolean enabled) { - config.set(HARDCORE, DEATH_STAT_LOSS, ENABLED, StringUtils.getCapitalized(primarySkillType.toString()), enabled); - }*/ - public double getHardcoreDeathStatPenaltyPercentage() { return getDoubleValue(HARDCORE, DEATH_STAT_LOSS, PENALTY_PERCENTAGE); } - /*public void setHardcoreDeathStatPenaltyPercentage(double value) { - config.set(HARDCORE, DEATH_STAT_LOSS, PENALTY_PERCENTAGE, value); - }*/ - public int getHardcoreDeathStatPenaltyLevelThreshold() { return getIntValue(HARDCORE, DEATH_STAT_LOSS, LEVEL_THRESHOLD); } @@ -758,18 +732,10 @@ public class MainConfig extends ConfigValidated { return getBooleanValue(HARDCORE, VAMPIRISM, ENABLED, StringUtils.getCapitalized(primarySkillType.toString())); } - /*public void setHardcoreVampirismEnabled(PrimarySkillType primarySkillType, boolean enabled) { - config.set(HARDCORE, VAMPIRISM, ENABLED, StringUtils.getCapitalized(primarySkillType.toString()), enabled); - }*/ - public double getHardcoreVampirismStatLeechPercentage() { return getDoubleValue(HARDCORE, VAMPIRISM, LEECH_PERCENTAGE); } - /*public void setHardcoreVampirismStatLeechPercentage(double value) { - config.set(HARDCORE, VAMPIRISM, LEECH_PERCENTAGE, value); - }*/ - public int getHardcoreVampirismLevelThreshold() { return getIntValue(HARDCORE, VAMPIRISM, LEVEL_THRESHOLD); } @@ -955,69 +921,46 @@ public class MainConfig extends ConfigValidated { } public boolean getAbilityMessagesEnabled() { - return getBooleanValue(ABILITIES + "." + MESSAGES); + return getBooleanValue(ABILITIES, MESSAGES); } public boolean getAbilitiesEnabled() { - return getBooleanValue(ABILITIES + "." + ENABLED); + return getBooleanValue(ABILITIES, ENABLED); } public boolean getAbilitiesOnlyActivateWhenSneaking() { - return getBooleanValue(ABILITIES + "." + ACTIVATION + "." + ONLY_ACTIVATE_WHEN_SNEAKING); + return getBooleanValue(ABILITIES, ACTIVATION, ONLY_ACTIVATE_WHEN_SNEAKING); } public boolean getAbilitiesGateEnabled() { - return getBooleanValue(ABILITIES + "." + ACTIVATION + "." + LEVEL_GATE_ABILITIES); + return getBooleanValue(ABILITIES, ACTIVATION, LEVEL_GATE_ABILITIES); } public int getCooldown(SuperAbilityType ability) { - return getIntValue(ABILITIES + "." + COOLDOWNS + ability.toString()); + return getIntValue(ABILITIES, COOLDOWNS + ability.toString()); } public int getMaxLength(SuperAbilityType ability) { - return getIntValue(ABILITIES + "." + MAX_SECONDS + "." + ability.toString()); + return getIntValue(ABILITIES, MAX_SECONDS, ability.toString()); } /* Durability Settings */ public int getAbilityToolDamage() { - return getIntValue(ABILITIES + "." + TOOLS + "." + DURABILITY_LOSS); + return getIntValue(ABILITIES, TOOLS, DURABILITY_LOSS); } /* Thresholds */ public int getTreeFellerThreshold() { - return getIntValue(ABILITIES + "." + LIMITS + "." + TREE_FELLER_THRESHOLD); + return getIntValue(ABILITIES, LIMITS, TREE_FELLER_THRESHOLD); } /* * SKILL SETTINGS */ public boolean getDoubleDropsEnabled(PrimarySkillType skill, Material material) { - return getBooleanValue(DOUBLE_DROPS + "." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getPrettyItemString(material).replace(" ", "_")); + return getBooleanValue(DOUBLE_DROPS, StringUtils.getCapitalized(skill.toString()), StringUtils.getPrettyItemString(material).replace(" ", "_")); } - public boolean getDoubleDropsDisabled(PrimarySkillType skill) { - String skillName = StringUtils.getCapitalized(skill.toString()); - ConfigurationSection section = config.getConfigurationSection(DOUBLE_DROPS + "." + skillName); - if (section == null) - return false; - Set keys = section.getKeys(false); - boolean disabled = true; - - for (String key : keys) { - if (getBooleanValue(DOUBLE_DROPS + "." + skillName + "." + key)) { - disabled = false; - break; - } - } - - return disabled; - } - - /* Axes */ - /*public int getAxesGate() { - return getIntValue(SKILLS + "." + AXES + "." + ABILITY_ACTIVATION + "_Level_Gate", 10); - }*/ - /* Acrobatics */ public boolean getDodgeLightningDisabled() { return getBooleanValue(SKILLS, ACROBATICS, PREVENT + DODGE + LIGHTNING); diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomToolConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomToolConfig.java index 941d573a6..8c09fb21d 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomToolConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomToolConfig.java @@ -1,21 +1,5 @@ package com.gmail.nossr50.config.mods; -import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.datatypes.mods.CustomTool; -import com.gmail.nossr50.datatypes.skills.ItemType; -import com.gmail.nossr50.datatypes.skills.MaterialType; -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.skills.repair.repairables.Repairable; -import com.gmail.nossr50.skills.repair.repairables.RepairableFactory; -import com.gmail.nossr50.util.skills.SkillUtils; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; /* public class CustomToolConfig extends Config { //TODO: Disabled until modded servers come back diff --git a/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java b/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java index 284486233..6ec03aeec 100644 --- a/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java +++ b/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java @@ -1,9 +1,9 @@ package com.gmail.nossr50.config.party; import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; import org.bukkit.Material; import java.util.HashSet; @@ -13,7 +13,6 @@ public class ItemWeightConfig extends Config { public static final String DEFAULT = "Default"; public static final String PARTY_SHAREABLES = "Party_Shareables"; public static final String MISC_ITEMS = "Misc_Items"; - private static ItemWeightConfig instance; public ItemWeightConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "itemweights.yml"); @@ -29,7 +28,12 @@ public class ItemWeightConfig extends Config { */ @Deprecated public static ItemWeightConfig getInstance() { - return mcMMO.getConfigManager().getIte(); + return mcMMO.getConfigManager().getItemWeightConfig(); + } + + @Override + public void unload() { + //do nothing } /** @@ -61,17 +65,17 @@ public class ItemWeightConfig extends Config { public HashSet getMiscItems() { HashSet miscItems = new HashSet(); - for (String item : getStringValueList(PARTY_SHAREABLES, MISC_ITEMS)) { - Material material = Material.getMaterial(item.toUpperCase()); + try { + for (String item : getStringValueList(PARTY_SHAREABLES, MISC_ITEMS)) { + Material material = Material.getMaterial(item.toUpperCase()); - if (material != null) { - miscItems.add(material); + if (material != null) { + miscItems.add(material); + } } + } catch (ObjectMappingException e) { + e.printStackTrace(); } return miscItems; } - - @Override - protected void loadKeys() { - } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 8f648da02..896439398 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -8,7 +8,6 @@ import com.gmail.nossr50.datatypes.chat.ChatMode; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.interactions.NotificationType; -import com.gmail.nossr50.datatypes.mods.CustomTool; import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.PartyTeleportRecord; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/PrimarySkillType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/PrimarySkillType.java index b05e91fcd..b82955b7f 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/PrimarySkillType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/PrimarySkillType.java @@ -150,9 +150,9 @@ public enum PrimarySkillType { return MainConfig.getInstance().getPVEEnabled(this); } - public boolean getDoubleDropsDisabled() { + /*public boolean getDoubleDropsDisabled() { return MainConfig.getInstance().getDoubleDropsDisabled(this); - } + }*/ public boolean getHardcoreStatLossEnabled() { return MainConfig.getInstance().getHardcoreStatLossEnabled(this); diff --git a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java index a64ba4701..16193b1f7 100644 --- a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java @@ -4,7 +4,6 @@ import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.treasure.TreasureConfig; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; import org.bukkit.block.BlockState; diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index f6dc0dc9b..7bd6351a5 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -5,7 +5,6 @@ import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.treasure.TreasureConfig; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.interactions.NotificationType; -import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index e4dd5f788..a6e9ac5a5 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.mining; import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.Misc; import org.bukkit.Material; import org.bukkit.block.BlockState; diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java index 3ec34f827..a7518e090 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java @@ -2,12 +2,10 @@ package com.gmail.nossr50.skills.woodcutting; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.interactions.NotificationType; -import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; -import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod; import com.gmail.nossr50.util.*; diff --git a/src/main/java/com/gmail/nossr50/util/MaterialUtils.java b/src/main/java/com/gmail/nossr50/util/MaterialUtils.java index 483d600d3..8c6983ba2 100644 --- a/src/main/java/com/gmail/nossr50/util/MaterialUtils.java +++ b/src/main/java/com/gmail/nossr50/util/MaterialUtils.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.util; -import com.gmail.nossr50.mcMMO; import org.bukkit.Material; public final class MaterialUtils {