How do i fix my internal error...

Discussion in 'Plugin Development' started by danielmiles, Feb 6, 2013.

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

    danielmiles

    i've never been able to figure out what was really wrong... im trying to check for more than one args in a command and here is what i do...
    Code:
             
    if(commandName.equals("cl")){
     
        if(args[0].equalsIgnoreCase("setcolor")){
          if(args[1].equalsIgnoreCase("blue")){
          //do stuff
          }
          if(args[1].equalsIgnoreCase("pink")){
          //do stuff
          }
    }
                                          }
    when i do like /cl setcolor blue/pink it works the way i want it to, but when i do /cl setcolor i get and internal error here is my stacktrace:

    Code:
    2013-02-06 18:42:12 [INFO] danielmiles issued server command: /cl setcolor
    2013-02-06 18:42:12 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'cl' in plugin mahplugin 1.00.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186)
        at org.bukkit.craftbukkit.v1_4_6.CraftServer.dispatchCommand(CraftServer.java:514)
        at net.minecraft.server.v1_4_6.PlayerConnection.handleCommand(PlayerConnection.java:979)
        at net.minecraft.server.v1_4_6.PlayerConnection.chat(PlayerConnection.java:897)
        at net.minecraft.server.v1_4_6.PlayerConnection.a(PlayerConnection.java:852)
        at net.minecraft.server.v1_4_6.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.v1_4_6.NetworkManager.b(NetworkManager.java:290)
        at net.minecraft.server.v1_4_6.PlayerConnection.d(PlayerConnection.java:112)
        at net.minecraft.server.v1_4_6.ServerConnection.b(SourceFile:39)
        at net.minecraft.server.v1_4_6.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_4_6.MinecraftServer.r(MinecraftServer.java:598)
        at net.minecraft.server.v1_4_6.DedicatedServer.r(DedicatedServer.java:224)
        at net.minecraft.server.v1_4_6.MinecraftServer.q(MinecraftServer.java:494)
        at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:427)
        at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
        at me.desty.plugin.mahplugin.onCommand(plugin.java:51)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
    fix any1?

    oh also, how do i access an array list from one class to another?
     
  2. Offline

    ZeusAllMighty11

    if(args.length >= 1)
     
  3. Offline

    danielmiles

    not sure where u mean to put that? please clearify, thanks

    u mean like this?
    Code:
    if(commandName.equals("cl")){
           //embody the below with it and an else to return false?
        if(args[0].equalsIgnoreCase("setcolor")){
         // or put it in here like "if(args[1].length() >= 1)" with an else to return false?
          if(args[1].equalsIgnoreCase("blue")){
          //do stuff
          }
          if(args[1].equalsIgnoreCase("pink")){
          //do stuff
          }
    }
                                          }
     
  4. Offline

    danielmiles

    bump.. any1??
     
  5. Offline

    EnvisionRed

    You don't know for sure that there are any arguments. So when you try to call args[0] (the first argument), and there are no arguments, there's an error. That's why you need to check if each argument EXISTS before you use it.
     
  6. Offline

    Technius

    danielmiles
    It should be something like this:
    Code:
    if(args.length == 2)
    {
        if(args[0].equalsIgnoreCase("something"))
        {
             if(args[0].equalsIgnoreCase("else")) //Your code here;
             else if(args[0].equalsIgnoreCase("other")) //Your code here;
             else /*You might want to send them usage*/;
        }
        else /*You might want to send them usage*/;
    }
    else /*You might want to send them usage*/;
    
     
  7. Offline

    danielmiles

    ok well here is what i have so far but still is giving me the internal error
    Code:
    if(commandName.equals("cl")){
    if(args.length>= 1){
        if(args[0].equalsIgnoreCase("setcolor")){
         if(args.lenght >= 1){
          if(args[1].equalsIgnoreCase("blue")){
          //do stuff
          }
          if(args[1].equalsIgnoreCase("pink")){
          //do stuff
          }
    }else
    return false;
    }else
    return false;
    }
    }
     
  8. Offline

    EnvisionRed

    You're checking if there is at least ONE argument and then proceed to use TWO. I don't see what's so hard about this.
     
Thread Status:
Not open for further replies.

Share This Page