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
This commit is contained in:
JOO200
2022-12-09 19:40:30 +01:00
committed by GitHub
parent 9cbaeb7b65
commit 97770cd1a6
5 changed files with 65 additions and 30 deletions

View File

@@ -131,11 +131,6 @@ public class KeyedVelocityTabList implements InternalTabList {
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
public TabListEntry buildEntry(GameProfile profile,
net.kyori.adventure.text.@Nullable Component displayName,
@@ -145,7 +140,7 @@ public class KeyedVelocityTabList implements InternalTabList {
@Override
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,
chatSession == null ? null : chatSession.getIdentifiedKey());
}

View File

@@ -162,21 +162,10 @@ public class VelocityTabList implements InternalTabList {
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
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode,
@Nullable IdentifiedKey key) {
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, null, true);
}
@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);
@Nullable ChatSession chatSession, boolean listed) {
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode, chatSession, listed);
}
@Override
@@ -211,7 +200,7 @@ public class VelocityTabList implements InternalTabList {
0,
-1,
null,
true
false
)
);
} else {
@@ -223,19 +212,19 @@ public class VelocityTabList implements InternalTabList {
return;
}
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_GAME_MODE)) {
currentEntry.setGameMode(entry.getGameMode());
currentEntry.setGameModeWithoutUpdate(entry.getGameMode());
}
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_LATENCY)) {
currentEntry.setLatency(entry.getLatency());
currentEntry.setLatencyWithoutUpdate(entry.getLatency());
}
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_DISPLAY_NAME)) {
currentEntry.setDisplayName(entry.getDisplayName());
currentEntry.setDisplayNameWithoutUpdate(entry.getDisplayName());
}
if (actions.contains(UpsertPlayerInfo.Action.INITIALIZE_CHAT)) {
currentEntry.setChatSession(entry.getChatSession());
}
if (actions.contains(UpsertPlayerInfo.Action.UPDATE_LISTED)) {
currentEntry.setListed(entry.isListed());
currentEntry.setListedWithoutUpdate(entry.isListed());
}
}

View File

@@ -76,6 +76,10 @@ public class VelocityTabListEntry implements TabListEntry {
return this;
}
void setDisplayNameWithoutUpdate(@Nullable Component displayName) {
this.displayName = displayName;
}
@Override
public int getLatency() {
return this.latency;
@@ -90,6 +94,10 @@ public class VelocityTabListEntry implements TabListEntry {
return this;
}
void setLatencyWithoutUpdate(int latency) {
this.latency = latency;
}
@Override
public int getGameMode() {
return this.gameMode;
@@ -104,6 +112,10 @@ public class VelocityTabListEntry implements TabListEntry {
return this;
}
void setGameModeWithoutUpdate(int gameMode) {
this.gameMode = gameMode;
}
protected void setChatSession(@Nullable ChatSession session) {
this.session = session;
}
@@ -121,4 +133,8 @@ public class VelocityTabListEntry implements TabListEntry {
this.tabList.emitActionRaw(UpsertPlayerInfo.Action.UPDATE_LISTED, upsertEntry);
return this;
}
void setListedWithoutUpdate(boolean listed) {
this.listed = listed;
}
}