@@ -245,34 +245,28 @@ public void register() {
245
245
final int count = wrapper .read (Types .VAR_INT );
246
246
for (int i = 0 ; i < count ; i ++) {
247
247
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 ;
253
255
254
- GameProfile . Property [] properties = wrapper . read ( Types . PROFILE_PROPERTY_ARRAY );
256
+ final GameProfileStorage . GameProfile gameProfile = gameProfileStorage . put ( uuid , name , displayName , ping , gamemode );
255
257
for (GameProfile .Property property : properties ) {
256
258
gameProfile .properties .add (new GameProfileStorage .Property (property .name (), property .value (), property .signature ()));
257
259
}
258
260
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
-
268
261
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 ());
270
263
playerInfo .write (Types .BOOLEAN , true );
271
264
playerInfo .write (Types .SHORT , (short ) ping );
272
265
playerInfo .scheduleSend (Protocol1_8To1_7_6_10 .class );
273
- } else if (action == 1 ) {
266
+ } else if (action == 1 ) { // Update game mode
274
267
final int gamemode = wrapper .read (Types .VAR_INT );
275
- GameProfileStorage .GameProfile gameProfile = gameProfileStorage .get (uuid );
268
+
269
+ final GameProfileStorage .GameProfile gameProfile = gameProfileStorage .get (uuid );
276
270
if (gameProfile == null || gameProfile .gamemode == gamemode ) {
277
271
continue ;
278
272
}
@@ -303,52 +297,60 @@ public void register() {
303
297
}
304
298
305
299
gameProfile .gamemode = gamemode ;
306
- } else if (action == 2 ) {
300
+ } else if (action == 2 ) { // Update latency
307
301
final int ping = wrapper .read (Types .VAR_INT );
308
302
309
303
final GameProfileStorage .GameProfile gameProfile = gameProfileStorage .get (uuid );
310
- if (gameProfile == null ) {
304
+ if (gameProfile == null || gameProfile . ping == ping ) {
311
305
continue ;
312
306
}
307
+
313
308
gameProfile .ping = ping ;
314
309
315
310
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 ());
317
312
packet .write (Types .BOOLEAN , true );
318
313
packet .write (Types .SHORT , (short ) ping );
319
314
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
+
321
322
JsonElement displayNameComponent = wrapper .read (Types .OPTIONAL_COMPONENT );
322
323
String displayName = displayNameComponent != null ? ChatUtil .jsonToLegacy (displayNameComponent ) : null ;
323
324
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
+ }
326
329
327
330
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 ());
329
332
playerInfo .write (Types .BOOLEAN , false );
330
- playerInfo .write (Types .SHORT , (short ) gameProfile . ping );
333
+ playerInfo .write (Types .SHORT , (short ) 0 );
331
334
playerInfo .scheduleSend (Protocol1_8To1_7_6_10 .class );
332
335
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 );
336
337
337
338
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 ());
339
340
playerInfo .write (Types .BOOLEAN , true );
340
341
playerInfo .write (Types .SHORT , (short ) gameProfile .ping );
341
342
playerInfo .scheduleSend (Protocol1_8To1_7_6_10 .class );
342
- } else if (action == 4 ) {
343
+ } else if (action == 4 ) { // Remove player
343
344
final GameProfileStorage .GameProfile gameProfile = gameProfileStorage .remove (uuid );
345
+
344
346
if (gameProfile == null ) {
345
347
continue ;
346
348
}
347
349
348
350
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 ());
350
352
playerInfo .write (Types .BOOLEAN , false );
351
- playerInfo .write (Types .SHORT , (short ) gameProfile . ping );
353
+ playerInfo .write (Types .SHORT , (short ) 0 );
352
354
playerInfo .scheduleSend (Protocol1_8To1_7_6_10 .class );
353
355
}
354
356
}
0 commit comments