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:
Timon
2024-11-10 00:03:34 +01:00
committed by GitHub
parent 08a42b3723
commit cefa3b272e
5 changed files with 107 additions and 10 deletions

View File

@@ -168,6 +168,25 @@ public interface TabList {
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
*/
@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,
int gameMode, @Nullable ChatSession chatSession, boolean listed);
int gameMode, @Nullable ChatSession chatSession, boolean listed, int listOrder);
}

View File

@@ -139,6 +139,27 @@ public interface TabListEntry extends KeyIdentifiable {
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}.
*
@@ -161,6 +182,7 @@ public interface TabListEntry extends KeyIdentifiable {
private int latency = 0;
private int gameMode = 0;
private boolean listed = true;
private int listOrder = 0;
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
* @return ${code this}, for chaining
@@ -254,6 +276,19 @@ public interface TabListEntry extends KeyIdentifiable {
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}.
*
@@ -266,7 +301,7 @@ public interface TabListEntry extends KeyIdentifiable {
if (profile == null) {
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);
}
}
}