Colored Tablist

Discussion in 'Spigot Plugin Development' started by MaxNatural, May 18, 2016.

  1. I am trying to make it so players have colored tab list if they have certain permissions.

    Here is my code.
    Code (Text):
        public void onPlayerJoinEvent(PlayerJoinEvent e) {
            Player p = e.getPlayer();
       
            if ((p.hasPermission("ch.prefix.owner")) || (p.isOp())) {
                e.getPlayer().setPlayerListName(ChatColor.RED + "" + ChatColor.BOLD + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.tab.admin")) {
                e.getPlayer().setPlayerListName(ChatColor.DARK_RED + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.dev")) {
                e.getPlayer().setPlayerListName(ChatColor.YELLOW + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.manager")) {
                e.getPlayer().setPlayerListName(ChatColor.GOLD + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.mod")) {
                e.getPlayer().setPlayerListName(ChatColor.GREEN + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.jrmod")) {
                e.getPlayer().setPlayerListName(ChatColor.DARK_GREEN + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.craftlord")) {
                e.getPlayer().setPlayerListName(ChatColor.DARK_PURPLE + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefxi.premium")) {
                e.getPlayer().setPlayerListName(ChatColor.AQUA + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.vip")) {
                e.getPlayer().setPlayerListName(ChatColor.DARK_AQUA + e.getPlayer().getName());
            } else if (p.hasPermission("")) {
                e.getPlayer().setPlayerListName(ChatColor.GRAY + e.getPlayer().getName());
            }
    }
    }
     
    All events are registered as well.
     
  2. .... I knew that..... It still doesn't work for me for some reason :?
     
  3. Post your onEnable method and is your class implementing Listener
     
  4. @iCodeTits

    Code (Text):
    public class TabList implements Listener{
     
        public TabList(Core core) {
            // TODO Auto-generated constructor stub
        }

        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent e) {
            Player p = e.getPlayer();
     
            if ((p.hasPermission("ch.prefix.owner")) || (p.isOp())) {
                e.getPlayer().setPlayerListName(ChatColor.RED + "" + ChatColor.BOLD + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.tab.admin")) {
                e.getPlayer().setPlayerListName(ChatColor.DARK_RED + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.dev")) {
                e.getPlayer().setPlayerListName(ChatColor.YELLOW + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.manager")) {
                e.getPlayer().setPlayerListName(ChatColor.GOLD + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.mod")) {
                e.getPlayer().setPlayerListName(ChatColor.GREEN + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.jrmod")) {
                e.getPlayer().setPlayerListName(ChatColor.DARK_GREEN + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.craftlord")) {
                e.getPlayer().setPlayerListName(ChatColor.DARK_PURPLE + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefxi.premium")) {
                e.getPlayer().setPlayerListName(ChatColor.AQUA + e.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.vip")) {
                e.getPlayer().setPlayerListName(ChatColor.DARK_AQUA + e.getPlayer().getName());
            } else if (p.hasPermission("")) {
                e.getPlayer().setPlayerListName(ChatColor.GRAY + e.getPlayer().getName());
            }
    }
    }
     
    Code (Text):
            Bukkit.getServer().getPluginManager().registerEvents(new TabList(this), this);
     
  5. Just use colored tags on bukkit
     
  6. that code
     
    • Optimistic Optimistic x 1
  7. I'm very confused
     
  8. Try it with § and not with ChatColor.***
     
  9. Code (Text):
        public TabList(Core core) {
            // TODO Auto-generated constructor stub
        }

        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent e) {
            Player p = e.getPlayer();
       
            if ((p.hasPermission("ch.prefix.owner")) || (p.isOp())) {
                p.getPlayer().setPlayerListName("§c§l" + p.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.tab.admin")) {
                p.getPlayer().setPlayerListName("§4" + p.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.dev")) {
                p.getPlayer().setPlayerListName("§e" + p.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.manager")) {
                p.getPlayer().setPlayerListName("§6" + p.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.mod")) {
                p.getPlayer().setPlayerListName("§a" + p.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.jrmod")) {
                p.getPlayer().setPlayerListName("§2" + p.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.craftlord")) {
                p.getPlayer().setPlayerListName("§5" + p.getPlayer().getName());
            } else if (p.hasPermission("ch.prefxi.premium")) {
                p.getPlayer().setPlayerListName("§b" + p.getPlayer().getName());
            } else if (p.hasPermission("ch.prefix.vip")) {
                p.getPlayer().setPlayerListName("§3" + p.getPlayer().getName());
            } else if (p.hasPermission("")) {
                p.getPlayer().setPlayerListName("§7" + p.getPlayer().getName());
            }
    }
    }
     
    Still doesn't work. :?
     
  10. Registered event in main class?
     
  11. Yup.
    Code (Text):
            Bukkit.getServer().getPluginManager().registerEvents(new TabList(this), this);
     
  12. I don't personally use the this under TabList(), did you get a java error of.you remove it?
     
  13. I did it like that with all my other event classes and those work.
     
  14. Try if statements instead of else if
     
  15. Tried this and still didn't work :?

    Code (Text):
    public class TabList implements Listener{
       
        Core plugin;

        public TabList(Core core) {
            // TODO Auto-generated constructor stub
        }

        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent e) {
            Player p = e.getPlayer();
       
            if ((p.hasPermission("ch.prefix.owner")) || (p.isOp())) {
                p.getPlayer().setPlayerListName("§c§l" + p.getPlayer().getName());
            } if (p.hasPermission("ch.prefix.tab.admin")) {
                p.getPlayer().setPlayerListName("§4" + p.getPlayer().getName());
            } if (p.hasPermission("ch.prefix.dev")) {
                p.getPlayer().setPlayerListName("§e" + p.getPlayer().getName());
            } if (p.hasPermission("ch.prefix.manager")) {
                p.getPlayer().setPlayerListName("§6" + p.getPlayer().getName());
            } if (p.hasPermission("ch.prefix.mod")) {
                p.getPlayer().setPlayerListName("§a" + p.getPlayer().getName());
            } if (p.hasPermission("ch.prefix.jrmod")) {
                p.getPlayer().setPlayerListName("§2" + p.getPlayer().getName());
            } if (p.hasPermission("ch.prefix.craftlord")) {
                p.getPlayer().setPlayerListName("§5" + p.getPlayer().getName());
            } if (p.hasPermission("ch.prefxi.premium")) {
                p.getPlayer().setPlayerListName("§b" + p.getPlayer().getName());
            } if (p.hasPermission("ch.prefix.vip")) {
                p.getPlayer().setPlayerListName("§3" + p.getPlayer().getName());
            } if (p.hasPermission("")) {
                p.getPlayer().setPlayerListName("§7" + p.getPlayer().getName());
            }
    }
    }
     
     
  16. Test and see if it's event getting past the if statements using some debugging (test if the event is even being fired)
     
  17. It worked before all the if statements but not in the if statements
     
  18. Remove the || p.isOp() part on all of them and it should work.
     
  19. For the last condition replace esle if to else. ;)