I was trying to reload config.yml
file on command with Bukkit Plugin
, I don't know how to do it.
I searched on google and I found one answer, but when I used it, config.yml
was not generating. Here's my code:
Please help
I was trying to reload config.yml
file on command with Bukkit Plugin
, I don't know how to do it.
I searched on google and I found one answer, but when I used it, config.yml
was not generating. Here's my code:
Please help
First you need to remove the final modifier from your config variables, else this can't refresh from config file.
Then you need a method for reload the config and set the config variables again. An example based on your code:
@Override
public void onEnable() {
loadConfig(this);
}
private final String prefix = ChatColor.AQUA + "[";
private String prefixTrue;
private String prefixFalse;
public void loadConfig(Plugin plugin) {
File file = new File(plugin.getDataFolder().getAbsolutePath() + "/config.yml");
FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
prefixTrue = prefix + cfg.getString("prefix") + "]" + ChatColor.GREEN + " ";
prefixFalse = prefix + cfg.getString("prefix") + "]" + ChatColor.RED + " ";
}
Make sure that you call the method loadConfig
in onEnable
and every time you want to reload the config