Per-Player Team Color

Discussion in 'Spigot Plugin Development' started by Swedz, Apr 29, 2017.

  1. I am looking to do something that will be handled through packets only, I want it to do something like this:

    Player #1 sees Player #2's name as red
    Player #1 sees Player #1's name as green
    Player #2 sees Player #1's name as red
    Player #2 sees Player #2's name as green

    Preferably, I would like to be able to do this all in ProtocolLib rather than using any NMS.
    Here's what I have for code so far:
    Code (Text):
    public TabColors() {
        new BukkitRunnable() {
            public void run() {
                for(Player lp1 : Bukkit.getOnlinePlayers()) {
                    for(Player lp2 : Bukkit.getOnlinePlayers()) {
                        if(lp1.getName().equals(lp2.getName())) {
                            //Set it to be green
                        } else {
                            //Set it to be red
                        }
                    }
                }
            }
        }.runTaskTimer(Main.instance(), 5, 5);
    }
    Simply just stumped on how to do it on the packet level.
    I have it in a BukkitRunnable because I plan on having other colors in the future (for spectators and such)
     
  2. What do you have against Scoreboards?
     
  3. Never said I have anything against Scoreboards, haha. I said I want players to see other players' names differently than another player would. Which to my knowledge, is not possible just using the Scoreboard classes.
     
  4. Hey man!

    I am also working on a project what requeres per team colors, After a lot of bug tracker and debugging I've found a way.

    Code (Text):
       
        public void setColor(){
            Scoreboard sb = p.getScoreboard();
            Team red = sb.getTeam("red");
            Team blue = sb.getTeam("blue");
           
            if (red == null){
                sb.registerNewTeam("red");
                red.setPrefix(ChatColor.RED + "");
            }else{
                red.unregister();
                sb.registerNewTeam("red");
                red.setPrefix(ChatColor.RED + "");
            }
            if (blue == null){
                sb.registerNewTeam("blue");
            }else{
                blue.unregister();
                sb.registerNewTeam("blue");
                blue.setPrefix(ChatColor.BLUE + "");
            }
            for (Player p : BLUEPLAYERS){
                blue.addPlayer(p);
                p.setScoreboard(sb);
            }
            for (Player p : REDPLAYERS){
                red.addPlayer(p);
                p.setScoreboard(sb);
            }
        }
     
     
  5. That would work, but it would get very messy very quickly if you have many different teams/colors on tab.

    What I'm doing isn't necessarily for teams, I would also like to use this for my faction server to show red for enemy factions, green for yours, etc. (and no, I'm not looking for a plugin to do this for me, my faction plugin is custom, it won't be compatible).
     
  6. I think it won't be as messy as you think, since it automatically organizes tab for you, it puts the red people by the red people etc. But be awere, when you do this, the displayname above people's head will also change!
     
  7. I was going for this too, and I meant the code would be messy. Not tab.
     
  8. Oh yeah, it will be a bit yeah, you can do also more methods though to make the code a bit cleaner, like make a method what requires a team, color, and the players. So that will save you like 20 lines of code and will it be looking a bit cleaner...
     
    • Agree Agree x 1
  9. I understand that, but I'm already using a Scoreboard API (ScoreboardLib) I don't think this system would be compatible with this API.

    But I'll double check that.
     
  10. ProtocolLib would be a dependency, why not use reflection to make it not version dependent? Preferable to lower dependencies in your plugin, especially if its for a custom server (or your own server), PM me if you need help I have worked in name tags section (and still have work).
     
  11. It's custom for my server, and I'll PM you.
     
  12. Trying to do the same thing with faction relation colors. Did you figure it out yet?
     
  13. Nope, DM'd Z3tr0nix and they didn't reply.
     
  14. If he isn't replying, you can DM me if you will.
     
  15. I was asleep -,-
     
    • Funny Funny x 1
  16. Check if the player is in sight and then change the color
     
  17. I'm not going for that, I'm looking to make it so people see enemy factions' players' names on tab as a different color. I'm getting help from Z3tr0nix.

    However, after revision of the code of the Scoreboard Library I am using I presume I may be able to just edit the scoreboard for the player specifically.
     
  18. Which scoreboard lib are you using?