Solved How to store player data in objects?

Discussion in 'Spigot Plugin Development' started by broforcez, Jun 18, 2021.

  1. Hello everyone !

    I have got a question about method of storing and retrieving player data.
    Lets say that I have different jobs/proffesions/skills (12 of them), each one has to store just few integers like exp, lvl, etc. I want to get those integers for specific profession and update them each time a player is doing something. (For example blockbreakevent updates exp in excavation skill)
    What is the best method, performance wise and speed wise, to do this ?

    I thought about:
    - creating one large object that will store all player data, with all professions, all getters and setters for ints. Then map that object to player.

    -create multiple small objects, one for each profession, and mapping those objects to one key player somehow (maybe mapping array of objects or using external libs to do this)

    I have no problem creating and saving those objects, I'm just worried about performance and speed when I plop all player data into one object.

    Thank you in advance for all replies.
     
  2. Personally, I would create an abstract class maybe called `Job` or `Profession` and then all other jobs/professions would extend that class. In there you could group common functions that all jobs need to access or modify.

    You could then have a enum with each job, something like `JobTypes`. Then, store these in a map, something like.
    Code (Text):

    final Map<Player, Map<JobType, AbstractJob>> map = new HashMap<>();

    // get my job.
    final SomeJob job = (SomeJob) map.get(player).get(JobType.SOME_JOB);
     
    I'd just play around with this basic concept, could probably be improved.
     
    • Like Like x 1