Profession Plugin - Storing Data

Discussion in 'Plugin Development' started by Rhisereld, Jan 9, 2015.

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

    Rhisereld

    This is more general advice than anything, I am hoping some more experienced plugin writers can give me some tips. I want to write a custom professions/skills plugin for a server of mine. However, I have never made anything of this scale before.

    Previously, I have used configuration files to keep track of data while the plugin was running. As soon as I got a piece of information I would write it to the configuration file and when I needed it I would retrieve it again. My concern is that I have no idea how resource-intensive this constant writing and reading is. Would writing a larger scale plugin in this manner cause lag? Is there a more efficient way to do it?

    Should I, perhaps, store my data in objects and only store it more permanently in a configuration file when onDisable() is called? Would this cause problems if the plugin was unexpectedly stopped? Would it cause lag by attempting to write all these things at once?

    Please offer your thoughts.
     
  2. Online

    timtower Moderator Moderator

    @Rhisereld Store the data in objects, maybe load on player join and save on disconnect. It could cause issues when the plugin is unexpectedly stopped, but in my opinion: not something that happens a lot.
     
  3. Offline

    sn1cko

    you can save the data in ArrayLists or HashMaps and on player quit you save it to an extern config file :)

    @timtower didn't know what you meant by objects but if you talked about arrays and maps i am sorry
     
  4. Online

    timtower Moderator Moderator

    @sn1cko More lists of hashmaps that contain special storage classes and are indexed with UUID's.
     
    sn1cko likes this.
  5. Offline

    sn1cko

    i see... understand :)
     
  6. Offline

    Dragonphase

    There are many ways you can do this. For custom professions, you could write your own Player Profile class which contains information relating to the player, such as:
    • Statistics
    • Profession details
    • Skills
    By professions, I assume you mean something similar to professions that you would see in an MMORPG, such as farming, tailoring, etc. If this is what you mean, you could create a Profession interface or abstract class which identifies how the profession will work.

    You could do something similar for skills, and perhaps use a custom Listener for each skill, which handles events such as PlayerInteractEvent (right click to cast a fireball, for example.)

    You could save and load data onEnable and onDisable. While the plugin is running, any data being created will only be saved once the plugin is disabled.

    As @timtower stated, sudden unexpected server shutdowns are rare. In my own experience, I've only seen this happen on servers with an extensive amount of plugins that use bad coding practices, are set up poorly, etc.

    I would however advise you to use some sort of automatic saving protocol, which would save data every 30 minutes or so, for example. This way, if your server does unexpectedly shut down, data would only be rolled back to the last 30 minutes. The time between automatic saving would depend on the importance of your data; if you want there to be less user problems when something like this happens (for example, Player X just spent 30 minutes grinding for a lot of skill experience, but all his work got rolled back, and he is very annoyed), you could automatically save every 5-10 minutes. Or, you could compensate for the user problems yourself, but there's no way to tell if they are being truthful about how much they earned.
     
  7. Offline

    PreFiXAUT

    @Rhisereld Well, for that Problem I wrote my own List: https://github.com/prefixaut/PreDB

    You basicly create your Object which contains all Data you need, and implement a Interface. Then you create a DBList and store your Object into it. That's it. Then use yourList.load() to load the List, and yourList.save() to save it.

    It's especially made for this purpose (Saving & Loading Objects) so you only work with Objects instead to work with IO-Stuff. I'm gonna update it soon (Adding a DBMap - Basicly like DBList, just as Map) and adding JSON Features to them (Loading & Saving from/to JSON-Format).
     
  8. Offline

    Rhisereld

    Thanks for all your advice, I think I have a good idea of how to go about this now!
     
Thread Status:
Not open for further replies.

Share This Page