player config not updating when setting value

Discussion in 'Spigot Plugin Development' started by ieatdiamond, Jul 14, 2018.

Thread Status:
Not open for further replies.
  1. Code (Text):
        @EventHandler
        public void increaseKills(EntityDeathEvent e) {
            Player p = null;
            if (e.getEntity().getKiller() instanceof Player) {
                p = e.getEntity().getKiller();
            } else {
                return;
            }
           
            if (!killCount.containsKey(p)) {
                killCount.put(p, getUserConfig(p).getInt("sword_upgrade_kills"));
            }
           
            int currentKc = killCount.get(p);
            getUserConfig(p).set("sword_upgrade_kills", currentKc + 1);
            save(p);
            System.out.println("you're at " + currentKc);
        }
    Code (Text):
        public void save(Player p) {
            try {
                getUserConfig(p).save(getPlayerFile(p));
                System.out.println("SAVED");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
       
        public File getPlayerFile(Player player) {
            if (playerFile == null) {
                playerFile = new File(plugin.getDataFolder()+File.separator+"/userdata/"+player.getUniqueId()+"/" + player.getUniqueId()+".yml");
            }
            return playerFile;
        }
       
        public YamlConfiguration getUserConfig(Player player) {
            return playerYaml = YamlConfiguration.loadConfiguration(getPlayerFile(player));
        }
    im confused it returns the value correctly but setting it doesnt seem to work event after i've saved it
     
Thread Status:
Not open for further replies.