public static void clearTab(Player p) { if (!p.isOnline()) return; int a; String msg; WrappedGameProfile gameProfile; if (protocolManager.getProtocolVersion(p) >= 47) { TabHolder47 tabold = (TabHolder47) playerTabLast47.get(p.getName()); if (tabold != null) { for (int b = 0; b < tabold.maxv; b++) { for (a = 0; a < tabold.maxh; a++) { msg = tabold.tabs[a][b]; gameProfile = tabold.tabGameProfiles[a][b]; addPacket( p, msg.substring(0, Math.min(msg.length(), 16)), getSlotId(b, a), gameProfile, false, 0); } } } } else { TabHolder tabold = (TabHolder) playerTabLast.get(p.getName()); if (tabold != null) { for (String[] s : tabold.tabs) { for (String message : s) { if (message != null) { addPacket(p, message.substring(0, Math.min(message.length(), 16)), 0, null, false, 0); } } } } } }
public static void updatePlayer(Player p) { if (!p.isOnline()) { return; } r = 0; e = 0; if (protocolManager.getProtocolVersion(p) >= 47) { TabObject47 tabo = (TabObject47) playerTab47.get(p.getName()); TabHolder47 tab = tabo.getTab(); if (tab == null) { return; } clearTab(p); for (int b = 0; b < tab.maxv; b++) { for (int a = 0; a < tab.maxh; a++) { if (tab.tabs[a][b] == null) { tab.tabs[a][b] = nextNull(); } String msg = tab.tabs[a][b]; int ping = tab.tabPings[a][b]; WrappedGameProfile gameProfile = tab.tabGameProfiles[a][b]; addPacket( p, msg == null ? " " : msg.substring(0, Math.min(msg.length(), 16)), getSlotId(b, a), gameProfile, true, ping); } } flushPackets(p, tab.getCopy()); } else { TabObject tabo = (TabObject) playerTab.get(p.getName()); TabHolder tab = tabo.getTab(); if (tab == null) { return; } clearTab(p); for (int b = 0; b < tab.maxv; b++) { for (int a = 0; a < tab.maxh; a++) { if (tab.tabs[a][b] == null) { tab.tabs[a][b] = nextNull(); } String msg = tab.tabs[a][b]; int ping = tab.tabPings[a][b]; addPacket( p, msg == null ? " " : msg.substring(0, Math.min(msg.length(), 16)), 0, null, true, ping); } } flushPackets(p, tab.getCopy()); } }
public static void resetTabList(Player p) { int a = 0; int b = 0; for (Player pl : Bukkit.getOnlinePlayers()) { setTabString(Bukkit.getPluginManager().getPlugin("TabAPI"), p, a, b, pl.getPlayerListName()); b++; if (b > getHorizSize(protocolManager.getProtocolVersion(pl))) { b = 0; a++; } } }
private static void addPacket( Player p, String msg, int slotId, WrappedGameProfile gameProfile, boolean b, int ping) { PacketContainer message = protocolManager.createPacket(PacketType.Play.Server.PLAYER_INFO); String nameToShow = (!shuttingdown ? "$" : "") + msg; if (protocolManager.getProtocolVersion(p) >= 47) { nameToShow = (!shuttingdown ? "$" : "") + ChatColor.DARK_GRAY + slotId + ": " + msg.substring(0, Math.min(msg.length(), 10)); } EnumWrappers.PlayerInfoAction action; if (b) { action = EnumWrappers.PlayerInfoAction.ADD_PLAYER; } else { action = EnumWrappers.PlayerInfoAction.REMOVE_PLAYER; } message.getPlayerInfoAction().write(0, action); List<PlayerInfoData> pInfoData = new ArrayList<PlayerInfoData>(); if (gameProfile != null) { pInfoData.add( new PlayerInfoData( gameProfile .withName(nameToShow.substring(1)) .withId( UUID.nameUUIDFromBytes( ("OfflinePlayer:" + nameToShow.substring(1)).getBytes(Charsets.UTF_8)) .toString()), ping, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(nameToShow))); } else { pInfoData.add( new PlayerInfoData( new WrappedGameProfile( UUID.nameUUIDFromBytes( ("OfflinePlayer:" + nameToShow.substring(1)).getBytes(Charsets.UTF_8)), nameToShow.substring(1)), ping, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(nameToShow))); } message.getPlayerInfoDataLists().write(0, pInfoData); List<PacketContainer> packetList = cachedPackets.get(p); if (packetList == null) { packetList = new ArrayList<PacketContainer>(); cachedPackets.put(p, packetList); } packetList.add(message); }
public static void setTabString( Plugin plugin, Player p, int x, int y, String msg, int ping, WrappedGameProfile gameProfile) { try { if (protocolManager.getProtocolVersion(p) >= 47) { TabObject47 tabo = getTab47(p); tabo.setTab(plugin, x, y, msg, ping, gameProfile); playerTab47.put(p.getName(), tabo); } else { TabObject tabo = getTab(p); tabo.setTab(plugin, x, y, msg, ping); playerTab.put(p.getName(), tabo); } } catch (Exception ex) { ex.printStackTrace(); } }