Polymart is now Voxel Shop! We're upgrading many features of the site, and during this open beta you will experience occasional bugs. Learn more
Universal library for work with yml configurations
@Getter
public class MessagesConfiguration
extends Configuration
{
public MessagesConfiguration(File folder)
{
super(folder.getAbsolutePath() + File.separator + "messages.yml");
}
@ConfigurationField("Hello-world")
public String helloWorld = "Hello, world!";
}public class Main
extends JavaPlugin
{
/*
* Creating an instance of our configuration class
*/
private MessagesConfiguration messagesConfiguration = new MessagesConfiguration(this.getDataFolder());
@Override
public void onEnable()
{
/*
* This method automatically creates a configuration file
* if it has not already been created. Also, it fills your class
* with values from the configuration, or vice versa fills the
* configuration with values from the class if there are no
* corresponding fields in the configuration.
*
* You can also call this method when you want to reload
* the configuration of your plugin.
*/
this.messagesConfiguration.load();
/*
* After loading the configuration, we can easily get
* the values of our fields from the class.
*/
this.getLogger().info(this.messagesConfiguration.getHelloWorld());
}
@Override
public void onDisable()
{
this.messagesConfiguration = null;
}
}@Getter
public class MessagesConfiguration
extends Configuration
{
public MessagesConfiguration(File folder)
{
super(folder.getAbsolutePath() + File.separator + "messages.yml");
}
@ConfigurationField("Hello-world.With-comment-above")
@ConfigurationComments({"# First comment line", "# Second comment line"})
public String helloWorld = "Hello, world!";
}# First comment line
# Second comment line
Hello-world:
With-comment-above: Hello, world!
