Resource How to use Player Storage API in your plugins!

Discussion in 'Spigot Plugin Development' started by hidden1nin, Jul 14, 2021.

?

Do you think this is useful?

  1. Yes, I could see myself using it.

    50.0%
  2. No, It needs alot of work.

    16.7%
  3. Yes, but I don't see myself using it.

    33.3%
  4. No, I think someone else might enjoy it though.

    0 vote(s)
    0.0%
  1. Recently I made public my API for quickly adding MongoDB / Redis support to plugins, I am now creating a simple guide to go along with it for developers and users!


    To Begin,
    please download the PlayerStorageAPI plugin from https://www.spigotmc.org/resources/player-storage-api.94229/ and place it inside your plugins folder.​
    [​IMG]

    Start your server,
    Once your server has started a config file will be created and have the following

    Code (Text):
    Redis_Connection: change this!
    Redis_Port: 12345
    Redis_Password: and this too!
    Redis_Data_Expire_After: 86400
    Storage_Configuration: both
    Mongo_DB_Name: PlayerStorageAPI
    Mongo_DB_ConnectionString: Change Me Too!
     
    You can use either Redis or MongoDB to store data, we also support using both with Redis being used as a Cache and using MongoDB for deep storage.

    For Redis Only,
    If you are using only Redis then
    Code (Text):
    Redis_Data_Expire_After: 86400
    will have no effect.
    To change database's

    If you only need to use Redis or MongoDB simply change
    Code (Text):
    Storage_Configuration: both
    to
    Code (Text):
    Storage_Configuration: redis
    or
    Code (Text):
    Storage_Configuration: mongo
    After filling out the config,

    You can restart your server and you will be greeted by some console messages
    [​IMG]
    [​IMG]
    How do I integrate PlayerStorageAPI in my plugins?

    Great question, once you have the plugin installed on the server you will need to add the JAR as a dependency to your plugin, then add it to your plugin.yml as well [​IMG]
    How do I set a value for a player?
    Simply register the value in your on-enable method
    [​IMG]
    Then whenever you need to update or change the value simply use
    [​IMG]

    How can I get the current value from a player?
    If the value is registered then you can use
    [​IMG]
    or similar methods of PlayerStorageAPI to get other datatypes.
    I need to do an action when the player joins, how can I do that?

    Since we do all database operations Async (aside from getting locally cached info) the players data will not have loaded during the PlayerJoinEvent so we created our own event called PlayerDataLoadEvent [​IMG] this event is fired after the players data has finished loading.

    Thank you for reading, I know I've probably made some mistakes or left something out, but I really hope this guide is helpful and will get more people to integrate Mongo or Redis In their plugins.
    If you need help or would like to contact me my discord is Hidden1nin#9457
     
    • Agree Agree x 1
  2. You should add some documentation, and maybe a separate API module for devs to depend on so that it doesn't include all the unnecessary implementation details of the API and plugin.
     
  3. A way to include this inside our plugin instead of having to add your plugin would be ideal. Good job tho!
     
  4. Thanks for the feedback, I'm fairly new to shading and stuff but I'll go ahead and try to make something like that possible!
     
  5. After some thought, and some coding, I will be transferring to an easier to use version for developers. The next version will just be a maven dependency where you no longer have to convince server owners to install another plugin to go along side your plugin. Thanks for everyone's feedback, I will make a post here once I finish writing up the guide for the newer version.
     
    • Friendly Friendly x 1
    • Useful Useful x 1
  6. I have finished converting over to a simple maven dependency, my new page can be found here
    and the github can be found here
     
    • Winner Winner x 1
    • Friendly Friendly x 1