Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2025-01-11 15:41:14 +01:00
Avoid sending duplicate set latency/gamemode/display name packets
Dieser Commit ist enthalten in:
Ursprung
335c34a679
Commit
1fd2bd9ee4
@ -21,7 +21,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
public class VelocityTabList implements TabList {
|
public class VelocityTabList implements TabList {
|
||||||
|
|
||||||
private final MinecraftConnection connection;
|
private final MinecraftConnection connection;
|
||||||
private final Map<UUID, TabListEntry> entries = new ConcurrentHashMap<>();
|
private final Map<UUID, VelocityTabListEntry> entries = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public VelocityTabList(MinecraftConnection connection) {
|
public VelocityTabList(MinecraftConnection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
@ -46,11 +46,13 @@ public class VelocityTabList implements TabList {
|
|||||||
"The provided entry was not created by this tab list");
|
"The provided entry was not created by this tab list");
|
||||||
Preconditions.checkArgument(!entries.containsKey(entry.getProfile().getId()),
|
Preconditions.checkArgument(!entries.containsKey(entry.getProfile().getId()),
|
||||||
"this TabList already contains an entry with the same uuid");
|
"this TabList already contains an entry with the same uuid");
|
||||||
|
Preconditions.checkArgument(entry instanceof VelocityTabListEntry,
|
||||||
|
"Not a Velocity tab list entry");
|
||||||
|
|
||||||
PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry);
|
PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry);
|
||||||
connection.write(
|
connection.write(
|
||||||
new PlayerListItem(PlayerListItem.ADD_PLAYER, Collections.singletonList(packetItem)));
|
new PlayerListItem(PlayerListItem.ADD_PLAYER, Collections.singletonList(packetItem)));
|
||||||
entries.put(entry.getProfile().getId(), entry);
|
entries.put(entry.getProfile().getId(), (VelocityTabListEntry) entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -111,7 +113,7 @@ public class VelocityTabList implements TabList {
|
|||||||
if (name == null || properties == null) {
|
if (name == null || properties == null) {
|
||||||
throw new IllegalStateException("Got null game profile for ADD_PLAYER");
|
throw new IllegalStateException("Got null game profile for ADD_PLAYER");
|
||||||
}
|
}
|
||||||
entries.put(item.getUuid(), TabListEntry.builder()
|
entries.put(item.getUuid(), (VelocityTabListEntry) TabListEntry.builder()
|
||||||
.tabList(this)
|
.tabList(this)
|
||||||
.profile(new GameProfile(uuid, name, properties))
|
.profile(new GameProfile(uuid, name, properties))
|
||||||
.displayName(item.getDisplayName())
|
.displayName(item.getDisplayName())
|
||||||
@ -124,23 +126,23 @@ public class VelocityTabList implements TabList {
|
|||||||
entries.remove(uuid);
|
entries.remove(uuid);
|
||||||
break;
|
break;
|
||||||
case PlayerListItem.UPDATE_DISPLAY_NAME: {
|
case PlayerListItem.UPDATE_DISPLAY_NAME: {
|
||||||
TabListEntry entry = entries.get(uuid);
|
VelocityTabListEntry entry = entries.get(uuid);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
entry.setDisplayName(item.getDisplayName());
|
entry.setDisplayNameInternal(item.getDisplayName());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PlayerListItem.UPDATE_LATENCY: {
|
case PlayerListItem.UPDATE_LATENCY: {
|
||||||
TabListEntry entry = entries.get(uuid);
|
VelocityTabListEntry entry = entries.get(uuid);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
entry.setLatency(item.getLatency());
|
entry.setLatencyInternal(item.getLatency());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PlayerListItem.UPDATE_GAMEMODE: {
|
case PlayerListItem.UPDATE_GAMEMODE: {
|
||||||
TabListEntry entry = entries.get(uuid);
|
VelocityTabListEntry entry = entries.get(uuid);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
entry.setLatency(item.getGameMode());
|
entry.setGameModeInternal(item.getGameMode());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,10 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setDisplayNameInternal(@Nullable Component displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLatency() {
|
public int getLatency() {
|
||||||
return latency;
|
return latency;
|
||||||
@ -59,6 +63,10 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setLatencyInternal(int latency) {
|
||||||
|
this.latency = latency;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getGameMode() {
|
public int getGameMode() {
|
||||||
return gameMode;
|
return gameMode;
|
||||||
@ -70,4 +78,8 @@ public class VelocityTabListEntry implements TabListEntry {
|
|||||||
tabList.updateEntry(PlayerListItem.UPDATE_GAMEMODE, this);
|
tabList.updateEntry(PlayerListItem.UPDATE_GAMEMODE, this);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setGameModeInternal(int gameMode) {
|
||||||
|
this.gameMode = gameMode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren