new config system part 3

This commit is contained in:
nossr50 2019-02-12 01:24:54 -08:00
parent 0f743a55b5
commit fd8e44ef47
2 changed files with 44 additions and 13 deletions

18
pom.xml
View File

@ -101,6 +101,7 @@
<include>org.bstats:bstats-bukkit</include>
<include>org.spongepowered:configurate-yaml</include>
<include>org.spongepowered:configurate-core</include>
<!--<include>com.flowpowered:flow-math</include>-->
</includes>
</artifactSet>
<relocations>
@ -120,6 +121,14 @@
<pattern>org.bstats</pattern>
<shadedPattern>com.gmail.nossr50.metrics.bstat</shadedPattern>
</relocation>
<!--<relocation>
<pattern>com.flowpowered</pattern>
<shadedPattern>com.gmail.nossr50.flow</shadedPattern>
</relocation>-->
<relocation>
<pattern>ninja.leaping</pattern>
<shadedPattern>com.gmail.nossr50.configurable</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
@ -145,6 +154,10 @@
<id>sponge</id>
<url>https://repo.spongepowered.org/maven</url>
</repository>
<repository>
<id>flow</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
@ -159,6 +172,11 @@
</repository>
</repositories>
<dependencies>
<!--<dependency>
<groupId>com.flowpowered</groupId>
<artifactId>flow-math</artifactId>
<version>1.0.4-SNAPSHOT</version>
</dependency>-->
<dependency>
<groupId>org.spongepowered</groupId>
<!-- Modify this line to target the loader you wish to use. -->

View File

@ -35,7 +35,7 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
/* ROOT NODES */
private ConfigurationNode rootNode = null;
private ConfigurationNode userRootNode = null;
private ConfigurationNode defaultRootNode = null;
//TODO: Needed?
@ -91,7 +91,7 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
defaultRootNode = defaultConfig;
final ConfigurationNode userConfig = this.userCopyLoader.load();
rootNode = userConfig;
userRootNode = userConfig;
} catch (IOException e) {
e.printStackTrace();
@ -214,7 +214,7 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
public void readConfig() {
mcMMO.p.getLogger().info("Attempting to read " + FILE_RELATIVE_PATH + ".");
int version = this.rootNode.getNode("ConfigVersion").getInt();
int version = this.userRootNode.getNode("ConfigVersion").getInt();
mcMMO.p.getLogger().info(FILE_RELATIVE_PATH + " version is " + version);
//Update our config
@ -226,18 +226,31 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
*/
private void updateConfig()
{
boolean addedValues = false;
mcMMO.p.getLogger().info(defaultRootNode.getChildrenMap().size() +" items in default children map");
mcMMO.p.getLogger().info(rootNode.getChildrenMap().size() +" items in default root map");
mcMMO.p.getLogger().info(userRootNode.getChildrenMap().size() +" items in default root map");
if(addedValues)
{
System.out.println("[mcMMO INFO] New config options were added, edit "+FILE_RELATIVE_PATH+" to customize!");
}
// Merge Values from default
userRootNode = userRootNode.mergeValuesFrom(defaultRootNode);
// Update config version
updateConfigVersion();
//Attempt to save
try {
saveUserCopy();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Saves the current state information of the config to the users copy (which they may edit)
* @throws IOException
*/
private void saveUserCopy() throws IOException
{
mcMMO.p.getLogger().info("Saving new node");
userCopyLoader.save(userRootNode);
}
/**
@ -245,7 +258,7 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
*/
private void updateConfigVersion() {
// Set a version for our config
this.rootNode.getNode("ConfigVersion").setValue(getConfigVersion());
this.userRootNode.getNode("ConfigVersion").setValue(getConfigVersion());
mcMMO.p.getLogger().info("Updated config to ["+getConfigVersion()+"] - " + FILE_RELATIVE_PATH);
}
@ -253,7 +266,7 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
* Returns the root node of this config
* @return the root node of this config
*/
protected ConfigurationNode getRootNode() {
return rootNode;
protected ConfigurationNode getUserRootNode() {
return userRootNode;
}
}