Organise the player tablist / Colored nameplates

Discussion in 'Plugin Help/Development/Requests' started by maux, Apr 25, 2016.

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

    maux

    Introduction
    Have you ever wondered how to organise the tab list/color the nameplates like most major servers? Most people have mentioned the use of PacketPlayOutPlayerInfo and a bunch of other creative ways, however I decided to go the all Bukkit route. Here is how you do such things!

    Tutorial
    So first, you want to get the Team class from Bukkit:
    Code:
        private Team team;
    After that, you want to make a constructer for the class like such:
    Code:
    public PlayerNameplate(String plateName) {
            Scoreboard board = Bukkit.getServer().getScoreboardManager().getMainScoreboard();
            Team team = board.getTeam(plateName); // plateName = teamName
            if (board.getTeam(plateName) != null) { // checking if the team exists
                this.team = team;
            } else {
                b.registerNewTeam(plateName); // registers the team if it doesn't exist
                this.team = team;
            }
        }
    Now, here is where you can set the player's name tag. Make sure you don't put extraneous characters / characters > 16.
    Code:
    team.addPlayer(player); // adds the player to the team that has the nameplate
    team.setPrefix(prefix); // sets the nameplate before the name
    team.setSuffix(suffix); // sets the nameplate after the name
    How the Minecraft team system works is that it changes the tab list as well. It orders the team names in alphabetical order. So the "plateName" part of the constructer is critical. So I used this code as an example in one of my projects. Here is the code:
    Code:
    if (gamePlayer.hasGroup(Group.AMBER)) {
    gamePlayer.setName("§e" + gamePlayer.getName());
    gamePlayer.setNameplate("j", "§e", ""); // As you can see, "j" is going to be lower than "h" because that's
                                                                             // how alphabetical order works
    } else if (gamePlayer.hasGroup(Group.AMETHYST)) {
    gamePlayer.setName("§d" + gamePlayer.getName());
    gamePlayer.setNameplate("h", "§d", ""); // The plate's name is "h." This will result in team "h" being higher
                                                                              // than team "j."
    }
    Now, let's put this to the test!:
    Screenshots (open)

    Screenshot from maux (he is in the team "h"):
    [​IMG]
    (if that image doesn't show, click: http://imgur.com/9xbB4Ki)
    Screenshot from xdbfplaysgamesx (he is in the team "j"):
    [​IMG]
    (if that image also doesn't show, click: http://imgur.com/mrbMwG1)

    As you can see, it works!

    End Comments
    Thank you for taking your time reading this. I sincerely hope you learned something new. I am not good at explaining or doing tutorials. In fact, this is my first. I really wanted to show the Bukkit community, however, how to use such a cool feature to your advantage. There is more to things behind Bukkit's code then you think. (; If there are any problems you see, or improvements I should put upon this code or myself, please do tell me. I do want constructive criticism and excellent questions.
     
    crzassassin likes this.
  2. Offline

    WolfMage1

    @maux
    Why not just do
    Code:
    if(team==null){ //You're assigning it anyway .
        board.registerNewTeam(plate);
    }
    this.team=team;
    
     
  3. Offline

    maux

    That works! I just took the weird route. My bad
     
  4.  
Thread Status:
Not open for further replies.

Share This Page