How to make a Player the Args?

Discussion in 'Plugin Development' started by xxCoderForLifexx, Nov 17, 2012.

Thread Status:
Not open for further replies.
  1. I wanted to make the player args like
    /tp [player]
     
  2. Offline

    LaxWasHere

    Player targetPlayer = player.getServer ().getPlayer(args[0]); ?
     
    xxCoderForLifexx likes this.
  3. Offline

    fireblast709

    yep

    xxCoderForLifexx if your player is the first argument:
    Code:java
    1. Player target = Bukkit.getPlayer(args[0]);
    2. if(target != null)
    3. {
    4. player.teleport(target);
    5. }
    6. else
    7. {
    8. player.sendMessage("Player "+args[0]+" is not online");
    9. }
     
  4. Offline

    Drkmaster83

    Isn't there a matchPlayer() method or something? I've forgotten how to use it, but I'm sure there is.
     
  5. Offline

    fireblast709

  6. Offline

    Drkmaster83

    Yes it does. I was just curious is all. :p
     
  7. Thanks
    Thanks lax I just couldn't remember that
     
  8. Offline

    Knaxel

    im looking at this thread for help but im confused on what the player variable is equal to?
     
  9. Offline

    molenzwiebel

    Nothing, it should be
    Player p = Bukkit.getPlayer(args[0]);
     
  10. Offline

    Knaxel

  11. Offline

    xXCryptoFreakXx

    .getPlayer() cannot be used to find offline players, instead, .getPlayer() looks for the player online with the closest name. If I did .getPlayer("xxc") it would return me, xXCryptoFreakXx.

    If you want to check for offline players, or search by exact name, you would use .getPlayerExact(), which searches for players by EXACT names, not by matching.

    Code:
       
    public Player FindPlayer(String strn) {
            Player player = m_plugin.getServer().getPlayer(strn);
            return player;
    }
    
    If you put that in your plugin (m_plugin is a pointer to my main class), you can easily find players anywhere in your plugin by doing

    Code:
    Player player = FindPlayer(string)
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
Thread Status:
Not open for further replies.

Share This Page