How do I count players individually?

Discussion in 'Plugin Development' started by PumpMelon, Aug 15, 2016.

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

    PumpMelon

    Hello,
    I was wondering how to count players by the # they are when they join...
    for example
    Hello Bob you are the (blank)th person on the server!
    Bob would always remain the same number, as it would go from the order of when they first joined the server.

    Thanks for the help!
     
  2. Offline

    WestBurst

    Would you like a coded plugin?
     
  3. Online

    timtower Administrator Administrator Moderator

    @WestBurst This is plugin development so a guide to what to do is better.
    @PumpMelon depends on your storage method.
    MySQL has an auto incrementing index (if you want to use a database)
    Configs key value pair.
     
  4. @PumpMelon There are a few ways, I can't remember if Getofflineplayers is still a thing but you can (IIRC) get the size of that. Or if you store any data about all your players use that or as @timtower said if you have MySQL you can wait till the player is added then get their id (+1) or count them and add one.
     
  5. Offline

    Zombie_Striker

    It still exist. Bukkit.getOfflinePlayers() returns a Collection of offline players. Getting the size of the collection will return the amount of other players (including that new player) who have joined that server.

    Use OfflinePlayer#hasJoinedBefore if you want to see if a player has joined before. Since the above method only works as long as they are the last person who joined, you will need to store their ID somewhere (such as a config or hashmap) and retrieve that number when they join.
     
Thread Status:
Not open for further replies.

Share This Page