How to display offline player name in a team scoreboard?

Discussion in 'Plugin Development' started by darknoneee, Apr 26, 2023.

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


    Hello everyone,

    I'm doing a team system and it have a scoreboard that displays all the teams members, but, when a player logs out, it will return a null value, so i can't display the player name in the scoreboard. How could i do it?

    Sorry for my bad english.
  2. Offline


    Hello. You can simply use OfflinePlayer instead of Player for when they are offline. OfflinePlayer#getName will return their name. When online, you can convert OfflinePlayer to Player using OfflinePlayer#getPlayer. Hope this helped!
  3. Offline


    I tried it, but still not working.

    Here's my code:

                    Objective.setDisplayName(Team.getTeam(players) + " (HP%)");
                    for (UUID team : Team.getMembers()) {
                        if (Team.members.get(team).equalsIgnoreCase(Team.getTeam(players))) {
                            OfflinePlayer mates = Bukkit.getPlayer(team);
                            if (mates!=null) {
                                double hp = ((CraftPlayer) mates).getHealth() / 2.0D * 10.0D;
                                Score Var = Objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + mates.getName()));
                                Var.setScore((int) hp);
                            } else {
                                Score Var = Objective.getScore(Bukkit.getOfflinePlayer("" + mates.getName()));


  4. Offline


    Hello again,

    The reason it is not working is because you are checking if "mates" is NULL, and then you are getting the Player by the Null variable.. getPlayer# returns null if they are offline.
    This should be:
    Last edited: Apr 27, 2023
    darknoneee likes this.
  5. Offline


    It works! Thank you so much :D
    mehboss likes this.
Thread Status:
Not open for further replies.

Share This Page