Skip to content

Commit 33be16d

Browse files
committed
Merge branch 'dev/3.0.0' of https://github.com/PaperMC/Velocity
2 parents c0eee75 + cefa3b2 commit 33be16d

File tree

5 files changed

+107
-10
lines changed

5 files changed

+107
-10
lines changed

api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,25 @@ default TabListEntry buildEntry(GameProfile profile, @Nullable Component display
168168
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
169169
*/
170170
@Deprecated
171+
default TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
172+
int gameMode, @Nullable ChatSession chatSession, boolean listed) {
173+
return buildEntry(profile, displayName, latency, gameMode, chatSession, listed, 0);
174+
}
175+
176+
/**
177+
* Represents an entry in a {@link Player}'s tab list.
178+
*
179+
* @param profile the profile
180+
* @param displayName the display name
181+
* @param latency the latency
182+
* @param gameMode the game mode
183+
* @param chatSession the chat session
184+
* @param listed the visible status of entry
185+
* @param listOrder the order/priority of entry in the tab list
186+
* @return the entry
187+
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
188+
*/
189+
@Deprecated
171190
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
172-
int gameMode, @Nullable ChatSession chatSession, boolean listed);
191+
int gameMode, @Nullable ChatSession chatSession, boolean listed, int listOrder);
173192
}

api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,27 @@ default TabListEntry setListed(boolean listed) {
139139
return this;
140140
}
141141

