Plugin Help Need help with Command Arguments. arg[0] always erroring.

Discussion in 'Plugin Help/Development/Requests' started by causticlasagne, Nov 24, 2015.

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

    causticlasagne

    Hello Everyone!
    This is my first thread here.

    I'm having an issue with my plugin I'm making where a player enters a command and some arguments.
    Basically if a player enters a command without arguments, I want to do something different. Example:
    /clsinv cls a
    cmd | arg0 | arg1
    /clsinv cls
    /clsinv
    Right now, if the player enters no arguments, then it displays the version and debug info, but I cannot check if the arguments are null or equal to "":

    if (!args[0].equalsIgnoreCase(null)) {
    if (!args[0].equalsIgnoreCase("")) {

    if (!args[0]==null)) {
    if (!args[0]==""{


    These above functions always return a java.lang.ArrayIndexOutOfRangeException, which I believe is caused by trying to access a cell in a non-existent dimension of an array... or something like that.
    args[0]=""
    args[1]=""
    .....
    The only way I can currently prevent the error is by using a try...catch function, which I'd rather not do.

    If anybody can make sense of what I've said above, can you help?

    Thanks, CausticLasagne
    Also, Any source you need just ask... within reason.

    Is there a way that I can check if args[0] is equal to null?

    I found a way... I used

    args.length

    to check the length of the array, and if the price is right, check it's contents.

    Dev: Can you lock this thread? It is no longer being used.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 24, 2015
  2. Offline

    ObviousEmeralds

    The methods you used are wrong. To check if there is no args you do

    Code:
    if(args.length == 0){
    //Do what you want if no arguments are specified
    }
     
Thread Status:
Not open for further replies.

Share This Page