Skip to content

Commit

Permalink
Update WrapperPlayServerPlayerInfoUpdate to 24w44a
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Oct 30, 2024
1 parent 3b86806 commit aedb43b
Showing 1 changed file with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.retrooper.packetevents.wrapper.play.server;

import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.chat.RemoteChatSession;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.GameMode;
Expand Down Expand Up @@ -47,9 +48,15 @@ public enum Action {
UPDATE_LATENCY,
UPDATE_DISPLAY_NAME,
/**
* Updates the order in which the player is listed in the tablist.
* Updates the order in which the player is listed in the tablist.<br>
* Added with 1.21.2.
*/
UPDATE_LIST_ORDER;
UPDATE_LIST_ORDER,
/**
* Updates wether the outer skin layer (hat) of the player will be shown in tablist.<br>
* Added with 1.21.5.
*/
UPDATE_HAT;

public static final WrapperPlayServerPlayerInfoUpdate.Action[] VALUES = values();
}
Expand All @@ -63,7 +70,14 @@ public static class PlayerInfo {
private Component displayName;
@Nullable
private RemoteChatSession chatSession;
private int listOrder; // added in 1.21.2
/**
* Added with 1.21.2
*/
private int listOrder;
/**
* Added with 1.21.5
*/
private boolean showHat;

public PlayerInfo(UUID profileId) {
this(new UserProfile(profileId, ""));
Expand All @@ -88,6 +102,16 @@ public PlayerInfo(
@Nullable Component displayName,
@Nullable RemoteChatSession chatSession,
int listOrder
) {
this(profile, listed, latency, gameMode, displayName, chatSession, listOrder, false);
}

public PlayerInfo(
UserProfile profile, boolean listed,
int latency, GameMode gameMode,
@Nullable Component displayName,
@Nullable RemoteChatSession chatSession,
int listOrder, boolean showHat
) {
this.profile = profile;
this.listed = listed;
Expand All @@ -96,6 +120,7 @@ public PlayerInfo(
this.displayName = displayName;
this.chatSession = chatSession;
this.listOrder = listOrder;
this.showHat = showHat;
}

public UUID getProfileId() {
Expand Down Expand Up @@ -126,10 +151,20 @@ public GameMode getGameMode() {
return chatSession;
}

/**
* Added with 1.21.2
*/
public int getListOrder() {
return this.listOrder;
}

/**
* Added with 1.21.5
*/
public boolean isShowHat() {
return this.showHat;
}

public void setGameProfile(UserProfile gameProfile) {
this.profile = gameProfile;
}
Expand All @@ -154,9 +189,19 @@ public void setChatSession(@Nullable RemoteChatSession chatSession) {
this.chatSession = chatSession;
}

/**
* Added with 1.21.2
*/
public void setListOrder(int listOrder) {
this.listOrder = listOrder;
}

/**
* Added with 1.21.5
*/
public void setShowHat(boolean showHat) {
this.showHat = showHat;
}
}

public WrapperPlayServerPlayerInfoUpdate(PacketSendEvent event) {
Expand Down Expand Up @@ -196,6 +241,7 @@ public void read() {
@Nullable RemoteChatSession chatSession = null;
@Nullable Component displayName = null;
int listOrder = 0;
boolean showHat = false;
for (Action action : actions) {
switch (action) {
case ADD_PLAYER:
Expand Down Expand Up @@ -227,11 +273,18 @@ public void read() {
displayName = wrapper.readOptional(PacketWrapper::readComponent);
break;
case UPDATE_LIST_ORDER:
listOrder = wrapper.readVarInt();
if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_2)) {
listOrder = wrapper.readVarInt();
}
break;
case UPDATE_HAT:
if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_4)) {
showHat = wrapper.readBoolean();
}
break;
}
}
return new PlayerInfo(gameProfile, listed, latency, gameMode, displayName, chatSession, listOrder);
return new PlayerInfo(gameProfile, listed, latency, gameMode, displayName, chatSession, listOrder, showHat);
});
}

Expand Down Expand Up @@ -266,7 +319,14 @@ public void write() {
wrapper.writeOptional(playerInfo.getDisplayName(), PacketWrapper::writeComponent);
break;
case UPDATE_LIST_ORDER:
wrapper.writeVarInt(playerInfo.getListOrder());
if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_2)) {
wrapper.writeVarInt(playerInfo.getListOrder());
}
break;
case UPDATE_HAT:
if (this.serverVersion.isNewerThanOrEquals(ServerVersion.V_1_21_4)) {
wrapper.writeBoolean(playerInfo.isShowHat());
}
break;
}
}
Expand Down

0 comments on commit aedb43b

Please sign in to comment.