Issue saving data onDisable (arraylists erased)

Discussion in 'Plugin Development' started by i3ick, Sep 9, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    i3ick

    Hi
    I'm trying to write some data right before I disable my plugin. This is the code I'm using
    Code:
        /** Update user data in playerData.yml
         *
         */
        public void updateUserData(){
            plugin.getLogger().info("1");
            FileConfiguration playerData = plugin.getPlayerData();
            plugin.getLogger().info(this.playerNameList +"");
    
            for(String pl : this.playerNameList) {
                plugin.getLogger().info("2");
                Player player = Bukkit.getPlayer(pl);
                String path = "Stats." + player.getName() + ".";
                int level = this.getPlayerInfo(player).getLevel();
                int points = this.getPlayerInfo(player).getPoints();
    
                playerData.set(path + "level", level);
                playerData.set(path + "points", points);
    
            }
            plugin.getLogger().info("3");
    
            File f = new File(plugin.getDataFolder() + File.separator + "playerData.yml");
            try {
                playerData.save(f);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    The problem seems to be that the arraylist is erased before I manage to loop through it to save.
    I ran updateUserData(); onEnable (returned 1 2 3) and onDisable (returned 1 3).

    Any suggestions on how to get around this? Or am I doing something wrong?
     
  2. @i3ick i have a guess why this is not working for you, but i would need to see the whole code for that.

    im guessing that you are working on different objects which is why one array always stays empty. also you should use UUID instead of playernames.
     
  3. Offline

    caderape

    @i3ick
    File f = new File(plugin.getDataFolder() + File.separator + "playerData.yml");

    Is that work to call the file after you set value ?
     
Thread Status:
Not open for further replies.

Share This Page