Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Reduce Spam from the TabList by not sending every package multiple times (#902)
* Reduce Spam from the TabList by not sending every package multiple times VelocityTabList#processUpsert called entry.setX which will create a package and send it to the client. BackendPlaySessionHandler doesn't return true for those packages, therefore the package for tab list updates will be send two times. * Cleanup TabList#buildEntry, added listed status to Entry builder
Dieser Commit ist enthalten in:
Ursprung
9cbaeb7b65
Commit
97770cd1a6
@ -84,8 +84,10 @@ public interface TabList {
|
|||||||
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
|
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
default TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||||
int gameMode);
|
int gameMode) {
|
||||||
|
return buildEntry(profile, displayName, latency, gameMode, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a tab list entry.
|
* Builds a tab list entry.
|
||||||
@ -99,8 +101,10 @@ public interface TabList {
|
|||||||
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
|
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
default TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||||
int gameMode, @Nullable IdentifiedKey key);
|
int gameMode, @Nullable IdentifiedKey key) {
|
||||||
|
return buildEntry(profile, displayName, latency, gameMode, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,6 +119,24 @@ 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) {
|
||||||
|
return buildEntry(profile, displayName, latency, gameMode, chatSession, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @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);
|
int gameMode, @Nullable ChatSession chatSession, boolean listed);
|
||||||
}
|
}
|
||||||
|
@ -160,6 +160,7 @@ public interface TabListEntry extends KeyIdentifiable {
|
|||||||
private @Nullable Component displayName;
|
private @Nullable Component displayName;
|
||||||
private int latency = 0;
|
private int latency = 0;
|
||||||
private int gameMode = 0;
|
private int gameMode = 0;
|
||||||
|
private boolean listed = true;
|
||||||
|
|
||||||
private @Nullable ChatSession chatSession;
|
private @Nullable ChatSession chatSession;
|
||||||
|
|
||||||
@ -241,6 +242,18 @@ public interface TabListEntry extends KeyIdentifiable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets wether this entry should be visible.
|
||||||
|
*
|
||||||
|
* @param listed to set
|
||||||
|
* @return ${code this}, for chaining
|
||||||
|
* @see TabListEntry#isListed()
|
||||||
|
*/
|
||||||
|
public Builder listed(boolean listed) {
|
||||||
|
this.listed = listed;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the {@link TabListEntry} specified by {@code this} {@link Builder}.
|
* Constructs the {@link TabListEntry} specified by {@code this} {@link Builder}.
|
||||||
*
|
*
|
||||||
@ -253,7 +266,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);
|
return tabList.buildEntry(profile, displayName, latency, gameMode, chatSession, listed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,11 +131,6 @@ public class KeyedVelocityTabList implements InternalTabList {
|
|||||||
return Collections.unmodifiableCollection(this.entries.values());
|
return Collections.unmodifiableCollection(this.entries.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode) {
|
|
||||||
return buildEntry(profile, displayName, latency, gameMode, (ChatSession) null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TabListEntry buildEntry(GameProfile profile,
|
public TabListEntry buildEntry(GameProfile profile,
|
||||||
net.kyori.adventure.text.@Nullable Component displayName,
|
net.kyori.adventure.text.@Nullable Component displayName,
|
||||||
@ -145,7 +140,7 @@ public class KeyedVelocityTabList implements InternalTabList {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode,
|
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode,
|
||||||
@Nullable ChatSession chatSession) {
|
@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());
|
||||||
}
|
}
|
||||||
|
@ -162,21 +162,10 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
this.entries.clear();
|
this.entries.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode) {
|
|
||||||
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, null, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode,
|
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode,
|
||||||
@Nullable IdentifiedKey key) {
|
@Nullable ChatSession chatSession, boolean listed) {
|
||||||
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, null, true);
|
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, chatSession, listed);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode,
|
|
||||||
@Nullable ChatSession chatSession) {
|
|
||||||
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, chatSession, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -211,7 +200,7 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
0,
|
0,
|
||||||
-1,
|
-1,
|
||||||
null,
|
null,
|
||||||
true
|
false
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -223,19 +212,19 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_GAME_MODE)) {
|
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_GAME_MODE)) {
|
||||||
currentEntry.setGameMode(entry.getGameMode());
|
currentEntry.setGameModeWithoutUpdate(entry.getGameMode());
|
||||||
}
|
}
|
||||||
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_LATENCY)) {
|
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_LATENCY)) {
|
||||||
currentEntry.setLatency(entry.getLatency());
|
currentEntry.setLatencyWithoutUpdate(entry.getLatency());
|
||||||
}
|
}
|
||||||
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_DISPLAY_NAME)) {
|
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_DISPLAY_NAME)) {
|
||||||
currentEntry.setDisplayName(entry.getDisplayName());
|
currentEntry.setDisplayNameWithoutUpdate(entry.getDisplayName());
|
||||||
}
|
}
|
||||||
if (actions.contains(UpsertPlayerInfo.Action.INITIALIZE_CHAT)) {
|
if (actions.contains(UpsertPlayerInfo.Action.INITIALIZE_CHAT)) {
|
||||||
currentEntry.setChatSession(entry.getChatSession());
|
currentEntry.setChatSession(entry.getChatSession());
|
||||||
}
|
}
|
||||||
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_LISTED)) {
|
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_LISTED)) {
|
||||||
currentEntry.setListed(entry.isListed());
|
currentEntry.setListedWithoutUpdate(entry.isListed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,10 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setDisplayNameWithoutUpdate(@Nullable Component displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLatency() {
|
public int getLatency() {
|
||||||
return this.latency;
|
return this.latency;
|
||||||
@ -90,6 +94,10 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setLatencyWithoutUpdate(int latency) {
|
||||||
|
this.latency = latency;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getGameMode() {
|
public int getGameMode() {
|
||||||
return this.gameMode;
|
return this.gameMode;
|
||||||
@ -104,6 +112,10 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setGameModeWithoutUpdate(int gameMode) {
|
||||||
|
this.gameMode = gameMode;
|
||||||
|
}
|
||||||
|
|
||||||
protected void setChatSession(@Nullable ChatSession session) {
|
protected void setChatSession(@Nullable ChatSession session) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
@ -121,4 +133,8 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
this.tabList.emitActionRaw(UpsertPlayerInfo.Action.UPDATE_LISTED, upsertEntry);
|
this.tabList.emitActionRaw(UpsertPlayerInfo.Action.UPDATE_LISTED, upsertEntry);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setListedWithoutUpdate(boolean listed) {
|
||||||
|
this.listed = listed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren