Solved BUG: For a reason, instead of the reason I get some weird string info.

Discussion in 'Plugin Development' started by ThePandaPlayer, Nov 27, 2016.

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

    ThePandaPlayer

    My problem is I am trying to convert the "args" array declared in the command method to a string. I originally created a new string that called the args.toString() method. But, instead of a string of command arguments, I got this:

    [Ljava.lang.String;@1f2f44b3

    I am not sure why this is popping up. I also don't want to have a line that is billions of characters long (e.g. player.sendMessage("You were kicked! Reason: " + args[1] + " " + args[2] ); etc.)


    I tried removing the toString() call, thinking that the sendMessage() method would automatically call the toString(); method on its own. (like System.out.print()) That didn't work. Any suggestions on how to convert the array to readable characters?
     
  2. Offline

    Zombie_Striker

    @ThePandaPlayer
    That's not how you turn arrays into single objects. For what you want, do the following:
    1. Create a StringBuilder object.
    2. Create a for loop. Loop through all the args that exist.
    3. For each arg, append it to the StringBuilder (using StringBuilder.append(arg[X]))
    4. Once you have looped through all the args, use StringBuilder.toString(). This is now contains all the args.
     
  3. Offline

    ThePandaPlayer

    Ok, I have tried this implementation, I have a for loop that loops thru. all of the arguments. But, if I start the server and try it, it is coming up with this exception that tells me something is null that shouldn't be. My for loop looks like:

    StringBuilder builder = new StringBuilder();

    for(int cycles =1; cycles>=args.length; cycles++) {
    //I need cycles to be 1 so it doesn't include a random Player name when the args get processed
    builder.append(args[cycles]);

    }
    String reason = builder.toString();

    I have tried changing the >= to == which gets rid of the exception, but the string of args is somehow blank...
    I have also tried adding an if-statement to check if the arg is null.
    I am just not sure what to do now...
     
  4. Offline

    ThePandaPlayer

    LOL, I thought that was just some sort of HTML-ish tag! Thank you, I will implement this now.
     
Thread Status:
Not open for further replies.

Share This Page