|
@@ -1,1032 +1,302 @@
|
|
|
package com.gmail.nossr50.core.config;
|
|
|
|
|
|
import com.gmail.nossr50.core.McmmoCore;
|
|
|
-import com.gmail.nossr50.core.data.database.SQLDatabaseManager;
|
|
|
-import com.gmail.nossr50.core.datatypes.party.PartyFeature;
|
|
|
-import com.gmail.nossr50.core.skills.MobHealthbarType;
|
|
|
-import com.gmail.nossr50.core.skills.PrimarySkillType;
|
|
|
-import com.gmail.nossr50.core.skills.SuperAbilityType;
|
|
|
-import com.gmail.nossr50.core.util.StringUtils;
|
|
|
+import com.google.common.io.Files;
|
|
|
+import ninja.leaping.configurate.ConfigurationNode;
|
|
|
+import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
|
|
+import ninja.leaping.configurate.loader.ConfigurationLoader;
|
|
|
+import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
|
|
+import org.yaml.snakeyaml.DumperOptions;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
|
|
|
-public class Config extends ConfigurableLoader {
|
|
|
- private static Config instance;
|
|
|
+/**
|
|
|
+ * Handles loading and cacheing configuration settings from a configurable compatible config file
|
|
|
+ */
|
|
|
+//@ConfigSerializable
|
|
|
+public abstract class Config implements VersionedConfig, Unload {
|
|
|
|
|
|
- private Config() {
|
|
|
- super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml");
|
|
|
- validate();
|
|
|
- }
|
|
|
-
|
|
|
- public static Config getInstance() {
|
|
|
- if (instance == null) {
|
|
|
- instance = new Config();
|
|
|
- }
|
|
|
-
|
|
|
- return instance;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void loadKeys() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected boolean validateKeys() {
|
|
|
- // Validate all the settings!
|
|
|
- List<String> reason = new ArrayList<String>();
|
|
|
-
|
|
|
- /* General Settings */
|
|
|
- if (getSaveInterval() <= 0) {
|
|
|
- reason.add("General.Save_Interval should be greater than 0!");
|
|
|
- }
|
|
|
-
|
|
|
- /* MySQL Settings */
|
|
|
- for (SQLDatabaseManager.PoolIdentifier identifier : SQLDatabaseManager.PoolIdentifier.values()) {
|
|
|
- if (getMySQLMaxConnections(identifier) <= 0) {
|
|
|
- reason.add("MySQL.Database.MaxConnections." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 0!");
|
|
|
- }
|
|
|
- if (getMySQLMaxPoolSize(identifier) <= 0) {
|
|
|
- reason.add("MySQL.Database.MaxPoolSize." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 0!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /* Mob Healthbar */
|
|
|
- if (getMobHealthbarTime() == 0) {
|
|
|
- reason.add("Mob_Healthbar.Display_Time cannot be 0! Set to -1 to disable or set a valid value.");
|
|
|
- }
|
|
|
-
|
|
|
- /* Scoreboards */
|
|
|
- /*if (getRankScoreboardTime() != -1 && getRankScoreboardTime() <= 0) {
|
|
|
- reason.add("Scoreboard.Types.Rank.Display_Time should be greater than 0, or -1!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getStatsScoreboardTime() != -1 && getStatsScoreboardTime() <= 0) {
|
|
|
- reason.add("Scoreboard.Types.Stats.Display_Time should be greater than 0, or -1!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getTopScoreboardTime() != -1 && getTopScoreboardTime() <= 0) {
|
|
|
- reason.add("Scoreboard.Types.Top.Display_Time should be greater than 0, or -1!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getInspectScoreboardTime() != -1 && getInspectScoreboardTime() <= 0) {
|
|
|
- reason.add("Scoreboard.Types.Inspect.Display_Time should be greater than 0, or -1!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getSkillScoreboardTime() != -1 && getSkillScoreboardTime() <= 0) {
|
|
|
- reason.add("Scoreboard.Types.Skill.Display_Time should be greater than 0, or -1!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getSkillLevelUpTime() != -1 && getSkillScoreboardTime() <= 0) {
|
|
|
- reason.add("Scoreboard.Types.Skill.Display_Time should be greater than 0, or -1!");
|
|
|
- }
|
|
|
-
|
|
|
- if (!(getRankUseChat() || getRankUseBoard())) {
|
|
|
- reason.add("Either Board or Print in Scoreboard.Types.Rank must be true!");
|
|
|
- }
|
|
|
-
|
|
|
- if (!(getTopUseChat() || getTopUseBoard())) {
|
|
|
- reason.add("Either Board or Print in Scoreboard.Types.Top must be true!");
|
|
|
- }
|
|
|
-
|
|
|
- if (!(getStatsUseChat() || getStatsUseBoard())) {
|
|
|
- reason.add("Either Board or Print in Scoreboard.Types.Stats must be true!");
|
|
|
- }
|
|
|
-
|
|
|
- if (!(getInspectUseChat() || getInspectUseBoard())) {
|
|
|
- reason.add("Either Board or Print in Scoreboard.Types.Inspect must be true!");
|
|
|
- }*/
|
|
|
-
|
|
|
- /* Database Purging */
|
|
|
- if (getPurgeInterval() < -1) {
|
|
|
- reason.add("Database_Purging.Purge_Interval should be greater than, or equal to -1!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getOldUsersCutoff() != -1 && getOldUsersCutoff() <= 0) {
|
|
|
- reason.add("Database_Purging.Old_User_Cutoff should be greater than 0 or -1!");
|
|
|
- }
|
|
|
-
|
|
|
- /* Hardcore Mode */
|
|
|
- if (getHardcoreDeathStatPenaltyPercentage() < 0.01 || getHardcoreDeathStatPenaltyPercentage() > 100) {
|
|
|
- reason.add("Hardcore.Death_Stat_Loss.Penalty_Percentage only accepts values from 0.01 to 100!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getHardcoreVampirismStatLeechPercentage() < 0.01 || getHardcoreVampirismStatLeechPercentage() > 100) {
|
|
|
- reason.add("Hardcore.Vampirism.Leech_Percentage only accepts values from 0.01 to 100!");
|
|
|
- }
|
|
|
-
|
|
|
- /* Items */
|
|
|
- if (getChimaeraUseCost() < 1 || getChimaeraUseCost() > 64) {
|
|
|
- reason.add("Items.Chimaera_Wing.Use_Cost only accepts values from 1 to 64!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getChimaeraRecipeCost() < 1 || getChimaeraRecipeCost() > 9) {
|
|
|
- reason.add("Items.Chimaera_Wing.Recipe_Cost only accepts values from 1 to 9!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getChimaeraItem() == null) {
|
|
|
- reason.add("Items.Chimaera_Wing.Item_Name is invalid!");
|
|
|
- }
|
|
|
-
|
|
|
- /* Particles */
|
|
|
- if (getLevelUpEffectsTier() < 1) {
|
|
|
- reason.add("Particles.LevelUp_Tier should be at least 1!");
|
|
|
- }
|
|
|
-
|
|
|
- /* PARTY SETTINGS */
|
|
|
- if (getAutoPartyKickInterval() < -1) {
|
|
|
- reason.add("Party.AutoKick_Interval should be at least -1!");
|
|
|
- }
|
|
|
+ /* PATH VARS */
|
|
|
|
|
|
- if (getAutoPartyKickTime() < 0) {
|
|
|
- reason.add("Party.Old_Party_Member_Cutoff should be at least 0!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getPartyShareBonusBase() <= 0) {
|
|
|
- reason.add("Party.Sharing.ExpShare_bonus_base should be greater than 0!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getPartyShareBonusIncrease() < 0) {
|
|
|
- reason.add("Party.Sharing.ExpShare_bonus_increase should be at least 0!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getPartyShareBonusCap() <= 0) {
|
|
|
- reason.add("Party.Sharing.ExpShare_bonus_cap should be greater than 0!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getPartyShareRange() <= 0) {
|
|
|
- reason.add("Party.Sharing.Range should be greater than 0!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getPartyXpCurveMultiplier() < 1) {
|
|
|
- reason.add("Party.Leveling.Xp_Curve_Modifier should be at least 1!");
|
|
|
- }
|
|
|
-
|
|
|
- for (PartyFeature partyFeature : PartyFeature.values()) {
|
|
|
- if (getPartyFeatureUnlockLevel(partyFeature) < 0) {
|
|
|
- reason.add("Party.Leveling." + StringUtils.getPrettyPartyFeatureString(partyFeature).replace(" ", "") + "_UnlockLevel should be at least 0!");
|
|
|
- }
|
|
|
- }
|
|
|
+ public final File DIRECTORY_DATA_FOLDER; //Directory that the file is in
|
|
|
+ public final String FILE_RELATIVE_PATH; //Relative Path to the file
|
|
|
+ protected final String DIRECTORY_DEFAULTS = "defaults";
|
|
|
|
|
|
- /* Inspect command distance */
|
|
|
- if (getInspectDistance() <= 0) {
|
|
|
- reason.add("Commands.inspect.Max_Distance should be greater than 0!");
|
|
|
- }
|
|
|
+ /* LOADERS */
|
|
|
|
|
|
- if (getTreeFellerThreshold() <= 0) {
|
|
|
- reason.add("Abilities.Limits.Tree_Feller_Threshold should be greater than 0!");
|
|
|
- }
|
|
|
+ private YAMLConfigurationLoader defaultCopyLoader;
|
|
|
+ private YAMLConfigurationLoader userCopyLoader;
|
|
|
|
|
|
- if (getFishingLureModifier() < 0) {
|
|
|
- reason.add("Abilities.Fishing.Lure_Modifier should be at least 0!");
|
|
|
- }
|
|
|
+ /* CONFIG FILES */
|
|
|
|
|
|
- if (getDetonatorItem() == null) {
|
|
|
- reason.add("Skills.Mining.Detonator_Item is invalid!");
|
|
|
- }
|
|
|
+ private File resourceConfigCopy; //Copy of the default config from the JAR (file is copied so that admins can easily compare to defaults)
|
|
|
+ private File resourceUserCopy; //File in the /$MCMMO_ROOT/mcMMO/ directory that may contain user edited settings
|
|
|
|
|
|
- if (getRepairAnvilMaterial() == null) {
|
|
|
- reason.add("Skills.Repair.Anvil_Type is invalid!!");
|
|
|
- }
|
|
|
+ /* ROOT NODES */
|
|
|
|
|
|
- if (getSalvageAnvilMaterial() == null) {
|
|
|
- reason.add("Skills.Repair.Salvage_Anvil_Type is invalid!");
|
|
|
- }
|
|
|
+ private ConfigurationNode userRootNode = null;
|
|
|
+ private ConfigurationNode defaultRootNode = null;
|
|
|
|
|
|
- if (getRepairAnvilMaterial() == getSalvageAnvilMaterial()) {
|
|
|
- reason.add("Cannot use the same item for Repair and Salvage anvils!");
|
|
|
- }
|
|
|
+ /* CONFIG MANAGER */
|
|
|
+ private ConfigurationLoader<CommentedConfigurationNode> configManager;
|
|
|
|
|
|
- if (getTamingCOTWMaterial(EntityType.WOLF) == null) {
|
|
|
- reason.add("Skills.Taming.Call_Of_The_Wild.Wolf.Item_Material is invalid!!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getTamingCOTWMaterial(EntityType.OCELOT) == null) {
|
|
|
- reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot.Item_Material is invalid!!");
|
|
|
- }
|
|
|
-
|
|
|
- if (getTamingCOTWMaterial(EntityType.HORSE) == null) {
|
|
|
- reason.add("Skills.Taming.Call_Of_The_Wild.Horse.Item_Material is invalid!!");
|
|
|
- }
|
|
|
+ public Config(String pathToParentFolder, String relativePath) {
|
|
|
+ //TODO: Check if this works...
|
|
|
+ this(new File(pathToParentFolder), relativePath);
|
|
|
+ System.out.println("mcMMO Debug: Don't forget to check if loading config file by string instead of File works...");
|
|
|
+ }
|
|
|
|
|
|
- if (getTamingCOTWCost(EntityType.WOLF) <= 0) {
|
|
|
- reason.add("Skills.Taming.Call_Of_The_Wild.Wolf.Item_Amount should be greater than 0!");
|
|
|
- }
|
|
|
+ public Config(File pathToParentFolder, String relativePath) {
|
|
|
+ /*
|
|
|
+ * These must be at the top
|
|
|
+ */
|
|
|
+ mkdirDefaults(); // Make our default config dir
|
|
|
+ DIRECTORY_DATA_FOLDER = pathToParentFolder; //Data Folder for our plugin
|
|
|
+ FILE_RELATIVE_PATH = relativePath; //Relative path to config from a parent folder
|
|
|
|
|
|
- if (getTamingCOTWCost(EntityType.OCELOT) <= 0) {
|
|
|
- reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot.Item_Amount should be greater than 0!");
|
|
|
- }
|
|
|
+ //Attempt IO Operations
|
|
|
+ try {
|
|
|
+ //Makes sure we have valid Files corresponding to this config
|
|
|
+ initConfigFiles();
|
|
|
|
|
|
- if (getTamingCOTWCost(EntityType.HORSE) <= 0) {
|
|
|
- reason.add("Skills.Taming.Call_Of_The_Wild.Horse.Item_Amount should be greater than 0!");
|
|
|
- }
|
|
|
+ //Init MainConfig Loaders
|
|
|
+ initConfigLoaders();
|
|
|
|
|
|
- if (getTamingCOTWAmount(EntityType.WOLF) <= 0) {
|
|
|
- reason.add("Skills.Taming.Call_Of_The_Wild.Wolf.Summon_Amount should be greater than 0!");
|
|
|
- }
|
|
|
+ //Load MainConfig Nodes
|
|
|
+ loadConfig();
|
|
|
|
|
|
- if (getTamingCOTWAmount(EntityType.OCELOT) <= 0) {
|
|
|
- reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot.Summon_Amount should be greater than 0!");
|
|
|
+ //Attempt to update user file, and then load it into memory
|
|
|
+ readConfig();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
- if (getTamingCOTWAmount(EntityType.HORSE) <= 0) {
|
|
|
- reason.add("Skills.Taming.Call_Of_The_Wild.Horse.Summon_Amount should be greater than 0!");
|
|
|
- }
|
|
|
|
|
|
- return noErrorsInConfig(reason);
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * GENERAL SETTINGS
|
|
|
+ /**
|
|
|
+ * Initializes the default copy File and the user config File
|
|
|
+ * @throws IOException
|
|
|
*/
|
|
|
+ private void initConfigFiles() throws IOException {
|
|
|
+ //Init our config copy
|
|
|
+ resourceConfigCopy = initDefaultConfig();
|
|
|
|
|
|
- /* General Settings */
|
|
|
- public boolean getIsMetricsEnabled() {
|
|
|
- return config.getBoolean("Metrics.bstats", true);
|
|
|
- }
|
|
|
-
|
|
|
- //Retro mode will default the value to true if the config file doesn't contain the entry (server is from a previous mcMMO install)
|
|
|
- public boolean getIsRetroMode() {
|
|
|
- return config.getBoolean("General.RetroMode.Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- public String getLocale() {
|
|
|
- return config.getString("General.Locale", "en_us");
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getMOTDEnabled() {
|
|
|
- return config.getBoolean("General.MOTD_Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getShowProfileLoadedMessage() {
|
|
|
- return config.getBoolean("General.Show_Profile_Loaded", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getDonateMessageEnabled() {
|
|
|
- return config.getBoolean("Commands.mcmmo.Donate_Message", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getSaveInterval() {
|
|
|
- return config.getInt("General.Save_Interval", 10);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getStatsTrackingEnabled() {
|
|
|
- return config.getBoolean("General.Stats_Tracking", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getUpdateCheckEnabled() {
|
|
|
- return config.getBoolean("General.Update_Check", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPreferBeta() {
|
|
|
- return config.getBoolean("General.Prefer_Beta", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getVerboseLoggingEnabled() {
|
|
|
- return config.getBoolean("General.Verbose_Logging", false);
|
|
|
+ //Init the user file
|
|
|
+ resourceUserCopy = initUserConfig();
|
|
|
}
|
|
|
|
|
|
- public String getPartyChatPrefix() {
|
|
|
- return config.getString("Commands.partychat.Chat_Prefix_Format", "[[GREEN]]([[WHITE]]{0}[[GREEN]])");
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPartyChatColorLeaderName() {
|
|
|
- return config.getBoolean("Commands.partychat.Gold_Leader_Name", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPartyDisplayNames() {
|
|
|
- return config.getBoolean("Commands.partychat.Use_Display_Names", true);
|
|
|
- }
|
|
|
-
|
|
|
- public String getPartyChatPrefixAlly() {
|
|
|
- return config.getString("Commands.partychat.Chat_Prefix_Format_Ally", "[[GREEN]](A)[[RESET]]");
|
|
|
- }
|
|
|
-
|
|
|
- public String getAdminChatPrefix() {
|
|
|
- return config.getString("Commands.adminchat.Chat_Prefix_Format", "[[AQUA]][[[WHITE]]{0}[[AQUA]]]");
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getAdminDisplayNames() {
|
|
|
- return config.getBoolean("Commands.adminchat.Use_Display_Names", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getMatchOfflinePlayers() {
|
|
|
- return config.getBoolean("Commands.Generic.Match_OfflinePlayers", false);
|
|
|
- }
|
|
|
-
|
|
|
- public long getDatabasePlayerCooldown() {
|
|
|
- return config.getLong("Commands.Database.Player_Cooldown", 1750);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getLevelUpSoundsEnabled() {
|
|
|
- return config.getBoolean("General.LevelUp_Sounds", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getRefreshChunksEnabled() {
|
|
|
- return config.getBoolean("General.Refresh_Chunks", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getMobHealthbarEnabled() {
|
|
|
- return config.getBoolean("Mob_Healthbar.Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- /* Mob Healthbar */
|
|
|
- public MobHealthbarType getMobHealthbarDefault() {
|
|
|
+ /**
|
|
|
+ * Loads the root node for the default config File and user config File
|
|
|
+ */
|
|
|
+ private void loadConfig()
|
|
|
+ {
|
|
|
try {
|
|
|
- return MobHealthbarType.valueOf(config.getString("Mob_Healthbar.Display_Type", "HEARTS").toUpperCase().trim());
|
|
|
- } catch (IllegalArgumentException ex) {
|
|
|
- return MobHealthbarType.HEARTS;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public int getMobHealthbarTime() {
|
|
|
- return config.getInt("Mob_Healthbar.Display_Time", 3);
|
|
|
- }
|
|
|
-
|
|
|
- /* Scoreboards */
|
|
|
- public boolean getScoreboardsEnabled() {
|
|
|
- return config.getBoolean("Scoreboard.UseScoreboards", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPowerLevelTagsEnabled() {
|
|
|
- return config.getBoolean("Scoreboard.Power_Level_Tags", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getAllowKeepBoard() {
|
|
|
- return config.getBoolean("Scoreboard.Allow_Keep", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getTipsAmount() {
|
|
|
- return config.getInt("Scoreboard.Tips_Amount", 5);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getShowStatsAfterLogin() {
|
|
|
- return config.getBoolean("Scoreboard.Show_Stats_After_Login", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getScoreboardRainbows() {
|
|
|
- return config.getBoolean("Scoreboard.Rainbows", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getShowAbilityNames() {
|
|
|
- return config.getBoolean("Scoreboard.Ability_Names", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getRankUseChat() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Rank.Print", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getRankUseBoard() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Rank.Board", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getRankScoreboardTime() {
|
|
|
- return config.getInt("Scoreboard.Types.Rank.Display_Time", 10);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getTopUseChat() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Top.Print", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getTopUseBoard() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Top.Board", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getTopScoreboardTime() {
|
|
|
- return config.getInt("Scoreboard.Types.Top.Display_Time", 15);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getStatsUseChat() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Stats.Print", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getStatsUseBoard() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Stats.Board", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getStatsScoreboardTime() {
|
|
|
- return config.getInt("Scoreboard.Types.Stats.Display_Time", 10);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getInspectUseChat() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Inspect.Print", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getInspectUseBoard() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Inspect.Board", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getInspectScoreboardTime() {
|
|
|
- return config.getInt("Scoreboard.Types.Inspect.Display_Time", 25);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getCooldownUseChat() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Cooldown.Print", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getCooldownUseBoard() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Cooldown.Board", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getCooldownScoreboardTime() {
|
|
|
- return config.getInt("Scoreboard.Types.Cooldown.Display_Time", 41);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getSkillUseBoard() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Skill.Board", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getSkillScoreboardTime() {
|
|
|
- return config.getInt("Scoreboard.Types.Skill.Display_Time", 30);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getSkillLevelUpBoard() {
|
|
|
- return config.getBoolean("Scoreboard.Types.Skill.LevelUp_Board", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getSkillLevelUpTime() {
|
|
|
- return config.getInt("Scoreboard.Types.Skill.LevelUp_Time", 5);
|
|
|
- }
|
|
|
-
|
|
|
- /* Database Purging */
|
|
|
- public int getPurgeInterval() {
|
|
|
- return config.getInt("Database_Purging.Purge_Interval", -1);
|
|
|
- }
|
|
|
-
|
|
|
- public int getOldUsersCutoff() {
|
|
|
- return config.getInt("Database_Purging.Old_User_Cutoff", 6);
|
|
|
- }
|
|
|
-
|
|
|
- /* Backups */
|
|
|
- public boolean getBackupsEnabled() {
|
|
|
- return config.getBoolean("Backups.Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getKeepLast24Hours() {
|
|
|
- return config.getBoolean("Backups.Keep.Last_24_Hours", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getKeepDailyLastWeek() {
|
|
|
- return config.getBoolean("Backups.Keep.Daily_Last_Week", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getKeepWeeklyPastMonth() {
|
|
|
- return config.getBoolean("Backups.Keep.Weekly_Past_Months", true);
|
|
|
- }
|
|
|
-
|
|
|
- /* mySQL */
|
|
|
- public boolean getUseMySQL() {
|
|
|
- return config.getBoolean("MySQL.Enabled", false);
|
|
|
- }
|
|
|
-
|
|
|
- public String getMySQLTablePrefix() {
|
|
|
- return config.getString("MySQL.Database.TablePrefix", "mcmmo_");
|
|
|
- }
|
|
|
-
|
|
|
- public String getMySQLDatabaseName() {
|
|
|
- return getStringIncludingInts("MySQL.Database.Name");
|
|
|
- }
|
|
|
-
|
|
|
- public String getMySQLUserName() {
|
|
|
- return getStringIncludingInts("MySQL.Database.User_Name");
|
|
|
- }
|
|
|
-
|
|
|
- public int getMySQLServerPort() {
|
|
|
- return config.getInt("MySQL.Server.Port", 3306);
|
|
|
- }
|
|
|
-
|
|
|
- public String getMySQLServerName() {
|
|
|
- return config.getString("MySQL.Server.Address", "localhost");
|
|
|
- }
|
|
|
+ final ConfigurationNode defaultConfig = this.defaultCopyLoader.load();
|
|
|
+ defaultRootNode = defaultConfig;
|
|
|
|
|
|
- public String getMySQLUserPassword() {
|
|
|
- return getStringIncludingInts("MySQL.Database.User_Password");
|
|
|
- }
|
|
|
-
|
|
|
- public int getMySQLMaxConnections(SQLDatabaseManager.PoolIdentifier identifier) {
|
|
|
- return config.getInt("MySQL.Database.MaxConnections." + StringUtils.getCapitalized(identifier.toString()), 30);
|
|
|
- }
|
|
|
-
|
|
|
- public int getMySQLMaxPoolSize(SQLDatabaseManager.PoolIdentifier identifier) {
|
|
|
- return config.getInt("MySQL.Database.MaxPoolSize." + StringUtils.getCapitalized(identifier.toString()), 10);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getMySQLSSL() {
|
|
|
- return config.getBoolean("MySQL.Server.SSL", true);
|
|
|
- }
|
|
|
+ final ConfigurationNode userConfig = this.userCopyLoader.load();
|
|
|
+ userRootNode = userConfig;
|
|
|
|
|
|
- private String getStringIncludingInts(String key) {
|
|
|
- String str = config.getString(key);
|
|
|
-
|
|
|
- if (str == null) {
|
|
|
- str = String.valueOf(config.getInt(key));
|
|
|
- }
|
|
|
-
|
|
|
- if (str.equals("0")) {
|
|
|
- str = "No value set for '" + key + "'";
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- return str;
|
|
|
- }
|
|
|
-
|
|
|
- /* Hardcore Mode */
|
|
|
- public boolean getHardcoreStatLossEnabled(PrimarySkillType primarySkillType) {
|
|
|
- return config.getBoolean("Hardcore.Death_Stat_Loss.Enabled." + StringUtils.getCapitalized(primarySkillType.toString()), false);
|
|
|
- }
|
|
|
-
|
|
|
- public void setHardcoreStatLossEnabled(PrimarySkillType primarySkillType, boolean enabled) {
|
|
|
- config.set("Hardcore.Death_Stat_Loss.Enabled." + StringUtils.getCapitalized(primarySkillType.toString()), enabled);
|
|
|
- }
|
|
|
-
|
|
|
- public double getHardcoreDeathStatPenaltyPercentage() {
|
|
|
- return config.getDouble("Hardcore.Death_Stat_Loss.Penalty_Percentage", 75.0D);
|
|
|
- }
|
|
|
-
|
|
|
- public void setHardcoreDeathStatPenaltyPercentage(double value) {
|
|
|
- config.set("Hardcore.Death_Stat_Loss.Penalty_Percentage", value);
|
|
|
- }
|
|
|
-
|
|
|
- public int getHardcoreDeathStatPenaltyLevelThreshold() {
|
|
|
- return config.getInt("Hardcore.Death_Stat_Loss.Level_Threshold", 0);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getHardcoreVampirismEnabled(PrimarySkillType primarySkillType) {
|
|
|
- return config.getBoolean("Hardcore.Vampirism.Enabled." + StringUtils.getCapitalized(primarySkillType.toString()), false);
|
|
|
- }
|
|
|
-
|
|
|
- public void setHardcoreVampirismEnabled(PrimarySkillType primarySkillType, boolean enabled) {
|
|
|
- config.set("Hardcore.Vampirism.Enabled." + StringUtils.getCapitalized(primarySkillType.toString()), enabled);
|
|
|
- }
|
|
|
-
|
|
|
- public double getHardcoreVampirismStatLeechPercentage() {
|
|
|
- return config.getDouble("Hardcore.Vampirism.Leech_Percentage", 5.0D);
|
|
|
- }
|
|
|
-
|
|
|
- public void setHardcoreVampirismStatLeechPercentage(double value) {
|
|
|
- config.set("Hardcore.Vampirism.Leech_Percentage", value);
|
|
|
- }
|
|
|
-
|
|
|
- public int getHardcoreVampirismLevelThreshold() {
|
|
|
- return config.getInt("Hardcore.Vampirism.Level_Threshold", 0);
|
|
|
- }
|
|
|
-
|
|
|
- /* SMP Mods */
|
|
|
- public boolean getToolModsEnabled() {
|
|
|
- return config.getBoolean("Mods.Tool_Mods_Enabled", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getArmorModsEnabled() {
|
|
|
- return config.getBoolean("Mods.Armor_Mods_Enabled", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getBlockModsEnabled() {
|
|
|
- return config.getBoolean("Mods.Block_Mods_Enabled", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getEntityModsEnabled() {
|
|
|
- return config.getBoolean("Mods.Entity_Mods_Enabled", false);
|
|
|
- }
|
|
|
-
|
|
|
- /* Items */
|
|
|
- public int getChimaeraUseCost() {
|
|
|
- return config.getInt("Items.Chimaera_Wing.Use_Cost", 1);
|
|
|
- }
|
|
|
-
|
|
|
- public int getChimaeraRecipeCost() {
|
|
|
- return config.getInt("Items.Chimaera_Wing.Recipe_Cost", 5);
|
|
|
- }
|
|
|
-
|
|
|
- public Material getChimaeraItem() {
|
|
|
- return Material.matchMaterial(config.getString("Items.Chimaera_Wing.Item_Name", "Feather"));
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getChimaeraEnabled() {
|
|
|
- return config.getBoolean("Items.Chimaera_Wing.Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getChimaeraPreventUseUnderground() {
|
|
|
- return config.getBoolean("Items.Chimaera_Wing.Prevent_Use_Underground", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getChimaeraUseBedSpawn() {
|
|
|
- return config.getBoolean("Items.Chimaera_Wing.Use_Bed_Spawn", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getChimaeraCooldown() {
|
|
|
- return config.getInt("Items.Chimaera_Wing.Cooldown", 240);
|
|
|
- }
|
|
|
-
|
|
|
- public int getChimaeraWarmup() {
|
|
|
- return config.getInt("Items.Chimaera_Wing.Warmup", 5);
|
|
|
- }
|
|
|
-
|
|
|
- public int getChimaeraRecentlyHurtCooldown() {
|
|
|
- return config.getInt("Items.Chimaera_Wing.RecentlyHurt_Cooldown", 60);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getChimaeraSoundEnabled() {
|
|
|
- return config.getBoolean("Items.Chimaera_Wing.Sound_Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getFluxPickaxeSoundEnabled() {
|
|
|
- return config.getBoolean("Items.Flux_Pickaxe.Sound_Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- /* Particles */
|
|
|
- public boolean getAbilityActivationEffectEnabled() {
|
|
|
- return config.getBoolean("Particles.Ability_Activation", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getAbilityDeactivationEffectEnabled() {
|
|
|
- return config.getBoolean("Particles.Ability_Deactivation", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getBleedEffectEnabled() {
|
|
|
- return config.getBoolean("Particles.Bleed", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getDodgeEffectEnabled() {
|
|
|
- return config.getBoolean("Particles.Dodge", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getFluxEffectEnabled() {
|
|
|
- return config.getBoolean("Particles.Flux", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getGreaterImpactEffectEnabled() {
|
|
|
- return config.getBoolean("Particles.Greater_Impact", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getCallOfTheWildEffectEnabled() {
|
|
|
- return config.getBoolean("Particles.Call_of_the_Wild", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getLevelUpEffectsEnabled() {
|
|
|
- return config.getBoolean("Particles.LevelUp_Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- public int getLevelUpEffectsTier() {
|
|
|
- return config.getInt("Particles.LevelUp_Tier", 100);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getLargeFireworks() {
|
|
|
- return config.getBoolean("Particles.LargeFireworks", true);
|
|
|
- }
|
|
|
-
|
|
|
- /* PARTY SETTINGS */
|
|
|
- public boolean getPartyFriendlyFire() {
|
|
|
- return config.getBoolean("Party.FriendlyFire", false);
|
|
|
- }
|
|
|
-
|
|
|
- public int getPartyMaxSize() {
|
|
|
- return config.getInt("Party.MaxSize", -1);
|
|
|
- }
|
|
|
-
|
|
|
- public int getAutoPartyKickInterval() {
|
|
|
- return config.getInt("Party.AutoKick_Interval", 12);
|
|
|
- }
|
|
|
-
|
|
|
- public int getAutoPartyKickTime() {
|
|
|
- return config.getInt("Party.Old_Party_Member_Cutoff", 7);
|
|
|
- }
|
|
|
-
|
|
|
- public double getPartyShareBonusBase() {
|
|
|
- return config.getDouble("Party.Sharing.ExpShare_bonus_base", 1.1D);
|
|
|
- }
|
|
|
-
|
|
|
- public double getPartyShareBonusIncrease() {
|
|
|
- return config.getDouble("Party.Sharing.ExpShare_bonus_increase", 0.05D);
|
|
|
- }
|
|
|
-
|
|
|
- public double getPartyShareBonusCap() {
|
|
|
- return config.getDouble("Party.Sharing.ExpShare_bonus_cap", 1.5D);
|
|
|
- }
|
|
|
-
|
|
|
- public double getPartyShareRange() {
|
|
|
- return config.getDouble("Party.Sharing.Range", 75.0D);
|
|
|
- }
|
|
|
-
|
|
|
- public int getPartyLevelCap() {
|
|
|
- int cap = config.getInt("Party.Leveling.Level_Cap", 10);
|
|
|
- return (cap <= 0) ? Integer.MAX_VALUE : cap;
|
|
|
- }
|
|
|
-
|
|
|
- public int getPartyXpCurveMultiplier() {
|
|
|
- return config.getInt("Party.Leveling.Xp_Curve_Modifier", 3);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPartyXpNearMembersNeeded() {
|
|
|
- return config.getBoolean("Party.Leveling.Near_Members_Needed", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPartyInformAllMembers() {
|
|
|
- return config.getBoolean("Party.Leveling.Inform_All_Party_Members_On_LevelUp", false);
|
|
|
}
|
|
|
|
|
|
- public int getPartyFeatureUnlockLevel(PartyFeature partyFeature) {
|
|
|
- return config.getInt("Party.Leveling." + StringUtils.getPrettyPartyFeatureString(partyFeature).replace(" ", "") + "_UnlockLevel", 0);
|
|
|
- }
|
|
|
-
|
|
|
- /* Party Teleport Settings */
|
|
|
- public int getPTPCommandCooldown() {
|
|
|
- return config.getInt("Commands.ptp.Cooldown", 120);
|
|
|
- }
|
|
|
-
|
|
|
- public int getPTPCommandWarmup() {
|
|
|
- return config.getInt("Commands.ptp.Warmup", 5);
|
|
|
- }
|
|
|
-
|
|
|
- public int getPTPCommandRecentlyHurtCooldown() {
|
|
|
- return config.getInt("Commands.ptp.RecentlyHurt_Cooldown", 60);
|
|
|
- }
|
|
|
-
|
|
|
- public int getPTPCommandTimeout() {
|
|
|
- return config.getInt("Commands.ptp.Request_Timeout", 300);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPTPCommandConfirmRequired() {
|
|
|
- return config.getBoolean("Commands.ptp.Accept_Required", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPTPCommandWorldPermissions() {
|
|
|
- return config.getBoolean("Commands.ptp.World_Based_Permissions", false);
|
|
|
- }
|
|
|
-
|
|
|
- /* Inspect command distance */
|
|
|
- public double getInspectDistance() {
|
|
|
- return config.getDouble("Commands.inspect.Max_Distance", 30.0D);
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * ABILITY SETTINGS
|
|
|
+ /**
|
|
|
+ * Initializes the YAMLConfigurationLoaders for this config
|
|
|
*/
|
|
|
-
|
|
|
- /* General Settings */
|
|
|
- public boolean getUrlLinksEnabled() {
|
|
|
- return config.getBoolean("Commands.Skills.URL_Links");
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getAbilityMessagesEnabled() {
|
|
|
- return config.getBoolean("Abilities.Messages", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getAbilitiesEnabled() {
|
|
|
- return config.getBoolean("Abilities.Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getAbilitiesOnlyActivateWhenSneaking() {
|
|
|
- return config.getBoolean("Abilities.Activation.Only_Activate_When_Sneaking", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getAbilitiesGateEnabled() {
|
|
|
- return config.getBoolean("Abilities.Activation.Level_Gate_Abilities");
|
|
|
- }
|
|
|
-
|
|
|
- public int getCooldown(SuperAbilityType ability) {
|
|
|
- return config.getInt("Abilities.Cooldowns." + ability.toString());
|
|
|
- }
|
|
|
-
|
|
|
- public int getMaxLength(SuperAbilityType ability) {
|
|
|
- return config.getInt("Abilities.Max_Seconds." + ability.toString());
|
|
|
- }
|
|
|
-
|
|
|
- /* Durability Settings */
|
|
|
- public int getAbilityToolDamage() {
|
|
|
- return config.getInt("Abilities.Tools.Durability_Loss", 1);
|
|
|
- }
|
|
|
-
|
|
|
- /* Thresholds */
|
|
|
- public int getTreeFellerThreshold() {
|
|
|
- return config.getInt("Abilities.Limits.Tree_Feller_Threshold", 500);
|
|
|
+ private void initConfigLoaders()
|
|
|
+ {
|
|
|
+ this.defaultCopyLoader = YAMLConfigurationLoader.builder().setPath(resourceConfigCopy.toPath()).setFlowStyle(DumperOptions.FlowStyle.BLOCK).build();
|
|
|
+ this.userCopyLoader = YAMLConfigurationLoader.builder().setPath(resourceUserCopy.toPath()).setFlowStyle(DumperOptions.FlowStyle.FLOW).build();
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * SKILL SETTINGS
|
|
|
+ /**
|
|
|
+ * Copies a new file from the JAR to the defaults directory and uses that new file to initialize our resourceConfigCopy
|
|
|
+ * @see Config#resourceConfigCopy
|
|
|
+ * @throws IOException
|
|
|
*/
|
|
|
- public boolean getDoubleDropsEnabled(PrimarySkillType skill, Material material) {
|
|
|
- return config.getBoolean("Double_Drops." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getPrettyItemString(material).replace(" ", "_"));
|
|
|
+ private File initDefaultConfig() throws IOException {
|
|
|
+ return copyDefaultFromJar(getDefaultConfigCopyRelativePath(), true);
|
|
|
}
|
|
|
|
|
|
- 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;
|
|
|
+ /**
|
|
|
+ * Attemps to load the config file if it exists, if it doesn't it copies a new one from within the JAR
|
|
|
+ * @return user config File
|
|
|
+ * @see Config#resourceUserCopy
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ private File initUserConfig() throws IOException {
|
|
|
+ File userCopy = new File(DIRECTORY_DATA_FOLDER, FILE_RELATIVE_PATH); //Load the user file;
|
|
|
|
|
|
- for (String key : keys) {
|
|
|
- if (config.getBoolean("Double_Drops." + skillName + "." + key)) {
|
|
|
- disabled = false;
|
|
|
- break;
|
|
|
- }
|
|
|
+ if(userCopy.exists())
|
|
|
+ {
|
|
|
+ // Yay
|
|
|
+ return userCopy;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //If it's gone we copy default files
|
|
|
+ //Note that we don't copy the values from the default copy put in /defaults/ that file exists only as a reference to admins and is unreliable
|
|
|
+ return copyDefaultFromJar(FILE_RELATIVE_PATH, false);
|
|
|
}
|
|
|
-
|
|
|
- return disabled;
|
|
|
- }
|
|
|
-
|
|
|
- /* Axes */
|
|
|
- public int getAxesGate() {
|
|
|
- return config.getInt("Skills.Axes.Ability_Activation_Level_Gate", 10);
|
|
|
- }
|
|
|
-
|
|
|
- /* Acrobatics */
|
|
|
- public boolean getDodgeLightningDisabled() {
|
|
|
- return config.getBoolean("Skills.Acrobatics.Prevent_Dodge_Lightning", false);
|
|
|
- }
|
|
|
-
|
|
|
- public int getXPAfterTeleportCooldown() {
|
|
|
- return config.getInt("Skills.Acrobatics.XP_After_Teleport_Cooldown", 5);
|
|
|
- }
|
|
|
-
|
|
|
- /* Alchemy */
|
|
|
- public boolean getEnabledForHoppers() {
|
|
|
- return config.getBoolean("Skills.Alchemy.Enabled_for_Hoppers", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPreventHopperTransferIngredients() {
|
|
|
- return config.getBoolean("Skills.Alchemy.Prevent_Hopper_Transfer_Ingredients", false);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getPreventHopperTransferBottles() {
|
|
|
- return config.getBoolean("Skills.Alchemy.Prevent_Hopper_Transfer_Bottles", false);
|
|
|
- }
|
|
|
-
|
|
|
- /* Fishing */
|
|
|
- public boolean getFishingDropsEnabled() {
|
|
|
- return config.getBoolean("Skills.Fishing.Drops_Enabled", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getFishingOverrideTreasures() {
|
|
|
- return config.getBoolean("Skills.Fishing.Override_Vanilla_Treasures", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getFishingExtraFish() {
|
|
|
- return config.getBoolean("Skills.Fishing.Extra_Fish", true);
|
|
|
- }
|
|
|
-
|
|
|
- public double getFishingLureModifier() {
|
|
|
- return config.getDouble("Skills.Fishing.Lure_Modifier", 4.0D);
|
|
|
- }
|
|
|
-
|
|
|
- /* Mining */
|
|
|
- public Material getDetonatorItem() {
|
|
|
- return Material.matchMaterial(config.getString("Skills.Mining.Detonator_Name", "FLINT_AND_STEEL"));
|
|
|
- }
|
|
|
-
|
|
|
- public int getMiningGate() {
|
|
|
- return config.getInt("Skills.Mining.Ability_Activation_Level_Gate", 10);
|
|
|
- }
|
|
|
-
|
|
|
- /* Excavation */
|
|
|
- public int getExcavationGate() {
|
|
|
- return config.getInt("Skills.Excavation.Ability_Activation_Level_Gate", 10);
|
|
|
- }
|
|
|
-
|
|
|
- /* Repair */
|
|
|
- public boolean getRepairAnvilMessagesEnabled() {
|
|
|
- return config.getBoolean("Skills.Repair.Anvil_Messages", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getRepairAnvilPlaceSoundsEnabled() {
|
|
|
- return config.getBoolean("Skills.Repair.Anvil_Placed_Sounds", true);
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getRepairAnvilUseSoundsEnabled() {
|
|
|
- return config.getBoolean("Skills.Repair.Anvil_Use_Sounds", true);
|
|
|
- }
|
|
|
-
|
|
|
- public Material getRepairAnvilMaterial() {
|
|
|
- return Material.matchMaterial(config.getString("Skills.Repair.Anvil_Material", "IRON_BLOCK"));
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getRepairConfirmRequired() {
|
|
|
- return config.getBoolean("Skills.Repair.Confirm_Required", true);
|
|
|
- }
|
|
|
-
|
|
|
- /* Salvage */
|
|
|
- public boolean getSalvageAnvilMessagesEnabled() {
|
|
|
- return config.getBoolean("Skills.Salvage.Anvil_Messages", true);
|
|
|
}
|
|
|
|
|
|
- public boolean getSalvageAnvilPlaceSoundsEnabled() {
|
|
|
- return config.getBoolean("Skills.Salvage.Anvil_Placed_Sounds", true);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Used to make a new config file at a specified relative output path inside the data directory by copying the matching file found in that same relative path within the JAR
|
|
|
+ * @param relativeOutputPath the path to the output file
|
|
|
+ * @param deleteOld whether or not to delete the existing output file on disk
|
|
|
+ * @return a copy of the default config within the JAR
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ private File copyDefaultFromJar(String relativeOutputPath, boolean deleteOld) throws IOException
|
|
|
+ {
|
|
|
+ /*
|
|
|
+ * Gen a Default config from inside the JAR
|
|
|
+ */
|
|
|
+ McmmoCore.getLogger().info("Preparing to copy internal resource file (in JAR) - "+FILE_RELATIVE_PATH);
|
|
|
+ InputStream inputStream = McmmoCore.getResource(FILE_RELATIVE_PATH);
|
|
|
|
|
|
- public boolean getSalvageAnvilUseSoundsEnabled() {
|
|
|
- return config.getBoolean("Skills.Salvage.Anvil_Use_Sounds", true);
|
|
|
- }
|
|
|
+ byte[] buffer = new byte[inputStream.available()];
|
|
|
+ inputStream.read(buffer);
|
|
|
|
|
|
- public Material getSalvageAnvilMaterial() {
|
|
|
- return Material.matchMaterial(config.getString("Skills.Salvage.Anvil_Material", "GOLD_BLOCK"));
|
|
|
- }
|
|
|
+ //This is a copy of the default file, which we will overwrite every time mcMMO loads
|
|
|
+ File targetFile = new File(DIRECTORY_DATA_FOLDER, relativeOutputPath);
|
|
|
|
|
|
- public boolean getSalvageConfirmRequired() {
|
|
|
- return config.getBoolean("Skills.Salvage.Confirm_Required", true);
|
|
|
- }
|
|
|
+ //Wipe old default file on disk
|
|
|
+ if (targetFile.exists() && deleteOld)
|
|
|
+ {
|
|
|
+ McmmoCore.getLogger().info("Updating file " + relativeOutputPath);
|
|
|
+ targetFile.delete(); //Necessary?
|
|
|
+ }
|
|
|
|
|
|
- /* Unarmed */
|
|
|
- public boolean getUnarmedBlockCrackerSmoothbrickToCracked() {
|
|
|
- return config.getBoolean("Skills.Unarmed.Block_Cracker.SmoothBrick_To_CrackedBrick", true);
|
|
|
- }
|
|
|
+ if(!targetFile.exists())
|
|
|
+ {
|
|
|
+ targetFile.getParentFile().mkdirs();
|
|
|
+ targetFile.createNewFile(); //New File Boys
|
|
|
+ }
|
|
|
|
|
|
- public boolean getUnarmedItemPickupDisabled() {
|
|
|
- return config.getBoolean("Skills.Unarmed.Item_Pickup_Disabled_Full_Inventory", true);
|
|
|
- }
|
|
|
+ Files.write(buffer, targetFile);
|
|
|
+ McmmoCore.getLogger().info("Created config file - " + relativeOutputPath);
|
|
|
|
|
|
- public boolean getUnarmedItemsAsUnarmed() {
|
|
|
- return config.getBoolean("Skills.Unarmed.Items_As_Unarmed", false);
|
|
|
- }
|
|
|
+ inputStream.close(); //Close the input stream
|
|
|
|
|
|
- public int getUnarmedGate() {
|
|
|
- return config.getInt("Skills.Unarmed.Ability_Activation_Level_Gate", 10);
|
|
|
+ return targetFile;
|
|
|
}
|
|
|
|
|
|
- /* Swords */
|
|
|
- public int getSwordsGate() {
|
|
|
- return config.getInt("Skills.Swords.Ability_Activation_Level_Gate", 10);
|
|
|
+ /**
|
|
|
+ * The path to the defaults directory
|
|
|
+ * @return the path to the defaults directory
|
|
|
+ */
|
|
|
+ private String getDefaultConfigCopyRelativePath() {
|
|
|
+ return DIRECTORY_DEFAULTS + File.separator + FILE_RELATIVE_PATH;
|
|
|
}
|
|
|
|
|
|
- /* Taming */
|
|
|
- public Material getTamingCOTWMaterial(EntityType type) {
|
|
|
- return Material.matchMaterial(config.getString("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Item_Material"));
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Creates the defaults directory
|
|
|
+ */
|
|
|
+ private void mkdirDefaults() {
|
|
|
+ //Make Default Subdirectory
|
|
|
+ File defaultsDir = new File (DIRECTORY_DATA_FOLDER, "defaults");
|
|
|
|
|
|
- public int getTamingCOTWCost(EntityType type) {
|
|
|
- return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Item_Amount");
|
|
|
+ if(!defaultsDir.exists())
|
|
|
+ defaultsDir.mkdir();
|
|
|
}
|
|
|
|
|
|
- public int getTamingCOTWAmount(EntityType type) {
|
|
|
- return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Summon_Amount");
|
|
|
+ /**
|
|
|
+ * Configs are versioned based on when they had significant changes to keys
|
|
|
+ * @return current MainConfig Version String
|
|
|
+ */
|
|
|
+ public String getVersion()
|
|
|
+ {
|
|
|
+ return String.valueOf(getConfigVersion());
|
|
|
}
|
|
|
|
|
|
- public int getTamingCOTWLength(EntityType type) {
|
|
|
- return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Summon_Length");
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Attempts to read the loaded config file
|
|
|
+ * MainConfig will have any necessary updates applied
|
|
|
+ * MainConfig will be compared to the default config to see if it is missing any nodes
|
|
|
+ * MainConfig will have any missing nodes inserted with their default value
|
|
|
+ */
|
|
|
+ public void readConfig() {
|
|
|
+ McmmoCore.getLogger().info("Attempting to read " + FILE_RELATIVE_PATH + ".");
|
|
|
|
|
|
- public int getTamingCOTWMaxAmount(EntityType type) {
|
|
|
- return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Summon_Max_Amount");
|
|
|
- }
|
|
|
+ int version = this.userRootNode.getNode("ConfigVersion").getInt();
|
|
|
+ McmmoCore.getLogger().info(FILE_RELATIVE_PATH + " version is " + version);
|
|
|
|
|
|
- public double getTamingCOTWRange() {
|
|
|
- return config.getDouble("Skills.Taming.Call_Of_The_Wild.Range", 40.0D);
|
|
|
+ //Update our config
|
|
|
+ updateConfig();
|
|
|
}
|
|
|
|
|
|
- /* Woodcutting */
|
|
|
- public boolean getWoodcuttingDoubleDropsEnabled(BlockData material) {
|
|
|
- return config.getBoolean("Double_Drops.Woodcutting." + StringUtils.getFriendlyConfigBlockDataString(material));
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Compares the users config file to the default and adds any missing nodes and applies any necessary updates
|
|
|
+ */
|
|
|
+ private void updateConfig()
|
|
|
+ {
|
|
|
+ McmmoCore.getLogger().info(defaultRootNode.getChildrenMap().size() +" items in default children map");
|
|
|
+ McmmoCore.getLogger().info(userRootNode.getChildrenMap().size() +" items in default root map");
|
|
|
|
|
|
- public boolean getTreeFellerSoundsEnabled() {
|
|
|
- return config.getBoolean("Skills.Woodcutting.Tree_Feller_Sounds", true);
|
|
|
- }
|
|
|
+ // Merge Values from default
|
|
|
+ userRootNode = userRootNode.mergeValuesFrom(defaultRootNode);
|
|
|
|
|
|
- public int getWoodcuttingGate() {
|
|
|
- return config.getInt("Skills.Woodcutting.Ability_Activation_Level_Gate", 10);
|
|
|
- }
|
|
|
+ // Update config version
|
|
|
+ updateConfigVersion();
|
|
|
|
|
|
- /* AFK Leveling */
|
|
|
- public boolean getAcrobaticsPreventAFK() {
|
|
|
- return config.getBoolean("Skills.Acrobatics.Prevent_AFK_Leveling", true);
|
|
|
+ //Attempt to save
|
|
|
+ try {
|
|
|
+ saveUserCopy();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public int getAcrobaticsAFKMaxTries() {
|
|
|
- return config.getInt("Skills.Acrobatics.Max_Tries_At_Same_Location", 3);
|
|
|
+ /**
|
|
|
+ * Saves the current state information of the config to the users copy (which they may edit)
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ private void saveUserCopy() throws IOException
|
|
|
+ {
|
|
|
+ McmmoCore.getLogger().info("Saving new node");
|
|
|
+ userCopyLoader.save(userRootNode);
|
|
|
}
|
|
|
|
|
|
- public boolean getHerbalismPreventAFK() {
|
|
|
- return config.getBoolean("Skills.Herbalism.Prevent_AFK_Leveling", true);
|
|
|
+ /**
|
|
|
+ * Performs any necessary operations to update this config
|
|
|
+ */
|
|
|
+ private void updateConfigVersion() {
|
|
|
+ // Set a version for our config
|
|
|
+ this.userRootNode.getNode("ConfigVersion").setValue(getConfigVersion());
|
|
|
+ McmmoCore.getLogger().info("Updated config to ["+getConfigVersion()+"] - " + FILE_RELATIVE_PATH);
|
|
|
}
|
|
|
|
|
|
- /* Level Caps */
|
|
|
- public int getPowerLevelCap() {
|
|
|
- int cap = config.getInt("General.Power_Level_Cap", 0);
|
|
|
- return (cap <= 0) ? Integer.MAX_VALUE : cap;
|
|
|
+ /**
|
|
|
+ * Returns the root node of this config
|
|
|
+ * @return the root node of this config
|
|
|
+ */
|
|
|
+ protected ConfigurationNode getUserRootNode() {
|
|
|
+ return userRootNode;
|
|
|
}
|
|
|
|
|
|
- public int getLevelCap(PrimarySkillType skill) {
|
|
|
- int cap = config.getInt("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Level_Cap");
|
|
|
- return (cap <= 0) ? Integer.MAX_VALUE : cap;
|
|
|
+ int getIntValue(String... path)
|
|
|
+ {
|
|
|
+ return userRootNode.getNode(path).getInt();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /*public int isSuperAbilityUnlocked(PrimarySkillType skill) {
|
|
|
- return config.getInt("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Ability_Activation_Level_Gate");
|
|
|
- }*/
|
|
|
-
|
|
|
- public boolean getTruncateSkills() {
|
|
|
- return config.getBoolean("General.TruncateSkills", false);
|
|
|
+ double getDoubleValue(String... path)
|
|
|
+ {
|
|
|
+ return userRootNode.getNode(path).getDouble();
|
|
|
}
|
|
|
|
|
|
- /* PVP & PVE Settings */
|
|
|
- public boolean getPVPEnabled(PrimarySkillType skill) {
|
|
|
- return config.getBoolean("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Enabled_For_PVP", true);
|
|
|
+ boolean getBooleanValue(String... path)
|
|
|
+ {
|
|
|
+ return userRootNode.getNode(path).getBoolean();
|
|
|
}
|
|
|
|
|
|
- public boolean getPVEEnabled(PrimarySkillType skill) {
|
|
|
- return config.getBoolean("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Enabled_For_PVE", true);
|
|
|
+ String getStringValue(String... path)
|
|
|
+ {
|
|
|
+ return userRootNode.getNode(path).getString();
|
|
|
}
|
|
|
-
|
|
|
- //public float getMasterVolume() { return (float) config.getDouble("Sounds.MasterVolume", 1.0); }
|
|
|
}
|