mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
new config system pt 2
This commit is contained in:
parent
69fa10559c
commit
0f743a55b5
5
src/main/java/com/gmail/nossr50/DefaultKeys.java
Normal file
5
src/main/java/com/gmail/nossr50/DefaultKeys.java
Normal file
@ -0,0 +1,5 @@
|
||||
package com.gmail.nossr50;
|
||||
|
||||
public interface DefaultKeys {
|
||||
boolean validateKeys();
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.config;
|
||||
|
||||
import com.gmail.nossr50.DefaultKeys;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.google.common.io.Files;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
@ -9,13 +10,12 @@ import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handles loading and cacheing configuration settings from a configurable compatible config file
|
||||
*/
|
||||
@ConfigSerializable
|
||||
public abstract class ConfigLoaderConfigurable {
|
||||
public abstract class ConfigLoaderConfigurable implements DefaultKeys {
|
||||
|
||||
/* PATH VARS */
|
||||
|
||||
@ -65,6 +65,8 @@ public abstract class ConfigLoaderConfigurable {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
validateKeys(); // Validate Keys
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,10 +217,8 @@ public abstract class ConfigLoaderConfigurable {
|
||||
int version = this.rootNode.getNode("ConfigVersion").getInt();
|
||||
mcMMO.p.getLogger().info(FILE_RELATIVE_PATH + " version is " + version);
|
||||
|
||||
//Update our config
|
||||
updateConfig();
|
||||
|
||||
//Update config version
|
||||
updateConfigVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,10 +226,18 @@ public abstract class ConfigLoaderConfigurable {
|
||||
*/
|
||||
private void updateConfig()
|
||||
{
|
||||
for(Object key : defaultRootNode.getChildrenMap().keySet())
|
||||
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");
|
||||
|
||||
if(addedValues)
|
||||
{
|
||||
|
||||
System.out.println("[mcMMO INFO] New config options were added, edit "+FILE_RELATIVE_PATH+" to customize!");
|
||||
}
|
||||
|
||||
// Update config version
|
||||
updateConfigVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,15 +245,15 @@ public abstract class ConfigLoaderConfigurable {
|
||||
*/
|
||||
private void updateConfigVersion() {
|
||||
// Set a version for our config
|
||||
/*this.rootNode.getNode("ConfigVersion").setValue(getConfigVersion());
|
||||
mcMMO.p.getLogger().info("Updated config to ["+getConfigVersion()+"] - " + FILE_RELATIVE_PATH);*/
|
||||
this.rootNode.getNode("ConfigVersion").setValue(getConfigVersion());
|
||||
mcMMO.p.getLogger().info("Updated config to ["+getConfigVersion()+"] - " + FILE_RELATIVE_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root node of this config
|
||||
* @return the root node of this config
|
||||
*/
|
||||
public ConfigurationNode getRootNode() {
|
||||
protected ConfigurationNode getRootNode() {
|
||||
return rootNode;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ public class ConfigurableTest extends ConfigLoaderConfigurable {
|
||||
public final static String relativePath = "configurabletest.yml";
|
||||
private static ConfigurableTest instance;
|
||||
|
||||
|
||||
|
||||
public ConfigurableTest() {
|
||||
super(mcMMO.p.getDataFolder(), relativePath);
|
||||
}
|
||||
@ -18,4 +20,8 @@ public class ConfigurableTest extends ConfigLoaderConfigurable {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateKeys() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
# The writing is on the wall!
|
||||
TheBidoofNotation:
|
||||
MudkipSquareRoot: 7
|
||||
CharmanderDivisor: 2
|
||||
CharmanderDivisor: 2
|
||||
# Woof!
|
||||
Woof:
|
||||
Bark:
|
||||
Meow: "Reeeee"
|
||||
Bone: 8.3827
|
Loading…
Reference in New Issue
Block a user