Saving player data to a config file.

Discussion in 'Spigot Plugin Development' started by Leeon, Apr 14, 2017.

  1. Hey I used to create plugins a while back but lost interest because I wasn't really going anywhere. I've now decided to come back and make them again but need a little help. I know the spigot community is failry toxic and I'm probably going to get some funny rating from this but I was wondering if I could have some insights on the topic at hand. Saving player data to a config file.

    For example if I wanted to save a players kills so that everytime they type /kills it displays the amount of kills they have. How would I go about the following.

    When a player first logins it puts their UUID into a main config file, where everyone has their uuid in it and whenever they get a kill it increments the number of kills they have inside the config file. And ofcourse the server would automatically save the config file every 5 minutes or something.

    Does anyone know any tutorials or could give me a quick rundown on the easiest way to do this. Thanks Leon.
  2. If you hook into essentials this data is already saved for you. Based on the time since they joined the server.

    Sent from my iPhone using Tapatalk
  3. This is a example.
    Code (Text):

    public void onDeath(PlayerDeathEvent e) {
       Player p = e.getEntity();
       Player k = p.getKiller();
       int amount = config.getInt("Data." + k.getUniqueId().toString() + ".Kills");
       config.set("Data." + k.getUniqueId().toString() + ".Kills", amount + 1);
    And of course you need to check if the config contains the players uuid in the config, but this should get you going!
    #3 ExoticDev, Apr 14, 2017
    Last edited: Apr 14, 2017
    • Like Like x 1
  4. And you need to remember to save the config!
  5. oh yeah, forgot that lol.
    • Like Like x 2