Skip to content

Commit 2c0d632

Browse files
fix: listOrder not preserved when converting PlayerInfoData (#3347)
The field `listOrder` was always set to zero in the wrapper instead of being read from the NMS object. This commit fixes that, while adding the respective constructor and getter.
1 parent fd5d8c5 commit 2c0d632

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

src/main/java/com/comphenix/protocol/wrappers/PlayerInfoData.java

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class PlayerInfoData {
4040

4141
private final UUID profileId;
4242
private final int latency;
43-
private final int listOrder = 0;
43+
private final int listOrder;
4444
private final boolean listed;
4545
private final boolean showHat;
4646
private final NativeGameMode gameMode;
@@ -113,6 +113,23 @@ public PlayerInfoData(UUID profileId, int latency, boolean listed, NativeGameMod
113113
this.profileKeyData = profileKeyData;
114114
this.remoteChatSessionData = null;
115115
this.showHat = false;
116+
this.listOrder = 0;
117+
}
118+
119+
/**
120+
* Constructs a new PlayerInfoData for Minecraft 1.21.2 or later.
121+
*
122+
* @param profileId the id of the profile (has to be non-null)
123+
* @param latency the latency in milliseconds
124+
* @param listed whether the player is listed in the tab list
125+
* @param gameMode the game mode
126+
* @param profile the game profile
127+
* @param displayName display name in tab list (optional)
128+
* @param listOrder the priority of this entry in the tab list
129+
* @param remoteChatSession the remote chat session for this profile or null
130+
*/
131+
public PlayerInfoData(UUID profileId, int latency, boolean listed, NativeGameMode gameMode, WrappedGameProfile profile, WrappedChatComponent displayName, int listOrder, @Nullable WrappedRemoteChatSessionData remoteChatSession) {
132+
this(profileId, latency, listed, gameMode, profile, displayName, false, listOrder, remoteChatSession);
116133
}
117134

118135
/**
@@ -128,6 +145,23 @@ public PlayerInfoData(UUID profileId, int latency, boolean listed, NativeGameMod
128145
* @param remoteChatSession the remote chat session for this profile or null
129146
*/
130147
public PlayerInfoData(UUID profileId, int latency, boolean listed, NativeGameMode gameMode, WrappedGameProfile profile, WrappedChatComponent displayName, boolean showHat, @Nullable WrappedRemoteChatSessionData remoteChatSession) {
148+
this(profileId, latency, listed, gameMode, profile, displayName, showHat, 0, remoteChatSession);
149+
}
150+
151+
/**
152+
* Constructs a new PlayerInfoData for Minecraft 1.21.4 or later.
153+
*
154+
* @param profileId the id of the profile (has to be non-null)
155+
* @param latency the latency in milliseconds
156+
* @param listed whether the player is listed in the tab list
157+
* @param gameMode the game mode
158+
* @param profile the game profile
159+
* @param displayName display name in tab list (optional)
160+
* @param showHat whether a hat should be shown
161+
* @param listOrder the priority of this entry in the tab list
162+
* @param remoteChatSession the remote chat session for this profile or null
163+
*/
164+
public PlayerInfoData(UUID profileId, int latency, boolean listed, NativeGameMode gameMode, WrappedGameProfile profile, WrappedChatComponent displayName, boolean showHat, int listOrder, @Nullable WrappedRemoteChatSessionData remoteChatSession) {
131165
this.profileId = profileId;
132166
this.latency = latency;
133167
this.listed = listed;
@@ -137,6 +171,7 @@ public PlayerInfoData(UUID profileId, int latency, boolean listed, NativeGameMod
137171
this.profileKeyData = null;
138172
this.remoteChatSessionData = remoteChatSession;
139173
this.showHat = showHat;
174+
this.listOrder = listOrder;
140175
}
141176

142177
/**
@@ -203,8 +238,16 @@ public WrappedChatComponent getDisplayName() {
203238
* @return if the hat is shown
204239
*/
205240
public boolean isShowHat() {
206-
return showHat;
207-
}
241+
return showHat;
242+
}
243+
244+
/**
245+
* Gets the priority of this entry in the tab list (since 1.21.2)
246+
* @return the priority of this entry in the tab list
247+
*/
248+
public int getListOrder() {
249+
return listOrder;
250+
}
208251

209252
/**
210253
* Returns the public key of the profile (since 1.19). Returns the public key of the remote chat session since 1.19.3
@@ -255,7 +298,7 @@ public Object getGeneric(PlayerInfoData specific) {
255298
args.add(MinecraftReflection.getIChatBaseComponentClass());
256299

257300
if (MinecraftVersion.v1_21_4.atOrAbove()) {
258-
args.add(boolean.class);
301+
args.add(boolean.class);
259302
}
260303
if (MinecraftVersion.v1_21_2.atOrAbove()) {
261304
args.add(int.class);
@@ -376,6 +419,18 @@ public PlayerInfoData getSpecific(Object generic) {
376419
gameProfile,
377420
displayName,
378421
modifier.<Boolean>withType(boolean.class).read(1),
422+
ints.read(1),
423+
modifier.withType(MinecraftReflection.getRemoteChatSessionDataClass(), BukkitConverters.getWrappedRemoteChatSessionDataConverter()).read(0)
424+
);
425+
}
426+
if (MinecraftVersion.v1_21_2.atOrAbove()) {
427+
return new PlayerInfoData(modifier.<UUID>withType(UUID.class).read(0),
428+
latency,
429+
modifier.<Boolean>withType(boolean.class).read(0),
430+
gameMode,
431+
gameProfile,
432+
displayName,
433+
ints.read(1),
379434
modifier.withType(MinecraftReflection.getRemoteChatSessionDataClass(), BukkitConverters.getWrappedRemoteChatSessionDataConverter()).read(0)
380435
);
381436
}

src/test/java/com/comphenix/protocol/wrappers/PlayerInfoDataTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void test() throws Exception {
4444
testWriteBack(new PlayerInfoData(profile.getUUID(), 42, false, NativeGameMode.CREATIVE, profile, displayName, TestUtils.creteDummyRemoteChatSessionData()));
4545
testWriteBack(new PlayerInfoData(profile.getUUID(), 42, false, NativeGameMode.CREATIVE, null, null, TestUtils.creteDummyRemoteChatSessionData()));
4646
testWriteBack(new PlayerInfoData(profile.getUUID(), 42, true, NativeGameMode.CREATIVE, null, displayName));
47+
testWriteBack(new PlayerInfoData(profile.getUUID(), 42, true, NativeGameMode.CREATIVE, profile, displayName, true, 5, TestUtils.creteDummyRemoteChatSessionData()));
4748
}
4849

4950
private static void testWriteBack(PlayerInfoData data) {

0 commit comments

Comments
 (0)