Command issues.

Discussion in 'Plugin Development' started by Razorcane, Oct 15, 2011.

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

    Razorcane

    Ok, so I have this simple TP command. When a user types /otp <player> it teleports them to the player and gives the player a message if the player is OP. The problem is, if a user types /otp, it returns an ArrayIndexOutOfBoundsException, and I have no idea how to fix this. I've tried making an if statement to check if args[0].isEmpty(), but it doesn't work, it returns the same error, and the error is this line here:

    Code:
    Player player = plugin.getServer().getPlayer(args[0]);
    I assume the error is because the 0 index is empty, but I don't know how to display a message if it is empty, because the if statement did not work. Any help would be greatly appreciated.
     
  2. Offline

    Jogy34

    try
    if(args[].length == 1)
    instead of
    if(args[0] == null)
     
  3. if (args.length >= 1) { //see whether args[] contains at least one element, which then has the index 0

    }
     
Thread Status:
Not open for further replies.

Share This Page