Skip to content

Commit 039c57f

Browse files
Improve player info packet handling
1 parent f791808 commit 039c57f

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

server/src/main/java/com/soulfiremc/server/protocol/bot/SessionDataManager.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -521,29 +521,41 @@ public void onPlayerListHeaderFooter(ClientboundTabListPacket packet) {
521521

522522
@EventHandler
523523
public void onPlayerListUpdate(ClientboundPlayerInfoUpdatePacket packet) {
524-
for (var update : packet.getEntries()) {
525-
var entry = playerListState.entries().computeIfAbsent(update.getProfileId(), k -> update);
524+
if (packet.getActions().contains(PlayerListEntryAction.ADD_PLAYER)) {
525+
for (var entry : packet.getEntries()) {
526+
playerListState.entries().putIfAbsent(entry.getProfileId(), entry);
527+
}
528+
}
529+
530+
for (var newEntry : packet.getEntries()) {
531+
var entry = playerListState.entries().get(newEntry.getProfileId());
532+
if (entry == null) {
533+
continue;
534+
}
535+
526536
for (var action : packet.getActions()) {
527537
SFHelpers.mustSupply(() -> switch (action) {
528-
case ADD_PLAYER -> () -> entry.setProfile(update.getProfile());
538+
case ADD_PLAYER -> () -> {
539+
// Don't handle, just like vanilla
540+
};
529541
case INITIALIZE_CHAT -> () -> {
530-
entry.setSessionId(update.getSessionId());
531-
entry.setExpiresAt(update.getExpiresAt());
532-
entry.setKeySignature(update.getKeySignature());
533-
entry.setPublicKey(update.getPublicKey());
542+
entry.setSessionId(newEntry.getSessionId());
543+
entry.setExpiresAt(newEntry.getExpiresAt());
544+
entry.setKeySignature(newEntry.getKeySignature());
545+
entry.setPublicKey(newEntry.getPublicKey());
534546
};
535547
case UPDATE_GAME_MODE -> () -> {
536-
if (entry.getGameMode() != update.getGameMode() && localPlayer != null && update.getProfileId().equals(localPlayer.uuid())) {
537-
localPlayer.onGameModeChanged(update.getGameMode());
548+
if (entry.getGameMode() != newEntry.getGameMode() && localPlayer != null && newEntry.getProfileId().equals(localPlayer.uuid())) {
549+
localPlayer.onGameModeChanged(newEntry.getGameMode());
538550
}
539551

540-
entry.setGameMode(update.getGameMode());
552+
entry.setGameMode(newEntry.getGameMode());
541553
};
542-
case UPDATE_LISTED -> () -> entry.setListed(update.isListed());
543-
case UPDATE_LATENCY -> () -> entry.setLatency(update.getLatency());
544-
case UPDATE_DISPLAY_NAME -> () -> entry.setDisplayName(update.getDisplayName());
545-
case UPDATE_HAT -> () -> entry.setShowHat(update.isShowHat());
546-
case UPDATE_LIST_ORDER -> () -> entry.setListOrder(update.getListOrder());
554+
case UPDATE_LISTED -> () -> entry.setListed(newEntry.isListed());
555+
case UPDATE_LATENCY -> () -> entry.setLatency(newEntry.getLatency());
556+
case UPDATE_DISPLAY_NAME -> () -> entry.setDisplayName(newEntry.getDisplayName());
557+
case UPDATE_HAT -> () -> entry.setShowHat(newEntry.isShowHat());
558+
case UPDATE_LIST_ORDER -> () -> entry.setListOrder(newEntry.getListOrder());
547559
});
548560
}
549561
}

0 commit comments

Comments
 (0)