Solved Add to list to save in config not working

Discussion in 'Plugin Help/Development/Requests' started by Vinnya124, Jan 5, 2015.

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

    Vinnya124

    Hi. I am making a court plugin. One of the features of this plugin is that you can join the jury by doing /jury join. I create a list in the config file of all the jury members. There can be up to 20 jury members. I thought in one of my threads I got everything squared away with lists in the config but then I start my server I got an internal error when I tried to run /jury join.

    Here is the error:
    Code:
    [16:01:30 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'jury' in plugin EasyCourt v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-13716d9-0899683]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-13716d9-0899683]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:645) ~[spigot.jar:git-Spigot-13716d9-0899683]
        at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [spigot.jar:git-Spigot-13716d9-0899683]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [spigot.jar:git-Spigot-13716d9-0899683]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [spigot.jar:git-Spigot-13716d9-0899683]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [spigot.jar:git-Spigot-13716d9-0899683]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot.jar:git-Spigot-13716d9-0899683]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_25]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_25]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:683) [spigot.jar:git-Spigot-13716d9-0899683]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-13716d9-0899683]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot.jar:git-Spigot-13716d9-0899683]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-13716d9-0899683]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_25]
    Caused by: java.lang.NullPointerException
        at me.Vinnya124.EasyCourt.onCommand(EasyCourt.java:71) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-13716d9-0899683]
        ... 14 more
    >
    
    Creating the list in the begging in the function onCommand:
    Code:
    List<String> juryMembers = (List<String>) this.getConfig().getList("Jury Members");
    Accessing and modifying the list:
    Code:
    }else if(commandLabel.equalsIgnoreCase("jury")){
            if (args.length == 1){
                if(args[0].equalsIgnoreCase("join")){   
                    if(juryMembers.size() >= 20){
                        player.sendMessage(ChatColor.RED + "The court's jury is full!");
                    }else if(juryMembers.size() < 20 ){
                        juryMembers.add(player.getName());
                        getConfig().set("Jury Members", juryMembers);
                        player.sendMessage(ChatColor.GREEN + "You are now a member of the court's jury!");
                        saveConfig();
                    }
                }else if(args[0].equalsIgnoreCase("leave")){
                    juryMembers.remove(player.getName());
                    player.sendMessage(ChatColor.GOLD + "You are no longer a member of the court's jury!");
                }
            }
            return true;
        }
    I don't know why I keep getting this error. Any ideas?
     
  2. Offline

    SuperOriginal

    Instead of using the getList() method, use getStringList() and also don't have spaces in your keys(you should separate words with "-" or "_").

    You also didn't specify what line 71 is? If it is the instantiation of juryMembers, check if the list is null before trying to get it.
     
  3. Offline

    Vinnya124

    SuperOriginal likes this.
Thread Status:
Not open for further replies.

Share This Page