if player used

Discussion in 'Plugin Development' started by Skmaestro, Feb 2, 2014.

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

    Skmaestro

    help please and sorry for my bad English language!
    how to know if player exist?

    if(getServer().GetPlayer("MyNick") - good
    if(getServer().GetPlayer("abcdefghijklmnopqrstu") - Big error how to fix? this player is never used
    i wan't disable error if player does not exist
     
  2. Offline

    Grief'd man

    If you want to see if he is online, do this:
    Code:
    for(Player p : Bukkit.getOnlinePlayers())
    {
        if(p.getName().equalsIgnoreCase("Name"))
        {
            //Do stuff
        }
    }
    Otherwise, to check if the player is either online or has ever been on, do this:
    Code:
    for(OfflinePlayer p : Bukkit.getOfflinePlayers())
    {
        if(p.getName().equalsIgnoreCase("Name"))
        {
            //Do stuff
        }
    }
     
    Skmaestro likes this.
  3. Offline

    The_Doctor_123

    Grief'd man
    Bit inefficient.. this would be better:
    Code:
    if (Bukkit.getServer().getPlayer("SomePlayer") != null)
    {
      // Player exists. Execute your code here.
    }
     
    Skmaestro and 97waterpolo like this.
  4. Offline

    Grief'd man

    The_Doctor_123

    True! I had forgotten about that, I've been getting lazy!
     
    97waterpolo likes this.
  5. Offline

    The_Doctor_123

    I wouldn't call your code lazy.. it was more work. :p
     
  6. Offline

    Skmaestro

    Sorry i'm noob-( and duplicate theme's
     
Thread Status:
Not open for further replies.

Share This Page