Getting from a list using bukkit configuration

Discussion in 'Plugin Development' started by xigsag, Aug 3, 2013.

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

    xigsag

  2. Offline

    Rocoty

    to save
    Code:java
    1. config.set(yourKey, yourList);


    to load
    Code:java
    1. config.getStringList(yourKey);
    2. config.getShortList(yourKey);
    3. config.getLongList(yourKey);
    4. config.getMapList(yourKey);
    5. config.getIntegerList(yourKey)

    Any of these
     
  3. Offline

    xigsag

    Rocoty
    I've actually just tried out the adding to list, giving me an error.
    How do I add player names to a list, then adding it to the config?
     
  4. Offline

    Rocoty

    Show me your attempt then?
    It's basically just retrieve the list from the config, add to the list, set the new list to the config.

    By the way, I'd avoid using getList(), as it will return a list parameterised with a wildcard, which may not be desirable.
     
  5. Offline

    xigsag

    Rocoty
    That is exactly it. I'm using getList().
    Code:java
    1. if(args[0].equalsIgnoreCase("create")){
    2. List<String> guildMembers = (List<String>)this.getConfig().getList("list");
    3. guildMembers.add("test");
    4. guildMembers.add("test2");
    5. this.getConfig().set("list", guildMembers);
    6. this.saveConfig();
    7. p.sendMessage(ChatColor.GREEN+"Guild created.");
    8. }


    Rocoty
    The error:
    Code:java
    1. org.bukkit.command.CommandException: Unhandled exception executing command 'guil
    2. d' in plugin Guilds v1
    3. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    4. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    5. 9)
    6. at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServe
    7. r.java:523)
    8. at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerCon
    9. nection.java:962)
    10. at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.j
    11. ava:880)
    12. at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java
    13. :837)
    14. at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
    15. at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296
    16. )
    17. at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java
    18. :116)
    19. at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    20. at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:3
    21. 0)
    22. at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    23. 90)
    24. at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    25. 26)
    26. at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    27. 86)
    28. at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    29. :419)
    30. at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    31. 82)
    32. Caused by: java.lang.NullPointerException
    33. at guild.main.Main.onCommand(Main.java:26)
    34. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    35. ... 15 more


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

    Rocoty

    Well, use getStringList()...it will give you a List<String> so there is no need to cast anything, and you'll get a safer result overall
     
  7. Offline

    xigsag

    Rocoty
    Awesome. Trying it out now..

    EDIT: Fantastic. Works great, thanks.
     
Thread Status:
Not open for further replies.

Share This Page