mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-01 16:19:53 +01:00
new config system part 3
This commit is contained in:
parent
0f743a55b5
commit
fd8e44ef47
18
pom.xml
18
pom.xml
@ -101,6 +101,7 @@
|
|||||||
<include>org.bstats:bstats-bukkit</include>
|
<include>org.bstats:bstats-bukkit</include>
|
||||||
<include>org.spongepowered:configurate-yaml</include>
|
<include>org.spongepowered:configurate-yaml</include>
|
||||||
<include>org.spongepowered:configurate-core</include>
|
<include>org.spongepowered:configurate-core</include>
|
||||||
|
<!--<include>com.flowpowered:flow-math</include>-->
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
<relocations>
|
<relocations>
|
||||||
@ -120,6 +121,14 @@
|
|||||||
<pattern>org.bstats</pattern>
|
<pattern>org.bstats</pattern>
|
||||||
<shadedPattern>com.gmail.nossr50.metrics.bstat</shadedPattern>
|
<shadedPattern>com.gmail.nossr50.metrics.bstat</shadedPattern>
|
||||||
</relocation>
|
</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>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
@ -145,6 +154,10 @@
|
|||||||
<id>sponge</id>
|
<id>sponge</id>
|
||||||
<url>https://repo.spongepowered.org/maven</url>
|
<url>https://repo.spongepowered.org/maven</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>flow</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
@ -159,6 +172,11 @@
|
|||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!--<dependency>
|
||||||
|
<groupId>com.flowpowered</groupId>
|
||||||
|
<artifactId>flow-math</artifactId>
|
||||||
|
<version>1.0.4-SNAPSHOT</version>
|
||||||
|
</dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spongepowered</groupId>
|
<groupId>org.spongepowered</groupId>
|
||||||
<!-- Modify this line to target the loader you wish to use. -->
|
<!-- Modify this line to target the loader you wish to use. -->
|
||||||
|
@ -35,7 +35,7 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
|
|||||||
|
|
||||||
/* ROOT NODES */
|
/* ROOT NODES */
|
||||||
|
|
||||||
private ConfigurationNode rootNode = null;
|
private ConfigurationNode userRootNode = null;
|
||||||
private ConfigurationNode defaultRootNode = null;
|
private ConfigurationNode defaultRootNode = null;
|
||||||
|
|
||||||
//TODO: Needed?
|
//TODO: Needed?
|
||||||
@ -91,7 +91,7 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
|
|||||||
defaultRootNode = defaultConfig;
|
defaultRootNode = defaultConfig;
|
||||||
|
|
||||||
final ConfigurationNode userConfig = this.userCopyLoader.load();
|
final ConfigurationNode userConfig = this.userCopyLoader.load();
|
||||||
rootNode = userConfig;
|
userRootNode = userConfig;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -214,7 +214,7 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
|
|||||||
public void readConfig() {
|
public void readConfig() {
|
||||||
mcMMO.p.getLogger().info("Attempting to read " + FILE_RELATIVE_PATH + ".");
|
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);
|
mcMMO.p.getLogger().info(FILE_RELATIVE_PATH + " version is " + version);
|
||||||
|
|
||||||
//Update our config
|
//Update our config
|
||||||
@ -226,18 +226,31 @@ public abstract class ConfigLoaderConfigurable implements DefaultKeys {
|
|||||||
*/
|
*/
|
||||||
private void updateConfig()
|
private void updateConfig()
|
||||||
{
|
{
|
||||||
boolean addedValues = false;
|
|
||||||
|
|
||||||
mcMMO.p.getLogger().info(defaultRootNode.getChildrenMap().size() +" items in default children map");
|
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)
|
// Merge Values from default
|
||||||
{
|
userRootNode = userRootNode.mergeValuesFrom(defaultRootNode);
|
||||||
System.out.println("[mcMMO INFO] New config options were added, edit "+FILE_RELATIVE_PATH+" to customize!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update config version
|
// Update config version
|
||||||
updateConfigVersion();
|
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() {
|
private void updateConfigVersion() {
|
||||||
// Set a version for our config
|
// 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);
|
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
|
* Returns the root node of this config
|
||||||
* @return the root node of this config
|
* @return the root node of this config
|
||||||
*/
|
*/
|
||||||
protected ConfigurationNode getRootNode() {
|
protected ConfigurationNode getUserRootNode() {
|
||||||
return rootNode;
|
return userRootNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user