Error With Commands

Discussion in 'Spigot Plugin Development' started by DimoKouli, May 18, 2015.

  1. So when i run command tt add or tt remove it says an enternal error occured please help!
    Code (Text):


                     if(args[0].equalsIgnoreCase("add")){
                         if(args[1] != null){
                         List<String> list = getConfig().getStringList("PlayersNotToBeKicked");
                         list.add(args[1]);
                         getConfig().set("PlayersNotToBeKicked", list);
                         saveConfig();
                         sender.sendMessage(ChatColor.GREEN + "Player " + args[1] + " Added To PlayersNotToBeKicked List In The Config.yml");
                         reloadConfig();
                     }}
                     else if(args[0].equalsIgnoreCase("remove")){
                         if(!getConfig().getStringList("PlayersNotToBeKicked").contains(args[1])){
                             sender.sendMessage(ChatColor.RED + "The List PlayersNotToBeKicked Does Not Contain The Player " + args[1]);
                         }
                         else if(getConfig().getStringList("PlayersNotToBeKicked").contains(args[1])){
                             List<String> list = getConfig().getStringList("PlayersNotToBeKicked");
                             list.remove(args[1]);
                             getConfig().set("PlayersNotToBeKicked", list);
                             saveConfig();
                             
                         sender.sendMessage(ChatColor.GREEN + "Player " + args[1] + " Removed From PlayersNotToBeKicked List In The Config.yml");
                         
                     }
                 }
               
                 
             
         }
             
         }
        return true;
     
    Console Log
    Code (Text):

    org.bukkit.command.CommandException: Unhandled exception executing command 'tt'
    in plugin tttt
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    1) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServe
    r.java:767) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerCon
    nection.java:1043) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :880) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat
    .java:65) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186
    ) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java
    :81) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:7
    34) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
            at me....onCommand(Main.java:79) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
            ... 13 more
     
  2. Could u tell me what pls ? :D
     
  3. is the error
     
  4. if(!getConfig().getStringList("PlayersNotToBeKicked").contains(args[1])){
    2 errors one above and one below
    list.add(args[1]);
     
  5. hmm can i see the code? the main class
     
  6. I'd like to see the whole code, before saying what it could be.
     
  7. Can you give me the code from line 79 in Main.java?
     
  8. well... anyways,. thats what u are interested in
    Code (Text):

     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
               
         if(cmd.getName().equalsIgnoreCase("tt") && sender instanceof Player){
             if(args.length == 1){
                 if(args[0].equalsIgnoreCase("tt")){
                     usePlayerListener = true;
                   
                             
                 }
                 else if(args[0].equalsIgnoreCase("ttt")){
                     usePlayerListener = false;
                   
                 }
                 
                     if(args[0].equalsIgnoreCase("tttt")){
                         if(args[1] != null){
                         List<String> list = getConfig().getStringList("PlayersNotToBeKicked");
                         list.add(args[1]);
                         getConfig().set("PlayersNotToBeKicked", list);
                         saveConfig();
                         sender.sendMessage(ChatColor.GREEN + "Player " + args[1] + " Added To PlayersNotToBeKicked List In The Config.yml");
                         reloadConfig();
                     }}
                     else if(args[0].equalsIgnoreCase("tttt")){
                         if(!getConfig().getStringList("PlayersNotToBeKicked").contains(args[1])){
                             sender.sendMessage(ChatColor.RED + "The List PlayersNotToBeKicked Does Not Contain The Player " + args[1]);
                         }
                         else if(getConfig().getStringList("PlayersNotToBeKicked").contains(args[1])){
                             List<String> list = getConfig().getStringList("PlayersNotToBeKicked");
                             list.remove(args[1]);
                             getConfig().set("PlayersNotToBeKicked", list);
                             saveConfig();
                             
                         sender.sendMessage(ChatColor.GREEN + "Player " + args[1] + " Removed From PlayersNotToBeKicked List In The Config.yml");
                         
                     }
                 }
               
                 
             
         }
             
         }
        return true;
      }
      public void launchConfig() {
         
         getConfig().addDefault("KickMessage", "&b&LPlease Rejoin! Bot Preventer Kicked You!");
         getConfig().options().copyDefaults(true);
         saveConfig();
         
         String stringValue = "tqrt";
         this.getConfig().set("PlayersNotToBeKicked", stringValue);
         reloadConfig();
      }
     
     
  9. The stack trace print showed error is on level 79, in your code I also noticed }} on one line, just had a quick sweep past it just saying.
     
  10. line 79:
    if(!getConfig().getStringList("PlayersNotToBeKicked").contains(args[1])){
     
  11. if(cmd.getName().equalsIgnoreCase("tt") && sender instanceof Player){
    if(args.length == 1){
    i always do 0
     
  12. You used if(args.length == 1)
    I noticed if(args[1] != null) instead, just use if(args.length >= 2) ._. that's why it is throwing the exception.
     
  13. and then there is
    which i think is another problem cuz u already said
    and that creates a command so i dont really know why u need
     
  14. @CreeperAnatomy i didnt have this line of code i just added after the exception to try debug it
     
  15. i always set it to
    when i make my first command
     
  16. You have to cycle through the Strings in the list and check them, don't you?

    for loop for getConfig(),getStringList("PlayersNotToBeKicked")


    Not sure tbh, I'm at school
     
  17. @T0X1C tt are replaced i just didnt want to show it ;)
     
  18. Now i dont get message that error occured but cmds still not work.