Skip to content

Commit

Permalink
Improve player info packet handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Feb 2, 2025
1 parent f791808 commit 039c57f
Showing 1 changed file with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,29 +521,41 @@ public void onPlayerListHeaderFooter(ClientboundTabListPacket packet) {

@EventHandler
public void onPlayerListUpdate(ClientboundPlayerInfoUpdatePacket packet) {
for (var update : packet.getEntries()) {
var entry = playerListState.entries().computeIfAbsent(update.getProfileId(), k -> update);
if (packet.getActions().contains(PlayerListEntryAction.ADD_PLAYER)) {
for (var entry : packet.getEntries()) {
playerListState.entries().putIfAbsent(entry.getProfileId(), entry);
}
}

for (var newEntry : packet.getEntries()) {
var entry = playerListState.entries().get(newEntry.getProfileId());
if (entry == null) {
continue;
}

for (var action : packet.getActions()) {
SFHelpers.mustSupply(() -> switch (action) {
case ADD_PLAYER -> () -> entry.setProfile(update.getProfile());
case ADD_PLAYER -> () -> {
// Don't handle, just like vanilla
};
case INITIALIZE_CHAT -> () -> {
entry.setSessionId(update.getSessionId());
entry.setExpiresAt(update.getExpiresAt());
entry.setKeySignature(update.getKeySignature());
entry.setPublicKey(update.getPublicKey());
entry.setSessionId(newEntry.getSessionId());
entry.setExpiresAt(newEntry.getExpiresAt());
entry.setKeySignature(newEntry.getKeySignature());
entry.setPublicKey(newEntry.getPublicKey());
};
case UPDATE_GAME_MODE -> () -> {
if (entry.getGameMode() != update.getGameMode() && localPlayer != null && update.getProfileId().equals(localPlayer.uuid())) {
localPlayer.onGameModeChanged(update.getGameMode());
if (entry.getGameMode() != newEntry.getGameMode() && localPlayer != null && newEntry.getProfileId().equals(localPlayer.uuid())) {
localPlayer.onGameModeChanged(newEntry.getGameMode());
}

entry.setGameMode(update.getGameMode());
entry.setGameMode(newEntry.getGameMode());
};
case UPDATE_LISTED -> () -> entry.setListed(update.isListed());
case UPDATE_LATENCY -> () -> entry.setLatency(update.getLatency());
case UPDATE_DISPLAY_NAME -> () -> entry.setDisplayName(update.getDisplayName());
case UPDATE_HAT -> () -> entry.setShowHat(update.isShowHat());
case UPDATE_LIST_ORDER -> () -> entry.setListOrder(update.getListOrder());
case UPDATE_LISTED -> () -> entry.setListed(newEntry.isListed());
case UPDATE_LATENCY -> () -> entry.setLatency(newEntry.getLatency());
case UPDATE_DISPLAY_NAME -> () -> entry.setDisplayName(newEntry.getDisplayName());
case UPDATE_HAT -> () -> entry.setShowHat(newEntry.isShowHat());
case UPDATE_LIST_ORDER -> () -> entry.setListOrder(newEntry.getListOrder());
});
}
}
Expand Down

0 comments on commit 039c57f

Please sign in to comment.