Skyoconfig - Create configurations with ease !

Discussion in 'Resources' started by Skyost, May 23, 2014.

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

    Skyost

    [​IMG]
    What is it ?
    Skyoconfig is a class used to simplify the creation and the management of plugins' configurations.​
    How to use ?
    First, you have to download the class here.​
    Then, create a new class named "PluginConfig" which extends Skyoconfig, It will be our configuration's class.​
    For the moment copy-paste the following code (do not worry, you will understand) :​
    Code:java
    1. public class PluginConfig extends Skyoconfig {
    2.  
    3. @ConfigOptions(name = "configurable.string.1")
    4. public String configurableString = "This String is configurable like others fields below ;)";
    5. @ConfigOptions(name = "configurable.int.1")
    6. public int configurableInt1 = 1;
    7. @ConfigOptions(name = "configurable.int.2")
    8. public int configurableInt2 = 0;
    9. @ConfigOptions(name = "configurable.list.1")
    10. public List<String> configurableList = Arrays.asList("YAML list...", "So awesome !");
    11. @ConfigOptions(name = "configurable.map.1")
    12. public HashMap<String, String> configurableMap = new HashMap<String, String>() {
    13. private static final long serialVersionUID = 1L; {
    14. put("key1", "value1");
    15. put("key2", "value2");
    16. }
    17. };
    18.  
    19. public String configurable_string_2 = "This one does not needs the annotation but the field's name looks so bad !";
    20.  
    21. public PluginConfig(final File configFile) {
    22. super(configFile, Arrays.asList("This is an header...", "...Which looks more than one line !"));
    23. }
    24.  
    25. }

    This is how looks a configuration class, now we have to create the plugin :​
    Code:java
    1. public class AwesomePlugin extends JavaPlugin {
    2.  
    3. private PluginConfig config; //Can be static too !
    4.  
    5. @Override
    6. public final void onEnable() {
    7. final Logger logger = getLogger();
    8. try {
    9. config = new PluginConfig(new File(this.getDataFolder(), "config.yml"));
    10. config.load(); //Load the config.
    11. logger.log(Level.INFO, "Voici le champ \"configurableString\" : \"" + config.configurableString + "\".");
    12. }
    13. catch(final InvalidConfigurationException ex) {
    14. ex.printStackTrace();
    15. logger.log(Level.SEVERE, "Oooops ! Something went wrong while loading the configuration !");
    16. Bukkit.getPluginManager().disablePlugin(this);
    17. }
    18. }
    19.  
    20. @Override
    21. public final void onDisable() {
    22. try {
    23. config.save(); //Save the config.
    24. }
    25. catch(final InvalidConfigurationException ex) {
    26. ex.printStackTrace();
    27. getLogger().log(Level.SEVERE, "Oooops ! Something went wrong while saving the configuration !");
    28. }
    29. }
    30.  
    31. }

    Okay, now, export your plugin, place it into your "plugins" folder and start your server.​
    Open the configuration file (usually .../plugins/NameOfYourPlugin/config.yml) and you will see something like that :​
    [​IMG]
    Finished ! You have created your configuration in an easy way ;)
    If you have any question or bug report, feel free to post it here.​
     
  2. Offline

    sheeprgrate

    hi can you pleas help me with my config this is my first time making a config.yml
     
  3. Offline

    Skyost

  4. Offline

    Phasesaber

    saveConfig();
     
  5. Offline

    Skyost

  6. Offline

    Phasesaber

    BOGUS! And do you have configs in other folders? Like, I have a plugin that I'm working on right now that has the plugin folder in the same directory as the plugins folder & bukkit.jar. It's really neat.
     
  7. Offline

    Skyost

    Phasesaber That's not false, you do not have to call saveConfig() with Skyoconfig.
    And yes, because you choose the folder ;)
     
    Phasesaber likes this.
  8. Offline

    lenis0012

    Very nice Skyost
    Really improves your code.
     
    Skyost and Phasesaber like this.
  9. Offline

    Phasesaber

    I see! I love that!
     
    Skyost likes this.
  10. Offline

    Skyost

    ARCT3CK likes this.
  11. Offline

    ARCT3CK

    So, how do you access the config? (noobish question, new with bukkit yaml config system xD)

    edit: Also thanks for the manager class! great work man
     
  12. Offline

    Skyost

    ARCT3CK Create a config variable. I have included an example on Github ;)
     
    ARCT3CK likes this.
  13. Offline

    ARCT3CK

    private PluginConfig config; :D
    Sorry i didn't read that variable
    Thanks for the resource! :D
    A cake for you [cake]
     
    Skyost likes this.
  14. Offline

    Skyost

  15. Offline

    ARCT3CK

    Only one question, i need to write some coords on the config

    I'm trying to do something like this ยป
    Code:java
    1. getConfig().set("Location.x", p.getLocation().getX());

    Can i do this with Skyoconfig? using your v.0.6 version :D

    Thanks
     
  16. Offline

    Skyost

    ARCT3CK Yes, you put a Location in the config's class ;)
     
  17. Offline

    ARCT3CK

    Haha this has made my plugin config creation a lot easier, this resource should be on Sticky :D
     
    Skyost likes this.
Thread Status:
Not open for further replies.

Share This Page