Need Advice Regarding Achievement Storage

Discussion in 'Plugin Development' started by Scizzr, Sep 19, 2013.

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


    So my setup is as follows.
    - StatType (StatType.PLACED_BLOCKS, etc)
    - Achievement (Just some text about the achievement and StatType and value that is needed)
    - Stat (StatType and value)
    - User (player's name, List<Stat>, List<Achievement>)
    - BlockListener (BlockBreakEvent, etc)
    - PlayerListener (PlayerDamageEvent, etc)
    - StatListener (see event below)
    - AchievementListener (see event below)
    - StatEvent (when a Stat changes for a User)
    - AchievementEvent (when a User earns an Achievement)

    When a player does something (breaks a block, for instance), I've got a method inside of User that calls a StatEvent. If the event is not cancelled, it changes the stat in the List for that user (changes the value or adds a new entry if one doesn't exist). That's all working nicely.

    I've got a StatListener hooked into the StatEvent and when a Stat changes, I have it perform a check for whether or not the user should be awarded any Achievements. That's working fine too.

    I've got an AchievementListener hooked into the AchievementEvent and when the User earns an Achievement, I save it to database. (Columns: user_id, achievement_name)

    I've got a database and tables setup, so we've got the ability to store Achievement earns and load them when each User joins.

    The problem I'm having is I would like to be able to keep track of WHEN they earned the Achievement. It's been completely puzzling me for several hours now. I thought about changing the List of Achievement for each User to a HashMap<Achievement, Calendar> but I'm not sure that's the best way to do it (if I ever want to store more information about the user earning the Achievement, such as "When the user earned the Achievement, what time was it? What was their location? How long had they played for at that moment? Etc..." So in order to have this information handy, how can I do this?

    I'll gladly provide more details, but I'm really needing help with this one.


    (sorry for heartless tag)

    Edit: Fixed typos and corrected things here and there.
  2. Offline


    Store the time in milliseconds to a long.
  3. Offline


    What I'm needing help with is actually how to store it (as far as where in what class). I can't really store it in the User class, because there's no link between a List of Achievements and the time they earned it. Achievement is basically a class that says "This Achievement is named X, and requires Y of StatType Z".
Thread Status:
Not open for further replies.

Share This Page