Created
July 13, 2018 07:01
-
-
Save Articdive/73fa1b408d3a6440c29631b2dbbdabdc to your computer and use it in GitHub Desktop.
Maven CommentedConfiguration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import de.articdive.CommentedConfiguration; | |
import de.articdive.config.CommentedConfig; | |
import de.articdive.interfaces.ConfigurationHandler; | |
import java.io.File; | |
// DO NOT INCLUDE THIS IF ARE MAKING A SIMPLE INTEGRATION!!!!! | |
public class CustomConfigurationHandler extends ConfigurationHandler { | |
public CustomConfigurationHandler(CommentedConfiguration main) { | |
super(main); | |
} | |
@Override | |
public CommentedConfig setDefaults(CommentedConfig memoryconfig, File file) { | |
newConfig = new CommentedConfig(file); | |
newConfig.load(); | |
for (EnumNodes root : main.getConfigNodes()) { | |
if (root.getComments().length > 0) { | |
addComment(root.getNode(), root.getComments()); | |
} | |
if (root.getNode().equals(EnumNodes.VERSION.getNode())) { | |
setNewProperty(root.getNode(), "LOL-You can auto-generate stuff you don't need to set this property."); | |
} | |
setNewProperty(root.getNode(), (memoryconfig.get(root.getNode().toLowerCase()) != null) ? memoryconfig.get(root.getNode().toLowerCase()) : root.getDefaultValue()); | |
} | |
return newConfig; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import de.articdive.interfaces.ConfigNodes; | |
public enum ConfigurationNodes implements ConfigNodes { | |
PATH_HEADER("path", "", "# This is a path."), | |
SOME_NODE( | |
"path.to.node", | |
"", | |
"# This is the current version of Something. Please do not edit."); | |
private final String Root; | |
private final String Default; | |
private String[] comments; | |
ConfigurationNodes(String root, String def, String... comments) { | |
this.Root = root; | |
this.Default = def; | |
this.comments = comments; | |
} | |
/** | |
* Retrieves the root for a config option | |
* | |
* @return The root for a config option | |
*/ | |
public String getNode() { | |
return Root; | |
} | |
/** | |
* Retrieves the default value for a config path | |
* | |
* @return The default value for a config path | |
*/ | |
public String getDefaultValue() { | |
return Default; | |
} | |
/** | |
* Retrieves the comment for a config path | |
* | |
* @return The comments for a config path | |
*/ | |
public String[] getComments() { | |
if (comments != null) { | |
return comments; | |
} | |
String[] comments = new String[1]; | |
comments[0] = ""; | |
return comments; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For Simple Integration (no self-generating configs) | |
@Override | |
public void onEnable() { | |
CommentedConfiguration config = new CommentedConfiguration(EnumNodes.class, this.getDataFolder().getPath() + System.getProperty("file.separator") + "config.yml"); | |
} | |
// For Extended Integration (self-generating configs) | |
@Override | |
public void onEnable() { | |
CommentedConfiguration config = new CommentedConfiguration(EnumNodes.class, this.getDataFolder().getPath() + System.getProperty("file.separator") + "config.yml", CustomConfigurationHandler.class); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment