feat: expose list order in TabListEntry (#1451)
* feat: expose list order in TabListEntry * fix: address comment (from github) * fix: address another comment (from github)
This commit is contained in:
@@ -159,12 +159,17 @@ public class KeyedVelocityTabList implements InternalTabList {
|
||||
|
||||
@Override
|
||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||
int gameMode,
|
||||
@Nullable ChatSession chatSession, boolean listed) {
|
||||
int gameMode, @Nullable ChatSession chatSession, boolean listed) {
|
||||
return new KeyedVelocityTabListEntry(this, profile, displayName, latency, gameMode,
|
||||
chatSession == null ? null : chatSession.getIdentifiedKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||
int gameMode, @Nullable ChatSession chatSession, boolean listed, int listOrder) {
|
||||
return buildEntry(profile, displayName, latency, gameMode, chatSession, listed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processLegacy(LegacyPlayerListItemPacket packet) {
|
||||
// Packets are already forwarded on, so no need to do that here
|
||||
|
@@ -19,6 +19,7 @@ package com.velocitypowered.proxy.tablist;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.player.ChatSession;
|
||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
@@ -89,7 +90,7 @@ public class VelocityTabList implements InternalTabList {
|
||||
} else {
|
||||
entry = new VelocityTabListEntry(this, entry1.getProfile(),
|
||||
entry1.getDisplayNameComponent().orElse(null),
|
||||
entry1.getLatency(), entry1.getGameMode(), entry1.getChatSession(), entry1.isListed());
|
||||
entry1.getLatency(), entry1.getGameMode(), entry1.getChatSession(), entry1.isListed(), entry1.getListOrder());
|
||||
}
|
||||
|
||||
EnumSet<UpsertPlayerInfoPacket.Action> actions = EnumSet
|
||||
@@ -128,6 +129,11 @@ public class VelocityTabList implements InternalTabList {
|
||||
actions.add(UpsertPlayerInfoPacket.Action.UPDATE_LISTED);
|
||||
playerInfoEntry.setListed(entry.isListed());
|
||||
}
|
||||
if (!Objects.equals(previousEntry.getListOrder(), entry.getListOrder())
|
||||
&& player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21_2)) {
|
||||
actions.add(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER);
|
||||
playerInfoEntry.setListOrder(entry.getListOrder());
|
||||
}
|
||||
if (!Objects.equals(previousEntry.getChatSession(), entry.getChatSession())) {
|
||||
ChatSession from = entry.getChatSession();
|
||||
if (from != null) {
|
||||
@@ -162,6 +168,11 @@ public class VelocityTabList implements InternalTabList {
|
||||
}
|
||||
playerInfoEntry.setLatency(entry.getLatency());
|
||||
playerInfoEntry.setListed(entry.isListed());
|
||||
if (entry.getListOrder() != 0
|
||||
&& player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21_2)) {
|
||||
actions.add(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER);
|
||||
playerInfoEntry.setListOrder(entry.getListOrder());
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
@@ -207,9 +218,9 @@ public class VelocityTabList implements InternalTabList {
|
||||
@Override
|
||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||
int gameMode,
|
||||
@Nullable ChatSession chatSession, boolean listed) {
|
||||
@Nullable ChatSession chatSession, boolean listed, int listOrder) {
|
||||
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, chatSession,
|
||||
listed);
|
||||
listed, listOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -246,7 +257,8 @@ public class VelocityTabList implements InternalTabList {
|
||||
0,
|
||||
-1,
|
||||
null,
|
||||
false
|
||||
false,
|
||||
0
|
||||
)
|
||||
);
|
||||
} else {
|
||||
@@ -274,6 +286,9 @@ public class VelocityTabList implements InternalTabList {
|
||||
if (actions.contains(UpsertPlayerInfoPacket.Action.UPDATE_LISTED)) {
|
||||
currentEntry.setListedWithoutUpdate(entry.isListed());
|
||||
}
|
||||
if (actions.contains(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER)) {
|
||||
currentEntry.setListOrderWithoutUpdate(entry.getListOrder());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.velocitypowered.proxy.tablist;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.player.ChatSession;
|
||||
import com.velocitypowered.api.proxy.player.TabList;
|
||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
@@ -38,6 +39,7 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
private int latency;
|
||||
private int gameMode;
|
||||
private boolean listed;
|
||||
private int listOrder;
|
||||
private @Nullable ChatSession session;
|
||||
|
||||
/**
|
||||
@@ -45,7 +47,7 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
*/
|
||||
public VelocityTabListEntry(VelocityTabList tabList, GameProfile profile, Component displayName,
|
||||
int latency,
|
||||
int gameMode, @Nullable ChatSession session, boolean listed) {
|
||||
int gameMode, @Nullable ChatSession session, boolean listed, int listOrder) {
|
||||
this.tabList = tabList;
|
||||
this.profile = profile;
|
||||
this.displayName = displayName;
|
||||
@@ -53,6 +55,7 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
this.gameMode = gameMode;
|
||||
this.session = session;
|
||||
this.listed = listed;
|
||||
this.listOrder = listOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,4 +153,24 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
void setListedWithoutUpdate(boolean listed) {
|
||||
this.listed = listed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getListOrder() {
|
||||
return listOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityTabListEntry setListOrder(int listOrder) {
|
||||
this.listOrder = listOrder;
|
||||
if (tabList.getPlayer().getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_21_2)) {
|
||||
UpsertPlayerInfoPacket.Entry upsertEntry = this.tabList.createRawEntry(this);
|
||||
upsertEntry.setListOrder(listOrder);
|
||||
tabList.emitActionRaw(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER, upsertEntry);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void setListOrderWithoutUpdate(int listOrder) {
|
||||
this.listOrder = listOrder;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user