new config system pt 5

This commit is contained in:
nossr50 2019-02-12 06:17:27 -08:00
parent e7b91f57ea
commit bf63ce33c5
4 changed files with 29 additions and 13 deletions

View File

@ -5,10 +5,13 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
import com.gmail.nossr50.mcMMO;
import net.md_5.bungee.api.ChatColor;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import java.util.ArrayList;
import java.util.List;
@ConfigSerializable
public class AdvancedConfig extends ConfigLoaderConfigurable {
private static AdvancedConfig instance;
@ -24,6 +27,9 @@ public class AdvancedConfig extends ConfigLoaderConfigurable {
return instance;
}
@Setting(value = "Skills.General.StartingLevel", comment = "The starting level for players on your server.\nHistorically this has been 0.\nRecently is has changed to 1.")
private int startingLevel = 1;
@Override
public List<String> validateKeys() {
// Validate all the settings!
@ -369,7 +375,7 @@ public class AdvancedConfig extends ConfigLoaderConfigurable {
}
/* GENERAL */
public int getStartingLevel() { return getIntValue("Skills.General.StartingLevel"); }
public int getStartingLevel() { return startingLevel; }
/**
* This returns the maximum level at which superabilities will stop lengthening from scaling alongside skill level.

View File

@ -3,6 +3,8 @@ package com.gmail.nossr50.config;
import com.gmail.nossr50.mcMMO;
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.objectmapping.serialize.ConfigSerializable;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
@ -37,6 +39,10 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
private ConfigurationNode userRootNode = null;
private ConfigurationNode defaultRootNode = null;
private CommentedConfigurationNode userCommentedRootNode = null;
/* CONFIG MANAGER */
private ConfigurationLoader<CommentedConfigurationNode> configManager;
//TODO: Needed?
//private ConfigurationLoader<CommentedConfigurationNode> configManager;
@ -105,6 +111,9 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
final ConfigurationNode userConfig = this.userCopyLoader.load();
userRootNode = userConfig;
//TESTING THIS
userCommentedRootNode = configManager.load();
} catch (IOException e) {
e.printStackTrace();
}
@ -282,28 +291,23 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
return userRootNode;
}
/**
* Attempts to get an int value from the config
* @param path path the node from the root node
* @return int value of the node
*/
int getIntValue(String path)
{
return userRootNode.getNode(path).getInt();
return userRootNode.getNode(path.split(".")).getInt();
}
double getDoubleValue(String path)
{
return userRootNode.getNode(path).getDouble();
return userRootNode.getNode(path.split(".")).getDouble();
}
boolean getBooleanValue(String path)
{
return userRootNode.getNode(path).getBoolean();
return userRootNode.getNode(path.split(".")).getBoolean();
}
String getStringValue(String path)
{
return userRootNode.getNode(path).getString();
return userRootNode.getNode(path.split(".")).getString();
}
}

View File

@ -1,18 +1,21 @@
package com.gmail.nossr50.config;
import com.gmail.nossr50.mcMMO;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import java.util.List;
@ConfigSerializable
public class ConfigurableTest extends ConfigLoaderConfigurable {
public final static String relativePath = "configurabletest.yml";
private static ConfigurableTest instance;
public ConfigurableTest() {
super(mcMMO.p.getDataFolder(), relativePath);
mcMMO.p.getLogger().severe("The value of bone "+boneValue);
}
public static ConfigurableTest getInstance() {
@ -22,6 +25,9 @@ public class ConfigurableTest extends ConfigLoaderConfigurable {
return instance;
}
@Setting(value = "woof.bone", comment = "Finally we have found the value of bone")
double boneValue = 9.4447;
@Override
public List<String> validateKeys() {
return null;

View File

@ -6,4 +6,4 @@ TheBidoofNotation:
Woof:
Bark:
Meow: "Reeeee"
Bone: 8.3827
Bone: 9.4447