Question about Args,If-Statements and Players

Discussion in 'Plugin Development' started by JeykoExample, Aug 14, 2014.

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

    JeykoExample

    Hello Guys,

    i wanted to know if there is an way to check with a If Statement, if the second arg equals a Playername that was on the Server. (not Online, just WAS on the Server, sometime ...)

    Thanks a LOT!
     
  2. Offline

    Gerov

    JeykoExample Loop through the OfflinePlayers and check if the argument equals the player's name.
     
  3. Offline

    JeykoExample

    Im a newbie can u help me doing this? Gerov
     
  4. Offline

    Gerov

    JeykoExample Alright, so first, you'd get your command's argument, I am just using the first argument as an example:

    Code:java
    1. if(args.length > 0){
    2. if(args[0] != null){
    3. String s = args[0];
    4. }
    5. }


    Next you'd set up your loop to see if the player's name equals the argument:

    Code:java
    1. for(OfflinePlayer p : Bukkit.getOfflinePlayers()){
    2. if(p.getName().equals(s)){
    3. COMMANDSENDER_VAR.sendMessage("You found the player!");
    4. break;
    5. }
    6. }



    There you go :), good luck!
     
    JeykoExample likes this.
  5. Offline

    Dragonphase

  6. Offline

    JeykoExample

    Gerov Is that the Loop? Or do I have to add something?

    PHP:
    [LIST=1]
    [*]for(
    OfflinePlayer p Bukkit.getOfflinePlayers()){
    [*]if(
    p.getName().equals(s)){
    [*]
    COMMANDSENDER_VAR.sendMessage("You found the player!");
    [*]break;
    [*]}
    [*]}
    [/LIST]
     
  7. Offline

    Drew1080

    JeykoExample
    Or instead of looping through all the offline players you could just use:

    Server#getOfflinePlayer(name)#hasPlayedBefore()
     
    JeykoExample likes this.
  8. Offline

    Gerov

    JeykoExample That is all that you need, I gave you what you need, now you can figure out how to put it all together :), most people on this site wouldn't give you as much as I just did.
     
    JeykoExample likes this.
Thread Status:
Not open for further replies.

Share This Page