1.13.2 Config Manager Default Values

Discussion in 'Spigot Plugin Development' started by Lysander12, Jan 18, 2020.

  1. Hey, I've been trying to set default values to something I want. The problem is it doens't work and the file remains empty. Here's the code:

    Code (Java):
            ItemsFile.get().addDefault("Healthorb.Value", 20.0);
            ItemsFile.get().addDefault("Rottenchunk.Value", 10.0);
    Code (Java):
    package me.xlysander12.mmorpg.configfiles;

    import me.xlysander12.mmorpg.Main;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;

    import java.io.File;
    import java.io.IOException;

    public class ItemsFile {
        static Main plugin = Main.getPlugin(Main.class);
        static FileConfiguration itemssconfig;
        static File itemsfile;

        public static void setup() {
            itemsfile = new File(plugin.getDataFolder(), "Items.yml");

            if (!itemsfile.exists()) {
                try {
                } catch (IOException e) {

            itemssconfig = YamlConfiguration.loadConfiguration(itemsfile);

        public static FileConfiguration get() {
            return itemssconfig;

        public static void save() {
            try {
            } catch (IOException e) {
                Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save items.yml!");

        public static void reload() {
            itemssconfig = YamlConfiguration.loadConfiguration(itemsfile);
    Thanks in advance
  2. Try to put the copyDefaults part under the setup! You dont must use setDefault(); you can simply use set("path", value);
  3. The second ItemsFile.setup() is useless.
    Call ItemsFile.get().set(String, Object)
    instead of

  4. Yea, that initialize a new config object a d the filled one gets overwridden.
  5. But won't doing ItemsFile.get().set() overwrite everything that was previously in there?
  6. Huh thats true.
    So addDefault should work better in this case.
  7. Yeah but that's what I was doing and didn't work. That's why I'm kinda lost