[Resource] The Easiest/Simplest way to handle multiple config files

Discussion in 'Resources' started by Goblom, Nov 12, 2013.

?

Did you find out that after using this class that managing multiple config files is much easier?

  1. Yes

    57.1%
  2. No

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

    Goblom

    Most tutorials or resources about managing config files are either vague or do not cover enough information to provide any actual simple way to handle multiple configurations.

    I set out to change the curve and provide a new line for other people to follow and that is how i came up with this. It is a single class file that can hold an seemingly unlimited amount of FileConfiguration, it can save any file, load any file (That is compatible with YamlConfiguration) and also reload any File.

    Source: https://github.com/Goblom/Bukkit-Li...g/goblom/bukkitlibs/config/ConfigManager.java

    The entire class file is documented but if you have any question or found a bug please tell and if you did find a bug you may also submit a pull request ;)

    How to use
    To Load a config file
    Code:java
    1. ConfigManager.load(myPlugin, "mySpecialConfig.yml");

    To get a Configuration (FileConfiguration)
    Code:java
    1. ConfigManager.get("mySpecialConfig.yml")

    To Reload a configuration
    Code:java
    1. ConfigManager.reload(myPlugin, "mySpecialConfig.yml");

    To save a config file
    Code:java
    1. ConfigManager.save(myPlugin, "mySpecialConfig.yml");


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  2. Offline

    Ultimate_n00b

    Wouldn't you put the .yml file name inside of quotes? And, why include the .yml if all it does is handle these files?
     
  3. Offline

    Goblom

    Ultimate_n00b Fixed the quotes, thanks for pointing that out :)

    It handles the entire file including the name. It seemed simpler to do so at the time of creation to do it this way.
    Also because getConfig() returns the FileConfiguration for config.yml. So i just seemed natural to use the entire file name

    (I know that paragraph might have been a little redundant)
     
  4. Offline

    jacklin213

    seems sweet +1
     
    Goblom likes this.
  5. Offline

    LCastr0

    what do I use in "myPlugin"? D:

    Should I do like
    Code:java
    1. public main plugin;

    and then
    Code:java
    1. Messages.load(plugin, "messages.yml");
    ?
     
  6. Offline

    Sarrabiscos

    Yes, the "myPlugin" variable is a JavaPlugin variable, in other words, your main class

    Goblom this resource was very helpfull :D
     
    Goblom likes this.
  7. Offline

    FuZioN720

    Goblom I'm getting an error on the loading of the plugin
    error:
    Code:
    [19:02:19 INFO]: xXFuZioN360Xx issued server command: /tw g medic
    [19:02:19 WARN]: java.lang.NullPointerException
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.ConfigManager.load(ConfigM
    anager.java:33)
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.classes.Medic.giveHelmet(M
    edic.java:59)
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.classes.Medic.giveMedic(Me
    dic.java:39)
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.cmds.Give.onCommand(Give.j
    ava:34)
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.CommandManager.onCommand(C
    ommandManager.java:54)
    [19:02:19 WARN]:        at org.bukkit.command.PluginCommand.execute(PluginComman
    d.java:44)
    [19:02:19 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:196)
    [19:02:19 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:542)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.PlayerConnection.handleC
    ommand(PlayerConnection.java:932)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.PlayerConnection.a(Playe
    rConnection.java:814)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(Packe
    tPlayInChat.java:28)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(
    PacketPlayInChat.java:47)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.NetworkManager.a(Network
    Manager.java:146)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.ServerConnection.c(Sourc
    eFile:134)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.u(Minecr
    aftServer.java:655)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.u(Dedica
    tedServer.java:250)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.t(Minecr
    aftServer.java:545)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.run(Mine
    craftServer.java:457)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.ThreadServerApplication.
    run(SourceFile:617)
    line 33 is:
    Code:java
    1. File file = new File(plugin.getDataFolder(), fileName);
     
  8. Offline

    Goblom

  9. Offline

    FuZioN720

    Goblom I figured out what was wrong. It wasn't getting the plugin right
     
  10. Offline

    JoeyDevs

    Edit: Problem moved!
     
  11. Offline

    Squid_Boss

    I use another way to handle multiple configurations. Seems to me it's a lot simpler than this. I can't remember the person who came up with it, but he did name it "ConfigAccessor" and it is easier to create and edit configs. With yours, every time you want to edit the Configuration you have to include the file name, whereas in the one I use, you just create a ConfigAccessor object, set the object's filename in the Enable, and then you can use the object name to edit the config. So, if I made one called "test" to edit all I'd have to do is use test.getConfig().etc
     
  12. Offline

    Goblom

    If you do not like having to use the file name every time you can create simple method to do it for you...

    Code:java
    1. public FileConfiguration getSpecialConfig() {
    2. return ConfigManager.get("mySpecialConfig.yml");
    3. }
     
  13. Offline

    Squid_Boss

    Code:java
    1.  
    2.  
    3. It just seems like a lot of unnecessary work, and a bit off that you call yours the easiest / simplest which isn't necessarily true.
     
  14. Offline

    StaticJava

    Looks like the source code is gone...and updated links?
     
  15. Offline

    Goblom

    StaticJava likes this.
  16. Offline

    StaticJava

  17. Offline

    essem2

    I get the following error:

    Code:
    [20:33:52] [Server thread/WARN]: java.lang.IllegalArgumentException: The embedded resource '9905dd85-5816-4e6c-9ced-a985c7d9b0de.yml' cannot be found in plugins/LobbyMain.jar
    [20:33:52] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPlugin.saveResource(JavaPlugin.java:252)
    [20:33:52] [Server thread/WARN]:     at de.essem2.lobby.libs.ConfigManager.load(ConfigManager.java:68)
    [20:33:52] [Server thread/WARN]:     at de.essem2.lobby.JoinEvent.OnJoin(JoinEvent.java:32)
    [20:33:52] [Server thread/WARN]:     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [20:33:52] [Server thread/WARN]:     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [20:33:52] [Server thread/WARN]:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [20:33:52] [Server thread/WARN]:     at java.lang.reflect.Method.invoke(Method.java:497)
    [20:33:52] [Server thread/WARN]:     at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306)
    [20:33:52] [Server thread/WARN]:     at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    [20:33:52] [Server thread/WARN]:     at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502)
    [20:33:52] [Server thread/WARN]:     at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:298)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:157)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:144)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:54)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:231)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.ServerConnection.c(ServerConnection.java:148)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:813)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653)
    [20:33:52] [Server thread/WARN]:     at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556)
    [20:33:52] [Server thread/WARN]:     at java.lang.Thread.run(Thread.java:745)
    
    my line 32: ConfigManager.load(p.getUniqueId()+".yml");

    ps: i like your configmanager :3
     
    Last edited: Jul 26, 2015
  18. Offline

    Goblom

    @essem2 The ConfigManager is trying to load the yaml file from the plugins jar. going into Configmanagers "load" method and change "PLUGIN.saveResource" to "file.createNewFile()"
     
Thread Status:
Not open for further replies.

Share This Page