Resource Config Manager class

Discussion in 'Spigot Plugin Development' started by megaphag, May 1, 2020.

  1. Hey guys! While I was working on my plugin for my server I was looking for an easy-to-use and flexible solution to manage multiple configs. Since I couldn't find anything I made my own, and I thought I'm gonna share it if someone might be in the same boat as me.

    Features:
    • Use anywhere (Singleton)
    • Keeps configs loaded
    • PlaceholderAPI support out of the box
    • Uses predefined .yml files
    • Loads config files when used for the first time
    • Reload (not tested yet, would be glad for feedback)
    • Easy to modify to fit your personal needs
    • Getting data from the file creates a placeholder/dummy data if given data is not available

    Note: You can preload the config file by calling "ConfigManager.getInstance().getConfig("<filename>.yml")"

    Usage:
    Don't forget to add a <filename>.yml to the final .jar file! IDEs usually have a way to include premade files in the jar.
    Before usage you need to set this:
    Code (Java):
    ConfigManager.getInstance().setPlugin(this);
    To get a value from a config file (assuming we are using PAPI):
    Code (Java):
    ConfigManager.getInstance().getString(ConfigManager.getInstance().getConfig("<filename>.yml"), "broadcast.join", player)
    Feel free to use it however you want to, but thanking always feels good :giggle:
    https://gist.github.com/vargaszabolcs/a0aaa8874ecf0e1a80f442eccf1ab460

    Have a great day!

    If you have any suggestions, please don't hold them back.
     
    #1 megaphag, May 1, 2020
    Last edited: May 12, 2020
    • Like Like x 1
    • Winner Winner x 1
  2. getStringWithPlaceholders is too long
    It should be renamed getString, and a function that returns the string without placeholders should be getRawString
     
  3. Thank you for the suggestion! You are right, I update it.
     
  4. This looks like a good start.
    I actually had a config utility years ago that I was testing with similar functionality.
    It was mostly something that I was playing around with testing various things and if I recoded it now I would probably do several things differently. I haven't updated it at all and have no real intention of updating it right now, but maybe it will help you improve and add features to your own project. You're welcome to use any of the code in it as well if you want but I would double check that it still works with newer versions. (I think it was made against 1.8.8)
     
  5. Thank you, I will definitely check it out as soon as I have time. So far my plugin doesn't need more functionality, but in the future probably I will use it as inspiration. Will give credit ofc :)