Using a username as a variable question

Discussion in 'Plugin Development' started by darknesschaos, Jan 19, 2011.

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

    darknesschaos

    I am trying to use a username in a command line function and was curious on how to get this to work.

    The code below is what I am currently using.



    if(command.length == 3)
    {
    Player onlinePlayers = plugin.getServer().getOnlinePlayers();​
    for(int i=0; i<onlinePlayers.length; i++)​
    {​
    if (command[2] == onlinePlayers.getName())​

    {​
    //do stuff​
    fail = false;​
    break;​
    }​
    else​
    fail = true;​
    }
    }

    I also used toString() on both and that didn't work either.
     
  2. Offline

    Zenexer

    How are you implementing a console command to begin with? I can't figure that out!
     
  3. Offline

    darknesschaos

    String command = event.getMessage().split(" ");
     
  4. Offline

    Zenexer

    That still doesn't explain how you are actually intercepting something sent to the console. Player commands are easy. Console commands... the classes are there, but I don't know how to actually use them, nor can I find any documentation.
     
  5. Offline

    darknesschaos

    it is a player command, sorry.
     
  6. Offline

    Zenexer

    Are you looking for plugin.getServer.matchPlayers(String)?
     
  7. Offline

    darknesschaos

    That may do the trick!
     
  8. Offline

    LRFLEW

    call onlinePlayers as:
    Code:
    Player[] onlinePlayers = plugin.getServer().getOnlinePlayers();
     
  9. Offline

    darknesschaos

    That is in the code.
    --- merged: Jan 20, 2011 2:59 AM ---
    Ok, your suggestion did not work out best.

    what I had to do was change the if statement of:
    command[2] == onlinePlayers.getName()

    to:
    command[2].compareToIgnoreCase(onlinePlayers.getName()) == 0

    I kinda feel stupid for this one.
     
  10. Offline

    LRFLEW

    I thought you had to declare it as Player[ ] instead of just Player, but I may be wrong.
     
  11. Offline

    darknesschaos

    It was a problem from me copying over, sorry. So, yes you are correct.
     
Thread Status:
Not open for further replies.

Share This Page