Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 08:10:12 +01:00
feat: expose list order in TabListEntry
Dieser Commit ist enthalten in:
Ursprung
7a9227d517
Commit
ab60261842
@ -168,6 +168,25 @@ public interface TabList {
|
|||||||
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
|
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
default TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||||
|
int gameMode, @Nullable ChatSession chatSession, boolean listed) {
|
||||||
|
return buildEntry(profile, displayName, latency, gameMode, chatSession, listed, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an entry in a {@link Player}'s tab list.
|
||||||
|
*
|
||||||
|
* @param profile the profile
|
||||||
|
* @param displayName the display name
|
||||||
|
* @param latency the latency
|
||||||
|
* @param gameMode the game mode
|
||||||
|
* @param chatSession the chat session
|
||||||
|
* @param listed the visible status of entry
|
||||||
|
* @param listOrder the order/priority of entry in the tab list
|
||||||
|
* @return the entry
|
||||||
|
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||||
int gameMode, @Nullable ChatSession chatSession, boolean listed);
|
int gameMode, @Nullable ChatSession chatSession, boolean listed, int listOrder);
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,27 @@ public interface TabListEntry extends KeyIdentifiable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the order/priority of this entry in the tab list.
|
||||||
|
*
|
||||||
|
* @return order of this entry
|
||||||
|
* @sinceMinecraft 1.21.2
|
||||||
|
*/
|
||||||
|
default int getListOrder() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the order/priority of this entry in the tab list.
|
||||||
|
*
|
||||||
|
* @param order order of this entry
|
||||||
|
* @return {@code this}, for chaining
|
||||||
|
* @sinceMinecraft 1.21.2
|
||||||
|
*/
|
||||||
|
default TabListEntry setListOrder(int order) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link Builder} to create a {@link TabListEntry}.
|
* Returns a {@link Builder} to create a {@link TabListEntry}.
|
||||||
*
|
*
|
||||||
@ -161,6 +182,7 @@ public interface TabListEntry extends KeyIdentifiable {
|
|||||||
private int latency = 0;
|
private int latency = 0;
|
||||||
private int gameMode = 0;
|
private int gameMode = 0;
|
||||||
private boolean listed = true;
|
private boolean listed = true;
|
||||||
|
private int listOrder = 0;
|
||||||
|
|
||||||
private @Nullable ChatSession chatSession;
|
private @Nullable ChatSession chatSession;
|
||||||
|
|
||||||
@ -243,7 +265,7 @@ public interface TabListEntry extends KeyIdentifiable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets wether this entry should be visible.
|
* Sets whether this entry should be visible.
|
||||||
*
|
*
|
||||||
* @param listed to set
|
* @param listed to set
|
||||||
* @return ${code this}, for chaining
|
* @return ${code this}, for chaining
|
||||||
@ -254,6 +276,19 @@ public interface TabListEntry extends KeyIdentifiable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the order/priority of this entry in the tab list.
|
||||||
|
*
|
||||||
|
* @param order to set
|
||||||
|
* @return ${code this}, for chaining
|
||||||
|
* @sinceMinecraft 1.21.2
|
||||||
|
* @see TabListEntry#getListOrder()
|
||||||
|
*/
|
||||||
|
public Builder listOrder(int order) {
|
||||||
|
this.listOrder = order;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the {@link TabListEntry} specified by {@code this} {@link Builder}.
|
* Constructs the {@link TabListEntry} specified by {@code this} {@link Builder}.
|
||||||
*
|
*
|
||||||
@ -266,7 +301,7 @@ public interface TabListEntry extends KeyIdentifiable {
|
|||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
throw new IllegalStateException("The GameProfile must be set when building a TabListEntry");
|
throw new IllegalStateException("The GameProfile must be set when building a TabListEntry");
|
||||||
}
|
}
|
||||||
return tabList.buildEntry(profile, displayName, latency, gameMode, chatSession, listed);
|
return tabList.buildEntry(profile, displayName, latency, gameMode, chatSession, listed, listOrder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,12 +159,17 @@ public class KeyedVelocityTabList implements InternalTabList {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||||
int gameMode,
|
int gameMode, @Nullable ChatSession chatSession, boolean listed) {
|
||||||
@Nullable ChatSession chatSession, boolean listed) {
|
|
||||||
return new KeyedVelocityTabListEntry(this, profile, displayName, latency, gameMode,
|
return new KeyedVelocityTabListEntry(this, profile, displayName, latency, gameMode,
|
||||||
chatSession == null ? null : chatSession.getIdentifiedKey());
|
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
|
@Override
|
||||||
public void processLegacy(LegacyPlayerListItemPacket packet) {
|
public void processLegacy(LegacyPlayerListItemPacket packet) {
|
||||||
// Packets are already forwarded on, so no need to do that here
|
// Packets are already forwarded on, so no need to do that here
|
||||||
|
@ -89,7 +89,7 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
} else {
|
} else {
|
||||||
entry = new VelocityTabListEntry(this, entry1.getProfile(),
|
entry = new VelocityTabListEntry(this, entry1.getProfile(),
|
||||||
entry1.getDisplayNameComponent().orElse(null),
|
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
|
EnumSet<UpsertPlayerInfoPacket.Action> actions = EnumSet
|
||||||
@ -207,9 +207,9 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
@Override
|
@Override
|
||||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||||
int gameMode,
|
int gameMode,
|
||||||
@Nullable ChatSession chatSession, boolean listed) {
|
@Nullable ChatSession chatSession, boolean listed, int listOrder) {
|
||||||
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, chatSession,
|
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, chatSession,
|
||||||
listed);
|
listed, listOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -246,7 +246,8 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
0,
|
0,
|
||||||
-1,
|
-1,
|
||||||
null,
|
null,
|
||||||
false
|
false,
|
||||||
|
0
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -274,6 +275,9 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
if (actions.contains(UpsertPlayerInfoPacket.Action.UPDATE_LISTED)) {
|
if (actions.contains(UpsertPlayerInfoPacket.Action.UPDATE_LISTED)) {
|
||||||
currentEntry.setListedWithoutUpdate(entry.isListed());
|
currentEntry.setListedWithoutUpdate(entry.isListed());
|
||||||
}
|
}
|
||||||
|
if (actions.contains(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER)) {
|
||||||
|
currentEntry.setListOrderWithoutUpdate(entry.getListOrder());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,6 +38,7 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
private int latency;
|
private int latency;
|
||||||
private int gameMode;
|
private int gameMode;
|
||||||
private boolean listed;
|
private boolean listed;
|
||||||
|
private int listOrder;
|
||||||
private @Nullable ChatSession session;
|
private @Nullable ChatSession session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +46,7 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
*/
|
*/
|
||||||
public VelocityTabListEntry(VelocityTabList tabList, GameProfile profile, Component displayName,
|
public VelocityTabListEntry(VelocityTabList tabList, GameProfile profile, Component displayName,
|
||||||
int latency,
|
int latency,
|
||||||
int gameMode, @Nullable ChatSession session, boolean listed) {
|
int gameMode, @Nullable ChatSession session, boolean listed, int listOrder) {
|
||||||
this.tabList = tabList;
|
this.tabList = tabList;
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
@ -53,6 +54,7 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
this.gameMode = gameMode;
|
this.gameMode = gameMode;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.listed = listed;
|
this.listed = listed;
|
||||||
|
this.listOrder = listOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -150,4 +152,22 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
void setListedWithoutUpdate(boolean listed) {
|
void setListedWithoutUpdate(boolean listed) {
|
||||||
this.listed = listed;
|
this.listed = listed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getListOrder() {
|
||||||
|
return listOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VelocityTabListEntry setListOrder(int listOrder) {
|
||||||
|
this.listOrder = listOrder;
|
||||||
|
UpsertPlayerInfoPacket.Entry upsertEntry = this.tabList.createRawEntry(this);
|
||||||
|
upsertEntry.setListOrder(listOrder);
|
||||||
|
this.tabList.emitActionRaw(UpsertPlayerInfoPacket.Action.UPDATE_LIST_ORDER, upsertEntry);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setListOrderWithoutUpdate(int listOrder) {
|
||||||
|
this.listOrder = listOrder;
|
||||||
|
}
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren