converting mainconfig pt 3

This commit is contained in:
nossr50 2019-02-18 15:35:46 -08:00
parent 4bb513c2d1
commit c91255c474
12 changed files with 38 additions and 112 deletions

View File

@ -2,15 +2,18 @@ package com.gmail.nossr50.config;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.commented.CommentedConfigurationNode; import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader; import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader; import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List;
/** /**
* Handles loading and cacheing configuration settings from a configurable compatible config file * 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) { public boolean hasNode(String... path) {
return (userRootNode.getNode(path) != null); return (userRootNode.getNode(path) != null);
} }
public List<String> getStringValueList(String... path) throws ObjectMappingException {
return userRootNode.getList(TypeToken.of(String.class));
}
} }

View File

@ -80,32 +80,23 @@ public final class ConfigManager {
//TODO: Not sure about the order of MainConfig //TODO: Not sure about the order of MainConfig
mainConfig = new MainConfig(); mainConfig = new MainConfig();
unloadables.add(mainConfig);
treasureConfig = new TreasureConfig(); treasureConfig = new TreasureConfig();
unloadables.add(treasureConfig);
advancedConfig = new AdvancedConfig(); advancedConfig = new AdvancedConfig();
unloadables.add(advancedConfig);
//TODO: Not sure about the order of experience config //TODO: Not sure about the order of experience config
experienceConfig = new ExperienceConfig(); experienceConfig = new ExperienceConfig();
unloadables.add(experienceConfig);
potionConfig = new PotionConfig(); potionConfig = new PotionConfig();
unloadables.add(potionConfig);
coreSkillsConfig = new CoreSkillsConfig(); coreSkillsConfig = new CoreSkillsConfig();
unloadables.add(coreSkillsConfig);
soundConfig = new SoundConfig(); soundConfig = new SoundConfig();
unloadables.add(soundConfig);
rankConfig = new RankConfig(); rankConfig = new RankConfig();
unloadables.add(rankConfig);
itemWeightConfig = new ItemWeightConfig(); itemWeightConfig = new ItemWeightConfig();
unloadables.add(itemWeightConfig);
/*if (MainConfig.getInstance().getToolModsEnabled()) { /*if (MainConfig.getInstance().getToolModsEnabled()) {
new ToolConfigManager(); new ToolConfigManager();
@ -244,4 +235,8 @@ public final class ConfigManager {
public ExperienceConfig getExperienceConfig() { public ExperienceConfig getExperienceConfig() {
return experienceConfig; return experienceConfig;
} }
public ItemWeightConfig getItemWeightConfig() {
return itemWeightConfig;
}
} }

View File

@ -9,12 +9,10 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
public class MainConfig extends ConfigValidated { public class MainConfig extends ConfigValidated {
@ -248,7 +246,7 @@ public class MainConfig extends ConfigValidated {
/* MySQL Settings */ /* MySQL Settings */
for (SQLDatabaseManager.PoolIdentifier identifier : SQLDatabaseManager.PoolIdentifier.values()) { for (SQLDatabaseManager.PoolIdentifier identifier : SQLDatabaseManager.PoolIdentifier.values()) {
if (getMySQLMaxConnections(identifier) <= 0) { 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) { if (getMySQLMaxPoolSize(identifier) <= 0) {
reason.add(MY_SQL + "." + DATABASE + "." + MAX_POOL_SIZE + "." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 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); 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() { public String getPartyChatPrefix() {
return getStringValue(COMMANDS, PARTYCHAT, CHAT_PREFIX_FORMAT); 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())); 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() { public double getHardcoreDeathStatPenaltyPercentage() {
return getDoubleValue(HARDCORE, DEATH_STAT_LOSS, PENALTY_PERCENTAGE); 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() { public int getHardcoreDeathStatPenaltyLevelThreshold() {
return getIntValue(HARDCORE, DEATH_STAT_LOSS, LEVEL_THRESHOLD); 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())); 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() { public double getHardcoreVampirismStatLeechPercentage() {
return getDoubleValue(HARDCORE, VAMPIRISM, LEECH_PERCENTAGE); return getDoubleValue(HARDCORE, VAMPIRISM, LEECH_PERCENTAGE);
} }
/*public void setHardcoreVampirismStatLeechPercentage(double value) {
config.set(HARDCORE, VAMPIRISM, LEECH_PERCENTAGE, value);
}*/
public int getHardcoreVampirismLevelThreshold() { public int getHardcoreVampirismLevelThreshold() {
return getIntValue(HARDCORE, VAMPIRISM, LEVEL_THRESHOLD); return getIntValue(HARDCORE, VAMPIRISM, LEVEL_THRESHOLD);
} }
@ -955,69 +921,46 @@ public class MainConfig extends ConfigValidated {
} }
public boolean getAbilityMessagesEnabled() { public boolean getAbilityMessagesEnabled() {
return getBooleanValue(ABILITIES + "." + MESSAGES); return getBooleanValue(ABILITIES, MESSAGES);
} }
public boolean getAbilitiesEnabled() { public boolean getAbilitiesEnabled() {
return getBooleanValue(ABILITIES + "." + ENABLED); return getBooleanValue(ABILITIES, ENABLED);
} }
public boolean getAbilitiesOnlyActivateWhenSneaking() { public boolean getAbilitiesOnlyActivateWhenSneaking() {
return getBooleanValue(ABILITIES + "." + ACTIVATION + "." + ONLY_ACTIVATE_WHEN_SNEAKING); return getBooleanValue(ABILITIES, ACTIVATION, ONLY_ACTIVATE_WHEN_SNEAKING);
} }
public boolean getAbilitiesGateEnabled() { public boolean getAbilitiesGateEnabled() {
return getBooleanValue(ABILITIES + "." + ACTIVATION + "." + LEVEL_GATE_ABILITIES); return getBooleanValue(ABILITIES, ACTIVATION, LEVEL_GATE_ABILITIES);
} }
public int getCooldown(SuperAbilityType ability) { public int getCooldown(SuperAbilityType ability) {
return getIntValue(ABILITIES + "." + COOLDOWNS + ability.toString()); return getIntValue(ABILITIES, COOLDOWNS + ability.toString());
} }
public int getMaxLength(SuperAbilityType ability) { public int getMaxLength(SuperAbilityType ability) {
return getIntValue(ABILITIES + "." + MAX_SECONDS + "." + ability.toString()); return getIntValue(ABILITIES, MAX_SECONDS, ability.toString());
} }
/* Durability Settings */ /* Durability Settings */
public int getAbilityToolDamage() { public int getAbilityToolDamage() {
return getIntValue(ABILITIES + "." + TOOLS + "." + DURABILITY_LOSS); return getIntValue(ABILITIES, TOOLS, DURABILITY_LOSS);
} }
/* Thresholds */ /* Thresholds */
public int getTreeFellerThreshold() { public int getTreeFellerThreshold() {
return getIntValue(ABILITIES + "." + LIMITS + "." + TREE_FELLER_THRESHOLD); return getIntValue(ABILITIES, LIMITS, TREE_FELLER_THRESHOLD);
} }
/* /*
* SKILL SETTINGS * SKILL SETTINGS
*/ */
public boolean getDoubleDropsEnabled(PrimarySkillType skill, Material material) { 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<String> 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 */ /* Acrobatics */
public boolean getDodgeLightningDisabled() { public boolean getDodgeLightningDisabled() {
return getBooleanValue(SKILLS, ACROBATICS, PREVENT + DODGE + LIGHTNING); return getBooleanValue(SKILLS, ACROBATICS, PREVENT + DODGE + LIGHTNING);

View File

@ -1,21 +1,5 @@
package com.gmail.nossr50.config.mods; 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 { public class CustomToolConfig extends Config {
//TODO: Disabled until modded servers come back //TODO: Disabled until modded servers come back

View File

@ -1,9 +1,9 @@
package com.gmail.nossr50.config.party; package com.gmail.nossr50.config.party;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.HashSet; import java.util.HashSet;
@ -13,7 +13,6 @@ public class ItemWeightConfig extends Config {
public static final String DEFAULT = "Default"; public static final String DEFAULT = "Default";
public static final String PARTY_SHAREABLES = "Party_Shareables"; public static final String PARTY_SHAREABLES = "Party_Shareables";
public static final String MISC_ITEMS = "Misc_Items"; public static final String MISC_ITEMS = "Misc_Items";
private static ItemWeightConfig instance;
public ItemWeightConfig() { public ItemWeightConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "itemweights.yml"); //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "itemweights.yml");
@ -29,7 +28,12 @@ public class ItemWeightConfig extends Config {
*/ */
@Deprecated @Deprecated
public static ItemWeightConfig getInstance() { public static ItemWeightConfig getInstance() {
return mcMMO.getConfigManager().getIte(); return mcMMO.getConfigManager().getItemWeightConfig();
}
@Override
public void unload() {
//do nothing
} }
/** /**
@ -61,6 +65,7 @@ public class ItemWeightConfig extends Config {
public HashSet<Material> getMiscItems() { public HashSet<Material> getMiscItems() {
HashSet<Material> miscItems = new HashSet<Material>(); HashSet<Material> miscItems = new HashSet<Material>();
try {
for (String item : getStringValueList(PARTY_SHAREABLES, MISC_ITEMS)) { for (String item : getStringValueList(PARTY_SHAREABLES, MISC_ITEMS)) {
Material material = Material.getMaterial(item.toUpperCase()); Material material = Material.getMaterial(item.toUpperCase());
@ -68,10 +73,9 @@ public class ItemWeightConfig extends Config {
miscItems.add(material); miscItems.add(material);
} }
} }
} catch (ObjectMappingException e) {
e.printStackTrace();
}
return miscItems; return miscItems;
} }
@Override
protected void loadKeys() {
}
} }

View File

@ -8,7 +8,6 @@ import com.gmail.nossr50.datatypes.chat.ChatMode;
import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.experience.XPGainSource;
import com.gmail.nossr50.datatypes.interactions.NotificationType; 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.Party;
import com.gmail.nossr50.datatypes.party.PartyTeleportRecord; import com.gmail.nossr50.datatypes.party.PartyTeleportRecord;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;

View File

@ -150,9 +150,9 @@ public enum PrimarySkillType {
return MainConfig.getInstance().getPVEEnabled(this); return MainConfig.getInstance().getPVEEnabled(this);
} }
public boolean getDoubleDropsDisabled() { /*public boolean getDoubleDropsDisabled() {
return MainConfig.getInstance().getDoubleDropsDisabled(this); return MainConfig.getInstance().getDoubleDropsDisabled(this);
} }*/
public boolean getHardcoreStatLossEnabled() { public boolean getHardcoreStatLossEnabled() {
return MainConfig.getInstance().getHardcoreStatLossEnabled(this); return MainConfig.getInstance().getHardcoreStatLossEnabled(this);

View File

@ -4,7 +4,6 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig; import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;

View File

@ -5,7 +5,6 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig; import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.interactions.NotificationType; 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.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType;

View File

@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.mining;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;

View File

@ -2,12 +2,10 @@ package com.gmail.nossr50.skills.woodcutting;
import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.interactions.NotificationType; 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.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod; import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod;
import com.gmail.nossr50.util.*; import com.gmail.nossr50.util.*;

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import com.gmail.nossr50.mcMMO;
import org.bukkit.Material; import org.bukkit.Material;
public final class MaterialUtils { public final class MaterialUtils {