Solved Large scale plugin help with structuring

Discussion in 'Plugin Development' started by Scullyking, Apr 8, 2015.

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

    Scullyking

    In my plugin every player has a Profile object. The Profile holds all of that players stats that relate to the plugin, such as cooldowns, abilities, skill levels, etc.

    I have a singleton class called ProfileManager that contains a HashMap (called OnlinePlayers) with player UUIDs as the key, and the players Profile object as the value.

    When a player joins, their Profile object is built from their player_data.yml file and added to OnlinePlayers.
    Same goes for a player leaving, their Profile object is saved to their player_data.yml file and removed from OnlinePlayers.

    Example: To add 100 xp to a players Woodcutting level, I have to write this.
    Code:
    ProfileManager.getInstance().getPlayerProfile(player).addXP(Skill.WOODCUTTING, 100);
    The question: Is this a good way of doing things? It seems efficient but I want to check before I get too deep in things. At the moment I'm not interacting with player profiles, I've only just set up the framework.

    Also, I want as much advice about creating large plugins as possible. What's something I should know now that I'm starting out?

    Any of you who have worked on large scale plugins please pitch in, thank-you! :)
     
    Last edited: Apr 8, 2015
  2. Offline

    Gater12

    @Scullyking
    Are you planning to put this on a large network?
     
  3. This seems good. With me it's, if it works it's good. The only other solutions would be making for every player stat a HashMap with the uuid.
     
  4. Offline

    Scullyking

    @Gater12
    Possibly, in the distant future. I am a one-man team at the moment.

    I think a HashMap for each stat would get out of hand very quickly, it also doesn't seem too scalable. Thanks for the feedback.
     
    Last edited by a moderator: Apr 8, 2015
  5. Offline

    1Rogue

    This would be worse than the current solutions

    Your solution is fine, but you might want to add thread safety if you want to access stuff asynchronously
     
  6. Offline

    Scullyking

    @1Rogue
    Thread safety? Not entirely confident on threading, I don't think I'm doing this?
    Also I find it funny how I occasionally (like once a year) bump into you, you made me a mod on MCF way way back! Is there any chance you're an Admin on Hypixel?
     
  7. Offline

    1Rogue

    Yes, I'm a developer for Hypixel.
     
  8. Offline

    RawCode

    Under normal conditions player may be affected only by single thread, there is no reason to waste resources on synchronization that wont have any effect.

    1) There is no reason to use UUID as key, player may not change his name at runtime.
    2) There is no reason to store skill data struct as hashmap, number of skills is defined by enum and have fixed size - simple array will be effective.
     
  9. Offline

    1Rogue

    So what's the reason to store a name instead? Why not store a UUID all the time, instead of arbitralily choosing? Consistency produces less room for error.
     
  10. Offline

    Evaluations

    I'd suggest using a database over files if you plan on having numerous users.
     
  11. Offline

    mythbusterma

    @Evaluations

    I'd suggest not, unless you have tons and tons of data to store.
     
  12. Offline

    Scullyking

    @Evaluations
    This will only be an option if the player base reaches the multiple hundreds, which is unlikely considering how competitive running a minecraft server is!

    @RawCode
    I'm using a HashMap for the skill level and xp because it's nice to use the skill enum as the key. Wouldn't an array be safer but less practical?

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 9, 2015
  13. Offline

    RawCode

    Enum instances are int wrappers, you can get ordinal from enum and use it as array slot directly.
    array[some.enum.instance.ordinal()] = value

    As for name<>uuid, there is no errors possible, debugging and heap\dump reading much more simple in case of Strings.
     
Thread Status:
Not open for further replies.

Share This Page