142+
/**
143+
* Returns the order/priority of this entry in the tab list.
144+
*
145+
* @return order of this entry
146+
* @sinceMinecraft 1.21.2
147+
*/
148+
default int getListOrder() {
149+
return 0;
150+
}
151+
152+
/**
153+
* Sets the order/priority of this entry in the tab list.
154+
*
155+
* @param order order of this entry
156+
* @return {@code this}, for chaining
157+
* @sinceMinecraft 1.21.2
158+
*/
159+
default TabListEntry setListOrder(int order) {
160+
return this;
161+
}
162+
142163
/**
143164
* Returns a {@link Builder} to create a {@link TabListEntry}.
144165
*
@@ -161,6 +182,7 @@ class Builder {
161182
private int latency = 0;
162183
private int gameMode = 0;
163184
private boolean listed = true;
185+
private int listOrder = 0;
164186

165187
private @Nullable ChatSession chatSession;
166188

@@ -243,7 +265,7 @@ public Builder gameMode(int gameMode) {
243265
}
244266

245267
/**
246-
* Sets wether this entry should be visible.
268+
* Sets whether this entry should be visible.
247269
*
248270
* @param listed to set
249271
* @return ${code this}, for chaining
@@ -254,6 +276,19 @@ public Builder listed(boolean listed) {
254276
return this;
255277
}
256278

279+
/**
280+
* Sets the order/priority of this entry in the tab list.
281+
*
282+
* @param order to set
283+
* @return ${code this}, for chaining
284+
* @sinceMinecraft 1.21.2
285+
* @see TabListEntry#getListOrder()
286+
*/
287+
public Builder listOrder(int order) {
288+
this.listOrder = order;
289+
return this;
290+
}
291+
257292
/**
258293
* Constructs the {@link TabListEntry} specified by {@code this} {@link Builder}.
259294
*
@@ -266,7 +301,7 @@ public TabListEntry build() {
266301
if (profile == null) {
267302
throw new IllegalStateException("The GameProfile must be set when building a TabListEntry");
268303
}
269-
return tabList.buildEntry(profile, displayName, latency, gameMode, chatSession, listed);
304+
return tabList.buildEntry(profile, displayName, latency, gameMode, chatSession, listed, listOrder);
270305
}
271306
}
272307
}

proxy/src/main/java/com/velocitypowered/proxy/tablist/KeyedVelocityTabList.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,17 @@ public TabListEntry buildEntry(GameProfile profile,
159159

160160
@Override
161161
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
162-
int gameMode,
163-
@Nullable ChatSession chatSession, boolean listed) {
162+
int gameMode, @Nullable ChatSession chatSession, boolean listed) {
164163
return new KeyedVelocityTabListEntry(this, profile, displayName, latency, gameMode,
165164
chatSession == null ? null : chatSession.getIdentifiedKey());
166165
}
167166

167+
@Override
168+
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
169+
int gameMode, @Nullable ChatSession chatSession, boolean listed, int listOrder) {
170+
return buildEntry(profile, displayName, latency, gameMode, chatSession, listed);
171+
}
172+
168173
@Override
169174
public void processLegacy(LegacyPlayerListItemPacket packet) {
170175
// Packets are already forwarded on, so no need to do that here

proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.common.base.Preconditions;
2121
import com.google.common.collect.Maps;
22+
import com.velocitypowered.api.network.ProtocolVersion;
2223
import com.velocitypowered.api.proxy.Player;
2324
import com.velocitypowered.api.proxy.player.ChatSession;
2425
import com.velocitypowered.api.proxy.player.TabListEntry;
@@ -89,7 +90,7 @@ public void addEntry(TabListEntry entry1) {
8990
} else {
9091
entry = new VelocityTabListEntry(this, entry1.getProfile(),
9192
entry1.getDisplayNameComponent().orElse(null),
92-
entry1.getLatency(), entry1.getGameMode(), entry1.getChatSession(), entry1.isListed());
93+
entry1.getLatency(), entry1.getGameMode(), entry1.getChatSession(), entry1.isListed(), entry1.getListOrder());
9394
}
9495

9596
EnumSet<UpsertPlayerInfoPacket.Action> actions = EnumSet
@@ -128,6 +129,11 @@ public void addEntry(TabListEntry entry1) {
128129
actions.add(UpsertPlayerInfoPacket.Action.UPDATE_LISTED);
129130
playerInfoEntry.setListed(entry.isListed());
130131
}
132+
if (!Objects.equals(previousEntry.getListOrder(), entry.getListOrder())
133+
&& player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21_2)) {
134+
actions.add(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER);
135+
playerInfoEntry.setListOrder(entry.getListOrder());
136+
}
131137
if (!Objects.equals(previousEntry.getChatSession(), entry.getChatSession())) {
132138
ChatSession from = entry.getChatSession();
133139
if (from != null) {
@@ -162,6 +168,11 @@ public void addEntry(TabListEntry entry1) {
162168
}
163169
playerInfoEntry.setLatency(entry.getLatency());
164170
playerInfoEntry.setListed(entry.isListed());
171+
if (entry.getListOrder() != 0
172+
&& player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21_2)) {
173+
actions.add(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER);
174+
playerInfoEntry.setListOrder(entry.getListOrder());
175+
}
165176
}
166177
return entry;
167178
});
@@ -207,9 +218,9 @@ public void clearAllSilent() {
207218
@Override
208219
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
209220
int gameMode,
210-
@Nullable ChatSession chatSession, boolean listed) {
221+
@Nullable ChatSession chatSession, boolean listed, int listOrder) {
211222
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, chatSession,
212-
listed);
223+
listed, listOrder);
213224
}
214225

215226
@Override
@@ -246,7 +257,8 @@ private void processUpsert(EnumSet<UpsertPlayerInfoPacket.Action> actions,
246257
0,
247258
-1,
248259
null,
249-
false
260+
false,
261+
0
250262
)
251263
);
252264
} else {
@@ -274,6 +286,9 @@ private void processUpsert(EnumSet<UpsertPlayerInfoPacket.Action> actions,
274286
if (actions.contains(UpsertPlayerInfoPacket.Action.UPDATE_LISTED)) {
275287
currentEntry.setListedWithoutUpdate(entry.isListed());
276288
}
289+
if (actions.contains(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER)) {
290+
currentEntry.setListOrderWithoutUpdate(entry.getListOrder());
291+
}
277292
}
278293

279294
@Override

proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.velocitypowered.proxy.tablist;
1919

20+
import com.velocitypowered.api.network.ProtocolVersion;
2021
import com.velocitypowered.api.proxy.player.ChatSession;
2122
import com.velocitypowered.api.proxy.player.TabList;
2223
import com.velocitypowered.api.proxy.player.TabListEntry;
@@ -38,21 +39,23 @@ public class VelocityTabListEntry implements TabListEntry {
3839
private int latency;
3940
private int gameMode;
4041
private boolean listed;
42+
private int listOrder;
4143
private @Nullable ChatSession session;
4244

4345
/**
4446
* Constructs the instance.
4547
*/
4648
public VelocityTabListEntry(VelocityTabList tabList, GameProfile profile, Component displayName,
4749
int latency,
48-
int gameMode, @Nullable ChatSession session, boolean listed) {
50+
int gameMode, @Nullable ChatSession session, boolean listed, int listOrder) {
4951
this.tabList = tabList;
5052
this.profile = profile;
5153
this.displayName = displayName;
5254
this.latency = latency;
5355
this.gameMode = gameMode;
5456
this.session = session;
5557
this.listed = listed;
58+
this.listOrder = listOrder;
5659
}
5760

5861
@Override
@@ -150,4 +153,24 @@ public VelocityTabListEntry setListed(boolean listed) {
150153
void setListedWithoutUpdate(boolean listed) {
151154
this.listed = listed;
152155
}
156+
157+
@Override
158+
public int getListOrder() {
159+
return listOrder;
160+
}
161+
162+
@Override
163+
public VelocityTabListEntry setListOrder(int listOrder) {
164+
this.listOrder = listOrder;
165+
if (tabList.getPlayer().getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21_2)) {
166+
UpsertPlayerInfoPacket.Entry upsertEntry = this.tabList.createRawEntry(this);
167+
upsertEntry.setListOrder(listOrder);
168+
tabList.emitActionRaw(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER, upsertEntry);
169+
}
170+
return this;
171+
}
172+
173+
void setListOrderWithoutUpdate(int listOrder) {
174+
this.listOrder = listOrder;
175+
}
153176
}

0 commit comments

Comments
 (0)