if(Bukkit.getServer().getPlayer(args[1]) != null){

Discussion in 'Plugin Development' started by suitinacow, Jul 15, 2015.

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

    suitinacow

    Code:
    if(Bukkit.getServer().getPlayer(args[1]) != null){
    this for somereason returns null even though args[1] is an actual player online?
     
  2. Offline

    aaiach

    If you are trying to find out if the targeted player is online I would recommend doing this:

    Code:
    Player target = Bukkit.getPlayerExact(args[1]);
    
    if(target != null){
    //Do your stuff
    }
    
    
     
  3. Offline

    SuperSniper

    just check if it IS null, if it is not, do stuff,
     
  4. Offline

    DoggyCode™

    Code:
    Player player = (Player)Bukkit.getServer().getPlayer(args[1]);
    
    if(player == null){
    sender.sendMessage("Player is null");
    } 
    sender.sendMessage("Player is not null");
    //code...
    }
    
    That should work ;)
     
    Last edited: Jul 16, 2015
  5. @aaiach
    Bukkit.getPlayer("name") is a fuzzy match method.

    For example if you have a user Notch online. Searching for "N", "No", "Not" will all return true.

    Use Bukkit.getPlayerExact
     
  6. Offline

    DoggyCode™

    @Adamki11s It's often what people want though.. Like if I were to send money to someone with the IGN "bossisawesome", then I would want to be so I can just type "/pay bossi 1000" for example..
     
Thread Status:
Not open for further replies.

Share This Page