build 1317 YamlConfiguration

Discussion in 'Plugin Development' started by calthor, Oct 11, 2011.

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

    calthor

    hi there, i've got a problem with the new configuration system in 1317.
    just updated a few mins ago and ran into a problem using a List<String>...
    with the previous builds i used configuration.getStringList(); but the configuration seemed to be deprecated now, so i changed to yamlconfiguration but only found the method getList();
    when i load a list (containing Strings) with getList() method i get a null object for some reason.
    does anyone here know how to solve this?
     
  2. Offline

    thehutch

    Join the queue :p most people who arent Java experts and don't know Java off of the back of their hands don't understand it, like me :p
     
  3. It works perfectly fine for me, you're probably doing something wrong. Could you post your source code?
     
  4. Offline

    LartTyler

    Your best bet would be to do this:
    Code:
    @SuppressWarnings("unchecked")
    List<String> vals = (List<String>)config.getList("path.to.vals", null);
    I had the same problem, and that was the only way that I knew of that could solve it. Works fine for me. Just cast the List to List<String> (or whatever other type you wanted it to return, I know ArrayList would work as well) and go. The SupressWarnings but will just stop compilers from complaining that you didn't check the List before casting it.
     
  5. Offline

    tanaka141

    This is not really friendly to modify something without explaining how the new system work...
     
  6. A bit of common sense goes a long way. ;)
     
  7. Offline

    Sagacious_Zed Bukkit Docs

  8. Offline

    tanaka141

    Thank you Sagacious_Zed,

    i try to find this in the wiki, but with the find tools, i never get this page....

    I looked the wiki,

    I have a question :
    When the Plugin configuration file doesn't exist, how we can know this information ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  9. If it does not exist, it obviously does not store any information. :)
     
  10. Offline

    tanaka141

    i look into source code, and saw some big problem without returning any information, this is a big problem
     
  11. What is a big problem?
     
  12. Offline

    tanaka141

    when i write my explanation i found how to resolve the problem

    but, i have another point, if you use this method :
    Code:
    FileConfiguration config = null;
    config = this.getConfig();
    
    It would be insteresting that config stay with the "null" value if there is no config file for the plugin, to create it with only one control, as this :
    Code:
    if(config == null) {
        config.set("Limite.Exterieur", 7000);
    }
    int Exterieur = config.getInt("Limite.Exterieur");
    this.saveConfig();
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  13. No need to do all of that, just use getConfig() and saveConfig(). It will do the file management for you.
     
  14. Offline

    Sagacious_Zed Bukkit Docs

    If config == null and you are calling a method on it, this will throw a null exception error guaranteed.
     
  15. Offline

    tanaka141

    this is very difficult to explain that the system doesn't make any control.

    i test :
    Code:
    FileConfiguration config = null;
    config = this.getConfig();
    int Exterieur = config.getInt("Limite.Exterieur");
    this.saveConfig();
    
    without config.yml in the plugin folder, there is no null exception error, but an empty "config.yml" is created, and Exterieur variable isn't set to any value.

    We must have information that the config file doesn't exist to create a default procedure to set default value.
     
  16. You should just do something like this: (keep in mind this example still uses the old configuration system)
    Code:java
    1. if (config.getProperty("allowCommands") == null) {
    2. List<String> dummyList = new ArrayList<String>();
    3. dummyList.add("/time");
    4. dummyList.add("/help");
    5. config.setProperty("allowCommands", dummyList);
    6. config.save();
    7. }
    8. if (config.getProperty("spawnOnKill") == null) {
    9. config.setProperty("spawnOnKill", true);
    10. config.save();
    11. }
    12. if (config.getProperty("randomSpawns") == null) {
    13. config.setProperty("randomSpawns", false);
    14. config.save();
    15. }
    16. if (config.getProperty("lobbyOnly") == null) {
    17. config.setProperty("lobbyOnly", false);
    18. config.save();
    19. }
    20. if (config.getProperty("ladder.custom") == null) {
    21. config.setProperty("ladder.custom", false);
    22. config.save();
    23. }
    24. if (config.getProperty("ladder.ladder") == null) {
    25. List<Integer> dummyList = new ArrayList<Integer>();
    26. dummyList.add(276);
    27. dummyList.add(267);
    28. dummyList.add(279);
    29. dummyList.add(258);
    30. dummyList.add(283);
    31. dummyList.add(286);
    32. dummyList.add(285);
    33. dummyList.add(0);
    34. config.setProperty("ladder.ladder", dummyList);
    35. config.save();
    36. }
    37. if (config.getProperty("ladder.sideItems") == null) {
    38. List<Integer> dummyList = new ArrayList<Integer>();
    39. dummyList.add(320);
    40. config.setProperty("ladder.sideItems", dummyList);
    41. config.save();
    42. }
     
  17. Offline

    Sagacious_Zed Bukkit Docs

    No, you don't actually. With the new system, you can assign defaults, that do not overwrite the value from the config. There are several ways of doing this in fact.
     
  18. Offline

    KoryuObihiro

    Getting this error:
    Stacktrace (open)

    12:38:51 [SEVERE] Error occurred while enabling ModDamage v0.9.6 (Is it up to date?): Cannot store null
    java.lang.IllegalArgumentException: Cannot store null
    at org.bukkit.configuration.MemorySection.prepForStorage(MemorySection.java:526)
    at org.bukkit.configuration.MemorySection.set(MemorySection.java:189)
    at org.bukkit.configuration.file.YamlConfiguration.deserializeValues(YamlConfiguration.java:96)
    at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:64)
    at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:143)
    at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:109)
    at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:178)
    at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:123)
    at com.KoryuObihiro.bukkit.ModDamage.ModDamage.onEnable(ModDamage.java:225)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:170)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:957)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:171)
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:154)
    at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:413)
    at org.bukkit.Bukkit.reload(Bukkit.java:182)
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:22)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:163)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:355)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:351)
    at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:506)
    at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:485)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)

    for this line of code:
    Snippet (open)

    final FileConfiguration config = this.getConfig();


    Has anybody else had this problem?
     
  19. Offline

    Sagacious_Zed Bukkit Docs

    That is not the line, responsible for the invalid argument exception, because that method call does not take any arguments.
    However, you need to update past the latest RB as there are some bugs in the new Configuration API.
     
  20. Offline

    KoryuObihiro

    I know it's not, because the top of the stacktrace points to ConfigurationSection.

    Using Bukkit #941, which RB 1317 depends on for the API. So yes, I'm using the latest build.
     
  21. Offline

    Sagacious_Zed Bukkit Docs

    no the latest build is
    bukkit #956 and craftbukkit #1344
    http://ci.bukkit.org/

    afaik you need Craftbukkit #1329 or greater
     
  22. Offline

    KoryuObihiro

    Latest build may fix it, but it shouldn't be necessary. The whole point of Recommended Builds is for devs to release against them in a stable fashion.

    So, all I can figure from your response there is that there's a bug with 1317. Correct?
     
  23. Offline

    Sagacious_Zed Bukkit Docs

    yes
     
  24. Offline

    KoryuObihiro

    **curses the distinct lack of testing**
    :p
     
Thread Status:
Not open for further replies.

Share This Page