Solved why using getPLayer() != null instead of isOnline()?

Discussion in 'Plugin Development' started by bellegueule, Apr 21, 2013.

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

    bellegueule

    all is in the title ,

    good night :p
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    Once checks if the returned value is null, the other invokes a method that returns true if the player is online. Not sure why you are comparing them. They do completely different things. You may in fact end up needing to call them both in the same block of code.
     
  3. Offline

    Tirelessly

    isOnline is for using the OfflinePlayer class, which Player inherits. Players can be null, but OfflinePlayers cannot.
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    Any variable or method return not pointing to a primitive can be null.
     
  5. Offline

    Tirelessly

    getOfflinePlayer(...) will create and return a new OfflinePlayer if the specified one doesn't exist. getPlayer(...) will return null if the player is not online. The reference can be null, but the method isn't going to return null.
     
  6. Offline

    bellegueule

    ok so if i undestant well,
    ___> will return true or false
    ______> will rerurn an online player name or NULL

    ______> return True , or NULL since he look in the player online

    i was using the last code but i was getting NULL when the player wasent online, thats why i ask the diferance in those code,

    Thanks, Sagacious_Zed Tirelessly
     
  7. Offline

    evilmidget38

    bellegueule Your last option won't return null, it'll throw a NullPointerException. There's a very large difference.
     
Thread Status:
Not open for further replies.

Share This Page