33import com .comphenix .protocol .PacketType ;
44import com .comphenix .protocol .events .PacketAdapter ;
55import com .comphenix .protocol .events .PacketEvent ;
6+ import com .comphenix .protocol .wrappers .EnumWrappers ;
67import com .comphenix .protocol .wrappers .PlayerInfoData ;
8+ import com .google .common .collect .Lists ;
79import org .bukkit .entity .EntityType ;
810import org .bukkit .event .EventHandler ;
911import org .bukkit .event .Listener ;
1012import org .bukkit .event .entity .EntitySpawnEvent ;
1113import org .bukkit .event .player .PlayerCommandPreprocessEvent ;
14+ import org .bukkit .event .world .ChunkUnloadEvent ;
1215import org .bukkit .plugin .java .JavaPlugin ;
1316
1417import java .util .HashSet ;
@@ -37,8 +40,7 @@ public void onPacketReceiving(PacketEvent ev) {
3740
3841 @ Override
3942 public void onPacketSending (PacketEvent ev ) {
40-
41- // these are needed or a notchian client will not join
43+ // these are needed or a notch-ian client will not join
4244 if (ev .getPacketType () == PacketType .Play .Server .KEEP_ALIVE ) return ;
4345 if (ev .getPacketType () == PacketType .Play .Server .LOGIN ) return ;
4446 if (ev .getPacketType () == PacketType .Play .Server .POSITION ) return ;
@@ -53,13 +55,23 @@ public void onPacketSending(PacketEvent ev) {
5355 // this keeps clients from showing server as lagging
5456 if (ev .getPacketType () == PacketType .Play .Server .UPDATE_TIME ) return ;
5557
56- // if we dont send this, player has default skin lol
58+ // if we don't send this, player has default skin lol
5759 if (ev .getPacketType () == PacketType .Play .Server .PLAYER_INFO ) {
58- for (List <PlayerInfoData > list : ev .getPacket ().getPlayerInfoDataLists ().getValues ()) {
59- if (list == null ) continue ;
60- list .removeIf (data -> data != null &&
61- !data .getProfile ().getUUID ().equals (ev .getPlayer ().getUniqueId ()));
60+ List <PlayerInfoData > newInfoData = Lists .newArrayList ();
61+
62+ // only show the player in the tab-list
63+ for (PlayerInfoData infoData : ev .getPacket ().getPlayerInfoDataLists ().read (1 )) {
64+ if (ev .getPlayer ().getUniqueId () != infoData .getProfileId ())
65+ continue ;
66+
67+ newInfoData .add (new PlayerInfoData (
68+ infoData .getProfile (),
69+ infoData .getLatency (),
70+ EnumWrappers .NativeGameMode .SPECTATOR ,
71+ infoData .getDisplayName ()));
6272 }
73+
74+ ev .getPacket ().getPlayerInfoDataLists ().write (1 , newInfoData );
6375 return ;
6476 }
6577
@@ -77,4 +89,9 @@ public void onCommand(PlayerCommandPreprocessEvent ev) {
7789 ev .setCancelled (true );
7890 }
7991
92+ @ EventHandler
93+ public void onChunkSave (ChunkUnloadEvent ev ) {
94+ ev .setSaveChunk (false );
95+ }
96+
8097}
0 commit comments