Check if a player is brand new?

Discussion in 'Spigot Plugin Development' started by BryceTheCoder, May 21, 2015.

  1. Hey guys, I was curious of how I can check if a player is brand new.
    I don't want to store in a file somewhere that list ALL the players that have joined or anything.
    Is there a better way of doing this? If so, please let me know, thanks :)
     
  2. if(!player.hasPlayedBefore())
     
    • Like Like x 1
    • Winner Winner x 1
    • Useful Useful x 1
  3. LMFAO Wow! What a great boolean ;D
    Exactly what I needed. Thank you very much Skepter:)
     
  4. JavaDoc reference here.

    And just compare it on an onJoinEvent
     
  5. How does this look guys? Or is this bad to teleport a player on join?
    Code (Text):

    @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            if (!e.getPlayer().hasPlayedBefore()) {
                Location l = new Location(Bukkit.getWorld("world"), getConfig().getDouble("Spawn.x"), getConfig().getDouble("Spawn.y"), getConfig().getDouble("Spawn.z"), getConfig().getLong("Spawn.yaw"), getConfig().getLong("Spawn.pitch"));
                e.getPlayer().teleport(l);
            }
        }
     
     
  6. You could add in a scheduled teleport. Sometimes the PlayerJoinEvent is executed, even if the player isn't completely on the server and this may cause errors :)

    Sorry for my bad english

    ~ CBPlugins
     
    • Agree Agree x 1