custom config not saving :\ main class Code (Java): public YamlConfiguration getNameTagConfig(){ nameConfig = new YamlConfiguration(); File f = new File(getDataFolder(), "nametags.yml"); if(!f.exists()){ try { f.createNewFile(); nameConfig.addDefault("default.prefix", "prefix "); nameConfig.addDefault("default.suffix", " suffix"); nameConfig.addDefault("default-rank", "default"); nameConfig.load(f); nameConfig.options().copyDefaults(true); } catch (Exception e) { e.printStackTrace(); } } try { nameConfig.save(f); } catch (Exception e) { e.printStackTrace(); } return nameConfig; } public void saveNameTagConfig(){ try { nameConfig.save(new File(getDataFolder(), "nametags.yml")); } catch (IOException e) { e.printStackTrace(); } } join class Code (Java): if(Main.get().getNameTagConfig().getString(event.getPlayer().getUniqueId() +".Group") == null){ Main.get().getNameTagConfig().set(event.getPlayer().getUniqueId() +".Group", Main.get().getNameTagConfig().get("default-rank")); Main.get().saveNameTagConfig(); } it does not save in the main class or the join class.
Because You loaded the config before saving " nameConfig.load(f); " also put the copy Default to the top and not at the end.
You never set nameConfig to a file Instead at the top of your code you need to change the order Current: Code (Java): public YamlConfiguration getNameTagConfig(){ nameConfig = new YamlConfiguration(); File f = new File(getDataFolder(), "nametags.yml"); if(!f.exists()){ make it Code (Java): public YamlConfiguration getNameTagConfig(){ File f = new File(getDataFolder(), "nametags.yml"); nameConfig = YamlConfiguration.loadConfiguration(f);
I always had that issue too, no idea why, so I just wrote a method in the custom file class Code (Java): public void set(String path, Object obj){ config.set(path, object); try{ config.save(file); } catch (Exception e) { e.printStackTrace(); } } On phone pls no hate for spacings