[1.12.1] Gathering Global Saved Data?

Discussion in 'Spigot Plugin Development' started by Soloem, Sep 14, 2017.

  1. How would one gather all saved data when not knowing what saved data exists? Such as grabbing players UUIDs in a save folder of the plugin to do something similar to /ftop(Factions Top) or /mctop(MCmmo Top).

    For extra information, trying to gather all of the player's total levels and then averaging them.
  2. Well, I might be misunderstanding your question but if it's what I think every time someone joins the server and gets assigned a level or when they level up store that in a ymal file configuration(config file or custom ymal config file.) Then when you want to get all of them loop through all the players that have joined the server and from there it's simple math of adding all the levels and dividing them by the total number of players. If you want to exclude inactive players then also store there last join time and check that before adding there level to the average. Also, if you are new to java just so you know if you divide 2 integers it always rounds up(I think or its down.) so you have to convert them to doubles or floats when you divide.
  3. So make another YML file to store the Player's levels by default and then loop through that file? I'm also trying to get Offline Players as well into the average.
  4. Maybe when a player joins, check if you have his data .yml file, if not then make one for them otherwise load it..
    Store it in a folder in your plugin's folder that would be called userdata or something like that, the file could be called hisuuid.yml and in that file you will store data what you want, then you can get all files in directory and go through them as you want..
  5. if your going to be able to configure it, use .yml, else just for storing json/gson is much easier and faster
    Code (Text):

      File dir = new File(myDirectoryPath);
      File[] directoryListing = dir.listFiles();
    gets all files from the directory. just loop through
  6. Why not give each player file a specific name and then you can just get the player's file without looping because you already know what its name is when you know the uuid of the player.
  7. I don't know if you're suggesting making a separate file from the player's default save(plugin save of course) and going from there. I thought of a similar solution where I make a file with every single player's level and saving it to that file on shutdown and loading it on start-up, and adjusting it through maps. The only major problem I have with this is the possibility of losing a player's level within said file even though their data is directly loaded from that file, as well as how large the file may be.

    I'll probably give this a shot as I wasn't actually aware of looping at all. Not sure if efficient, but might be a probable way.

    The problem is I don't know the player's UUID or anything about the player, unless they are online or I directly look into the player's folder to find out and hardcode that in. I have to make absolutely zero assumptions about whether a player exists or not.
  8. How do you want to save the statistics of a player then? How do you want to identify the player? You know you can request the uuid of a player based on their name, don't you?
    • Optimistic Optimistic x 1
  9. dont think thats what was the question asked... @Jalau fyi.
  10. Oh sorry. I totally misread that.
    • Optimistic Optimistic x 1

Share This Page