Help with config lists

Discussion in 'Spigot Plugin Development' started by jckswk, May 30, 2016.

  1. Hi, I'm back again with another problem xD. So I have a string and I want to create a list in the config and save it to a list. But I'm getting errors and I'm not really sure what the problem is...

    Code
    Code (Text):
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
           
            Player player = (Player) sender;
           
            if(cmd.getName().equalsIgnoreCase("request")){
                int al = args.length;
                if(al >= 2){
                    if(args[0].equals("add")){

                        StringBuilder sb = new StringBuilder(args[1]);
                       
                        for(int i =2; i < al; i++){
                            sb.append(' ').append(args[i]);
                            Bukkit.getLogger().info(sb.toString());
                        }
                       
                        @SuppressWarnings("unchecked")
                        List<String> requestList = (List<String>)this.getConfig().getList("requests");
                        requestList.add(sb.toString() + ":" + player.getUniqueId());
                       
                        saveConfig();
                       
                        Bukkit.getLogger().info(player.getName() + " has added a request " + sb.toString());
                       

                            }
                       
                       
                    }


                }
           
            return false;
        }
    ERROR
    Code (Text):
    [09:03:03 INFO]: jckswk issued server command: /request add this is a test
    [09:03:03 INFO]: this is
    [09:03:03 INFO]: this is a
    [09:03:03 INFO]: this is a test
    [09:03:03 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'request' in plugin jckswkKitpvp v0.01
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.dispatchCommand(CraftServer.java:646) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PlayerConnection.handleCommand(PlayerConnection.java:1349) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:1184) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_60]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_60]
        at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
        at me.jckswk.requests.Main.onCommand(Main.java:53) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        ... 15 more
     
    Thanks!
     
  2. Can you give me the code from line 53 of the Main.class which is what gives the error
     
  3. Caused by: java.lang.NullPointerException
    at me.jckswk.requests.Main.onCommand(Main.java:53) ~[?:?]
    It's a NullPointerException.
     
  4. Code (Text):
                        requestList.add(sb.toString() + ":" + player.getUniqueId().toString());
     
  5. You have a few simple errors, first in the list that you created, and second that in the config never these saving nothing.
    See this is what you have to use
    Code (Text):
    List<String> list = this.getConfig().getList("requests");
               
    list.add(sb.toString() + ":" + player.getUniqueId().getString());
                this.getConfig().set("requests", list);
     
  6. Tried it and I'm still getting a null error. I also tried the getConfig().addDefaults("requests", null); in on enable

    Code (Text):
    [11:54:21 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'request' in plugin jckswkKitpvp v0.01
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.dispatchCommand(CraftServer.java:646) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PlayerConnection.handleCommand(PlayerConnection.java:1349) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:1184) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_60]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_60]
        at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
        at me.jckswk.requests.Main.onCommand(Main.java:56) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        ... 15 more
     
  7. Try to add you manually culauquier the StringList thing is if in the config is:
    Code (Text):
    PLUGIN:
           LISTAS:
                 COSAS:
                                 -
                                 -
    INSERT ANYTHING AND THEN RUN THE COMMAND TO SEE IF THE ERROR IS BECAUSE THE LIST IS NULL
     
  8. Code (Text):
    [12:16:58 INFO]: jckswk issued server command: /request add testing this out
    [12:16:58 INFO]: testing this
    [12:16:58 INFO]: testing this out
    [12:16:58 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'request' in plugin Requests v0.01
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.dispatchCommand(CraftServer.java:646) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PlayerConnection.handleCommand(PlayerConnection.java:1349) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:1184) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_60]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_60]
        at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
        at me.jckswk.requests.Main.onCommand(Main.java:57) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Spigot-8a048fe-d8637df]
        ... 15 more
     
    Something is wrong, when I reload the server, the config file clears. Maybe I should try add defaults again?
     
  9. Is deleted again I added the command? or deletes the entire file?
     
  10. if I manually add in "requests:" to the config, then reload the server, that "requests:" and whatever other text I put in there is gone...
     
  11. You got that done with the server off
     
  12. Yep. If this isn't gonna work, is there way I can do it without a list... although it would work best with it
     
  13. The truth is that not is because you're not going I use it in a game that thinks and I will 100% well