Search code examples
javapluginsminecraftbukkit

Change Tablist names for each individual Player. (Spigot)


I am currently making a Minecraft SkyWars-Plugin and want to make a better looking tablist.


The Problem:

Lets say you have PlayerA and PlayerB. If PlayerA looks on the tablist, his name should be green and the name of PlayerB should be red.

But if PlayerB looks at his tablist, PlayerB's name should be green and PlayerA's name should be red.

So basically your own name should be marked as green (Color code 'a') and the opponents should have a red name (Color code 'c').


How do I achieve that? Do I send packages to each Player for his tablist? If so, which packages should/can I use?


Solution

  • Your problem can be solved in two ways.

    If you want to show per-player visible colors only in a tablist, you can use Player Info packet (specification https://wiki.vg/Protocol#Player_Info) for tablist content modification. Full valid code can be very volume, so i give you an algorithm (below I mean "packet" is Player Info packet):

    1. Send packet with action remove player (see wiki for action list) with PlayerA.uuid to PlayerA
    2. Send packet with action remove player with PlayerB.uuid to PlayerA
    3. Repeat 1 and 2, but send packets to playerB.
    4. Send packet with: action add player, PlayerA.uuid and colored PlayerA's display name for PlayerA (which in your case is green) to PlayerA.
    5. Send packet with: action add player, PlayerB.uuid and colored PlayerB's display name for PlayerA (which in your case is red) to PlayerA.
    6. Repeat 4 and 5, but send packets to playerB and invert colors.

    For packets management you can use ProtocolLib plugin.

    If you want to show per-player visible colors in tablist and above the head, you can use similar algorithm with scoreboard teams packets. Or you can try to find implemented plugin api for per-player visible prefixes.