Loading/Storing Player Skills?

Discussion in 'Plugin Development' started by Jeffyboyy, Dec 27, 2017.

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

    Jeffyboyy

    I am writing a plugin where each player would have their own set of skills (let's say about 25 skills). Each one would have their own "level" and "exp", so for example:

    This is the "exp.config" file I have created:

    (player's UUID):
    >Skill1:
    >>level: 1
    >>exp: 1.0
    >Skill2:
    >>level: 1
    >>exp: 1.0
    etcetc

    Now I have two concerns/questions about this approach.

    1. Is there a better way to do this?

    - I thought of doing something like this:
    (player's UUID):
    >level: 1:2:1:4:4:2:4.... (where the #'s are the skill's levels)
    >exp: 1.0:2.3:5.6:2.4....(where the #'s are the skill's experience)

    But I don't think it's dynamic - at all. Like down the road say I wanted to add another skill, I would have to somehow reiterate over all the existing UUID's and add another blank value to the end..

    2. What would be a good (not necessarily the best way) to load this data into memory, and use it?

    - So far all I can come up with is a HashMap that could hold the player's UUID and an array of each of the stats:

    ex: HashMap<UUID, double[]> playerExp ... etc.

    But the problem with this is the double[] array only has "1:2:1:4:4..etc" in it. How would I ever know which stat is which?

    I'm really stuck with how I could restructure this whole mess. Any help/suggestions would be greatly appreciated.
     
  2. Offline

    pookeythekid

    Your first method is probably the best. If you can keep track of it (use comments!), then I might suggest some nested Maps, i.e:
    Code:
    Map<String, Map<String, String>> playerData = new HashMap<>();
    The first String is the UUID, the second String is the skill number/name, and the third one is the information within that skill, formatted something like "level - 1" and "exp - 1".

    You could nest another Map in there instead of breaking apart the level/exp strings, but that might get a little messy. In personal experience, I've used exactly what I just described to you, and it worked just fine for me.

    Good luck with your project!

    (P.S. Anyone know how to do code blocks with Java syntax highlighting? What used to work seems to not work right now.)
     
Thread Status:
Not open for further replies.

Share This Page