@@ -245,34 +245,28 @@ public void register() {
245245 final int count = wrapper .read (Types .VAR_INT );
246246 for (int i = 0 ; i < count ; i ++) {
247247 UUID uuid = wrapper .read (Types .UUID );
248- if (action == 0 ) {
249- String name = wrapper .read (Types .STRING );
250-
251- GameProfileStorage .GameProfile gameProfile = gameProfileStorage .get (uuid );
252- if (gameProfile == null ) gameProfile = gameProfileStorage .put (uuid , name );
248+ if (action == 0 ) { // Add player
249+ final String name = wrapper .read (Types .STRING );
250+ final GameProfile .Property [] properties = wrapper .read (Types .PROFILE_PROPERTY_ARRAY );
251+ final int gamemode = wrapper .read (Types .VAR_INT );
252+ final int ping = wrapper .read (Types .VAR_INT );
253+ final JsonElement displayNameComponent = wrapper .read (Types .OPTIONAL_COMPONENT );
254+ final String displayName = displayNameComponent != null ? ChatUtil .jsonToLegacy (displayNameComponent ) : null ;
253255
254- GameProfile . Property [] properties = wrapper . read ( Types . PROFILE_PROPERTY_ARRAY );
256+ final GameProfileStorage . GameProfile gameProfile = gameProfileStorage . put ( uuid , name , displayName , ping , gamemode );
255257 for (GameProfile .Property property : properties ) {
256258 gameProfile .properties .add (new GameProfileStorage .Property (property .name (), property .value (), property .signature ()));
257259 }
258260
259- int gamemode = wrapper .read (Types .VAR_INT );
260- int ping = wrapper .read (Types .VAR_INT );
261- gameProfile .ping = ping ;
262- gameProfile .gamemode = gamemode ;
263- JsonElement displayName = wrapper .read (Types .OPTIONAL_COMPONENT );
264- if (displayName != null ) {
265- gameProfile .setDisplayName (ChatUtil .jsonToLegacy (displayName ));
266- }
267-
268261 final PacketWrapper playerInfo = PacketWrapper .create (ClientboundPackets1_7_2_5 .PLAYER_INFO , wrapper .user ());
269- playerInfo .write (Types .STRING , gameProfile .getDisplayName ());
262+ playerInfo .write (Types .STRING , gameProfile .getLegacyDisplayName ());
270263 playerInfo .write (Types .BOOLEAN , true );
271264 playerInfo .write (Types .SHORT , (short ) ping );
272265 playerInfo .scheduleSend (Protocol1_8To1_7_6_10 .class );
273- } else if (action == 1 ) {
266+ } else if (action == 1 ) { // Update game mode
274267 final int gamemode = wrapper .read (Types .VAR_INT );
275- GameProfileStorage .GameProfile gameProfile = gameProfileStorage .get (uuid );
268+
269+ final GameProfileStorage .GameProfile gameProfile = gameProfileStorage .get (uuid );
276270 if (gameProfile == null || gameProfile .gamemode == gamemode ) {
277271 continue ;
278272 }
@@ -303,52 +297,60 @@ public void register() {
303297 }
304298
305299 gameProfile .gamemode = gamemode ;
306- } else if (action == 2 ) {
300+ } else if (action == 2 ) { // Update latency
307301 final int ping = wrapper .read (Types .VAR_INT );
308302
309303 final GameProfileStorage .GameProfile gameProfile = gameProfileStorage .get (uuid );
310- if (gameProfile == null ) {
304+ if (gameProfile == null || gameProfile . ping == ping ) {
311305 continue ;
312306 }
307+
313308 gameProfile .ping = ping ;
314309
315310 PacketWrapper packet = PacketWrapper .create (ClientboundPackets1_7_2_5 .PLAYER_INFO , wrapper .user ());
316- packet .write (Types .STRING , gameProfile .getDisplayName ());
311+ packet .write (Types .STRING , gameProfile .getLegacyDisplayName ());
317312 packet .write (Types .BOOLEAN , true );
318313 packet .write (Types .SHORT , (short ) ping );
319314 packet .scheduleSend (Protocol1_8To1_7_6_10 .class );
320- } else if (action == 3 ) {
315+ } else if (action == 3 ) { // Update display name
316+ GameProfileStorage .GameProfile gameProfile = gameProfileStorage .get (uuid );
317+
318+ if (gameProfile == null ) {
319+ continue ;
320+ }
321+
321322 JsonElement displayNameComponent = wrapper .read (Types .OPTIONAL_COMPONENT );
322323 String displayName = displayNameComponent != null ? ChatUtil .jsonToLegacy (displayNameComponent ) : null ;
323324
324- GameProfileStorage .GameProfile gameProfile = gameProfileStorage .get (uuid );
325- if (gameProfile == null || gameProfile .displayName == null && displayName == null ) continue ;
325+ // Don't update if display name is the same
326+ if (Objects .equals (gameProfile .displayName , displayName )) {
327+ continue ;
328+ }
326329
327330 PacketWrapper playerInfo = PacketWrapper .create (ClientboundPackets1_7_2_5 .PLAYER_INFO , wrapper .user ());
328- playerInfo .write (Types .STRING , gameProfile .getDisplayName ());
331+ playerInfo .write (Types .STRING , gameProfile .getLegacyDisplayName ());
329332 playerInfo .write (Types .BOOLEAN , false );
330- playerInfo .write (Types .SHORT , (short ) gameProfile . ping );
333+ playerInfo .write (Types .SHORT , (short ) 0 );
331334 playerInfo .scheduleSend (Protocol1_8To1_7_6_10 .class );
332335
333- if (gameProfile .displayName == null && displayName != null || gameProfile .displayName != null && displayName == null || !gameProfile .displayName .equals (displayName )) {
334- gameProfile .setDisplayName (displayName );
335- }
336+ gameProfile .setDisplayName (displayName );
336337
337338 playerInfo = PacketWrapper .create (ClientboundPackets1_7_2_5 .PLAYER_INFO , wrapper .user ());
338- playerInfo .write (Types .STRING , gameProfile .getDisplayName ());
339+ playerInfo .write (Types .STRING , gameProfile .getLegacyDisplayName ());
339340 playerInfo .write (Types .BOOLEAN , true );
340341 playerInfo .write (Types .SHORT , (short ) gameProfile .ping );
341342 playerInfo .scheduleSend (Protocol1_8To1_7_6_10 .class );
342- } else if (action == 4 ) {
343+ } else if (action == 4 ) { // Remove player
343344 final GameProfileStorage .GameProfile gameProfile = gameProfileStorage .remove (uuid );
345+
344346 if (gameProfile == null ) {
345347 continue ;
346348 }
347349
348350 final PacketWrapper playerInfo = PacketWrapper .create (ClientboundPackets1_7_2_5 .PLAYER_INFO , wrapper .user ());
349- playerInfo .write (Types .STRING , gameProfile .getDisplayName ());
351+ playerInfo .write (Types .STRING , gameProfile .getLegacyDisplayName ());
350352 playerInfo .write (Types .BOOLEAN , false );
351- playerInfo .write (Types .SHORT , (short ) gameProfile . ping );
353+ playerInfo .write (Types .SHORT , (short ) 0 );
352354 playerInfo .scheduleSend (Protocol1_8To1_7_6_10 .class );
353355 }
354356 }
0 commit comments