Storing player data

Discussion in 'Plugin Development' started by Permeer, Sep 13, 2015.

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


    So, what would be the "best way" to save individual player data?

    1. When the server start up load all the data from a unique YAML file with all players data and save it in a HashMap and when the data is updated save it in the hashmap and when the server stops save it in the YAML file or

    2. Each player have a individual file that are created when the player join in the server and is all the data is saved in a HashMap and when the player left the server all the data is saved in the player YAML and removed from the HashMap

    Sorry for my english
  2. Offline


    could you show us what you already have? @Permeer
  3. Offline


    I'm not very good in storing data, but shouldn't he have hashmap, then create an event onplayerjoin, then somehow call the hashmap on join?
    Again, I'm not gold at this but that's what I might assume.
  4. Offline


    One thing to keep in mind is if you store it in one file, it'll be harder to find a player's data, after a while. Using multiple files let's you easily find that file and look at it.
  5. Offline


    @Googlelover1234 Yeah , i know, but if i store it in one file the file will be loaded/used only when the server start up and will load every player data thats saved

    @SkyleTyler1337 Thats what i have, its simple but works
    and works like that

    - Player join, loads from YAML and save data in a hashmap
    - Player quit, save data in the YAML and remove from the hashmap

        public void PlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            UUID uuid = p.getUniqueId();
            int kill= 0;
            int death = 0;
            int killstreak = 0;
            int money = 0;
            if (Config.existPlayerFile(uuid)) {
                Config playerfile = Config.getPlayerFile(uuid);
                kill = playerfile.getInteger("kill");
                death = playerfile.getInteger("death");
                killstreak = playerfile.getInteger("killstreak");
                money = playerfile.getInteger("money");
            Main.Main_().kill.put(uuid, kill);
            Main.Main_().death.put(uuid, death);
            Main.Main_().killstreak.put(uuid, killstreak);
            Main.Main_().money.put(uuid, money);
        public void PlayerQuit(PlayerQuitEvent e){
            Player p = e.getPlayer();
            UUID uuid = p.getUniqueId();
            int kill = Main.Main_().kill.get(uuid);
            int death = Main.Main_().death.get(uuid);
            int killstreak = Main.Main_().killstreak.get(uuid);
            int money = Main.Main_().money.get(uuid);
            Config playerfile = Config.getPlayerFile(uuid);
            boolean kbol = true;
            boolean dbol = true;
            boolean ksbol = true;
            boolean mbol = true;
            if(playerfile.contains("kill") && playerfile.getInteger("kill") == kill)
                kbol = false;
            if(playerfile.contains("death") && playerfile.getInteger("death") == kill)
                dbol = false;
            if(playerfile.contains("killstreak") && playerfile.getInteger("killstreak") == kill)
                ksbol = false;
            if(playerfile.contains("money") && playerfile.getInteger("money") == kill)
                mbol = false;
            playerfile.set("kill", kill);
            playerfile.set("death", death);
            playerfile.set("killstreak", killstreak);
            playerfile.set("money", money);
    Double post ;v sorry

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 11, 2016
Thread Status:
Not open for further replies.

Share This Page