public class TagUtil { private static Scoreboard scoreboard; static { TagUtil.scoreboard = new Scoreboard(); } public static void init() { TagUtil.scoreboard = new Scoreboard(); } public static void createBoard(final Player p) throws Exception { ScoreboardTeam team = null; if (TagUtil.scoreboard.getPlayerTeam(Bukkit.getPlayer(p.getName()).getName()) == null) { team = TagUtil.scoreboard.createTeam(p.getName()); } TagUtil.scoreboard.addPlayerToTeam(p.getName(), team.getName()); team.setPrefix(""); team.setDisplayName(""); team.setSuffix(""); final PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam(team, 0); ((CraftPlayer)p).getHandle().playerConnection.sendPacket((Packet)packet); for (final Player pp : Bukkit.getServer().getOnlinePlayers()) { if (pp != p) { ((CraftPlayer)pp).getHandle().playerConnection.sendPacket((Packet)packet); } } for (final Player pp : Bukkit.getServer().getOnlinePlayers()) { if (pp != p) { final ScoreboardTeam t = TagUtil.scoreboard.getTeam(pp.getName()); final PacketPlayOutScoreboardTeam packetShow = new PacketPlayOutScoreboardTeam(t, 0); ((CraftPlayer)p).getHandle().playerConnection.sendPacket((Packet)packetShow); } } } public static void updateBoard(final Player p) { final ScoreboardTeam team = TagUtil.scoreboard.getPlayerTeam(p.getName()); if (team == null) { return; } team.setPrefix(""); team.setDisplayName(""); team.setSuffix(""); for (final Player online : Bukkit.getServer().getOnlinePlayers()) { team.setSuffix(getValidPrefix(p, online)); team.setPrefix(getGuildPrefix(p, online)); final Guild g = GuildManager.getGuild(p); if (g != null) { final PermissionUser pu = PermissionsEx.getUser(p); final PacketPlayOutScoreboardTeam pa = new PacketPlayOutScoreboardTeam(team, 2); if (pu.inGroup("ROOT")) { ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)pa); return; } if (pu.inGroup("H@")) { ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)pa); return; } if (pu.inGroup("ADMIN")) { ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)pa); return; } if (pu.inGroup("MODERATOR")) { ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)pa); return; } if (pu.inGroup("HELPER")) { ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)pa); return; } if (pu.inGroup("YW")) { ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)pa); return; } if (pu.inGroup("TW")) { ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)pa); return; } if (pu.inGroup("VIP")) { ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)pa); return; } if (pu.inGroup("SVIP")) { ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)pa); return; } } final PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam(team, 2); ((CraftPlayer)online).getHandle().playerConnection.sendPacket((Packet)packet); } } public static void refreshAll() { for (final Player p : Bukkit.getOnlinePlayers()) { updateBoard(p); } } public static String getGuildPrefix(final Player get, final Player send) { String color = Config.TAG_COLOR_ENEMY; final Guild g = GuildManager.getGuild(get); final Guild o = GuildManager.getGuild(send); if (g != null && o != null) { if (g.equals(o)) { color = Config.TAG_COLOR_FRIEND; } else if (g.getAlly().contains(o.getTag())) { color = Config.TAG_COLOR_ALLIANCE; } } String tag = Config.TAG_COLOR_NOGUILD; if (g != null) { tag = color + g.getTag() + " &7"; } return ChatUtil.fixColor(tag); } public static String getValidPrefix(final Player get, final Player send) { final PermissionUser pu = PermissionsEx.getUser(get); final Guild gg = GuildManager.getGuild(get); if (pu.inGroup("ROOT")) { return ChatUtil.fixColor(" &4ROOT"); } if (pu.inGroup("H@")) { return ChatUtil.fixColor(" &4H@"); } if (pu.inGroup("TECHNIK")) { return ChatUtil.fixColor(" &4DEV"); } if (pu.inGroup("ADMIN")) { return ChatUtil.fixColor(" &4A"); } if (pu.inGroup("MODERATOR")) { return ChatUtil.fixColor(" &2M"); } if (pu.inGroup("HELPER")) { return ChatUtil.fixColor(" &3H"); } if (pu.inGroup("YT")) { return ChatUtil.fixColor(" &4Y&fT"); } if (pu.inGroup("TW")) { return ChatUtil.fixColor(" &dTW"); } if (pu.inGroup("VIP")) { return ChatUtil.fixColor(" &6VIP"); } if (pu.inGroup("SVIP")) { return ChatUtil.fixColor(" &5SVIP"); } return ChatUtil.fixColor(""); } public static void removeBoard(final Player p) { try { ScoreboardTeam team = null; if (TagUtil.scoreboard.getPlayerTeam(Bukkit.getPlayer(p.getName()).getName()) == null) { return; } team = TagUtil.scoreboard.getPlayerTeam(p.getName()); TagUtil.scoreboard.removePlayerFromTeam(p.getName(), team); final PacketPlayOutScoreboardTeam packet = new PacketPlayOutScoreboardTeam(team, 1); ((CraftPlayer)p).getHandle().playerConnection.sendPacket((Packet)packet); for (final Player pp : Bukkit.getServer().getOnlinePlayers()) { if (pp != p) { ((CraftPlayer)pp).getHandle().playerConnection.sendPacket((Packet)packet); } } for (final Player pp : Bukkit.getServer().getOnlinePlayers()) { if (pp != p) { final ScoreboardTeam t = TagUtil.scoreboard.getTeam(pp.getName()); final PacketPlayOutScoreboardTeam packetHide = new PacketPlayOutScoreboardTeam(t, 1); ((CraftPlayer)p).getHandle().playerConnection.sendPacket((Packet)packetHide); } } TagUtil.scoreboard.removeTeam(team); } catch (Exception ex) {} } }