Solved Arguments error , please help me fix .

Discussion in 'Plugin Development' started by TGamingStudio, Apr 26, 2018.

Thread Status:
Not open for further replies.
  1. Hello i have made a code . but im getting errors when i dont have args .
    i allready checked if arg is null and made else method . but it cant reach it .
    Code:
    if(args[1]!=null)
    {some code}
    else{say"check syntax"}
    my code (open)

    Code:
    if(args[0].equals("user"))
                 {
                     if(args[1] != null)
                     {
                         if( args[1].equals("invite"))
                         {
                         if(args[1] != null && args[2] != null) //kingdom
                         {
                             if(args[1] != null && args[3] != null) //name
                             {
                                 if(this.getConfig().getString("kingdoms." + args[2] + ".players" ) != null) //kingdom exists
                                 {
                                    if(this.getConfig().getString(p.getName() + ".king").equalsIgnoreCase("true"))// p is king
                                    {
                                        Player target = Bukkit.getPlayer(args[3]);
                                        if(target != null)  // target exists
                                        {
                                            if(this.getConfig().getString(p.getName()+".kingdom") == null) // has kingdom
                                            {
                                              target.sendMessage("You were invited to kingdom " + args[2]);
                                              invited.put(args[3], args[2]);
                                            }else
                                            {
                                                p.sendMessage(target.getName()+ " has a kingdom");
                                            }
                                        }
                                        else
                                        {
                                          p.sendMessage("Player "+args[3]+" is not online");
                                        }
                                    }
                                    else
                                     {
                                        p.sendMessage("u are not a king");
                                     }
                                 }
                                 else
                                 {
                                    p.sendMessage("check your syntax");
                                 }
                             }
                             else
                             {
                                p.sendMessage("check your syntax");
                             }
                         }
                         else
                         {
                            p.sendMessage("check your syntax");
                         }
                      }
                         else if(args[1].equals("kick"))
                         {
                           
                         }
                         else if(args[1].equals("accept"))
                         {
                             if(invited.get(p.getName())!= null)
                             {
                                 p.sendMessage("You joined kingdom " + invited.get(p.getName()));
                                 this.getConfig().set("kingdoms."+ invited.get(p.getName()) +".players",
                                 this.getConfig().getString("kingdoms."+ invited.get(p.getName()) +".players") + " , "+ p.getName());
                                 this.getConfig().set(p.getName()+".kingdom", invited.get(p.getName()));
                                 this.getConfig().set(p.getName()+".king", "false");
                                 this.saveConfig();
                                 invited.put(p.getName(),null);
                             }
                             else
                             {
                                 p.sendMessage("u didnt recive an invitation");
                             }
                         }
                     }
                     else
                     {
                        p.sendMessage("check your syntax");
                     }
                 }

    error (open)

    Code:
     null
    org.bukkit.command.CommandException: Unhandled exception executing command 'kingdom' in plugin Kingdoms v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_161]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_161]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
            at pl.kingdoms.Main.onCommand(Main.java:115) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.1.8.8.jar:git-Bukkit-18fbb24]
            ... 15 more

    . thanks

    EDIT : yes . i get the error when i do /command user , /command user args[1] ... and with others too
     
  2. Online

    timtower Administrator Moderator

    TGamingStudio likes this.
  3. @timtower thanks :D it fixed my problem . but why checking if isnt null doesnt work ?
     
  4. Online

    timtower Administrator Moderator

    @TGamingStudio Arrays throw errors when you access something that doesn't exist.
     
  5. Offline

    JanTuck

    Because you can’t get any index from an array that is null.


    Sent from my iPhone using Tapatalk
     
    TGamingStudio likes this.
Thread Status:
Not open for further replies.

Share This Page