- 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 createBoard(final OfflinePlayer 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);
- }
- }
- }
- @SuppressWarnings("rawtypes")
- public static void updateBoard(final Player p) {
- if (TagUtil.scoreboard.getPlayerTeam(Bukkit.getPlayer(p.getName()).getName()) == null) {
- return;
- }
- final ScoreboardTeam team = TagUtil.scoreboard.getPlayerTeam(p.getName());
- team.setDisplayName("");
- team.setSuffix("");
- for (final Player online : Bukkit.getOnlinePlayers()) {
- team.setPrefix(getValidPrefix(p, online));
- final PermissionUser pu = PermissionsEx.getUser(p);
- final PacketPlayOutScoreboardTeam pa = new PacketPlayOutScoreboardTeam(team, 2);
- if (pu.inGroup("WLASCICIEL")) {
- ((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 getValidPrefix(final Player get, final Player send) {
- final PermissionUser pu = PermissionsEx.getUser(get);
- String prefix = "";
- if (pu.inGroup("WLASCICIEL")) {
- return ChatUtil.fixColor("&4WLASCICIEL&7 ");
- }
- return ChatUtil.fixColor(String.valueOf(String.valueOf(String.valueOf(prefix)));
- }
- 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) {}
- }
- }