geforkt von Mirrors/Velocity
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 {
|
||||
|
||||
private final MinecraftConnection connection;
|
||||
private final Map<UUID, TabListEntry> entries = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, VelocityTabListEntry> entries = new ConcurrentHashMap<>();
|
||||
|
||||
public VelocityTabList(MinecraftConnection connection) {
|
||||
this.connection = connection;
|
||||
@ -46,11 +46,13 @@ public class VelocityTabList implements TabList {
|
||||
"The provided entry was not created by this tab list");
|
||||
Preconditions.checkArgument(!entries.containsKey(entry.getProfile().getId()),
|
||||
"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);
|
||||
connection.write(
|
||||
new PlayerListItem(PlayerListItem.ADD_PLAYER, Collections.singletonList(packetItem)));
|
||||
entries.put(entry.getProfile().getId(), entry);
|
||||
entries.put(entry.getProfile().getId(), (VelocityTabListEntry) entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -111,7 +113,7 @@ public class VelocityTabList implements TabList {
|
||||
if (name == null || properties == null) {
|
||||
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)
|
||||
.profile(new GameProfile(uuid, name, properties))
|
||||
.displayName(item.getDisplayName())
|
||||
@ -124,23 +126,23 @@ public class VelocityTabList implements TabList {
|
||||
entries.remove(uuid);
|
||||
break;
|
||||
case PlayerListItem.UPDATE_DISPLAY_NAME: {
|
||||
TabListEntry entry = entries.get(uuid);
|
||||
VelocityTabListEntry entry = entries.get(uuid);
|
||||
if (entry != null) {
|
||||
entry.setDisplayName(item.getDisplayName());
|
||||
entry.setDisplayNameInternal(item.getDisplayName());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerListItem.UPDATE_LATENCY: {
|
||||
TabListEntry entry = entries.get(uuid);
|
||||
VelocityTabListEntry entry = entries.get(uuid);
|
||||
if (entry != null) {
|
||||
entry.setLatency(item.getLatency());
|
||||
entry.setLatencyInternal(item.getLatency());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerListItem.UPDATE_GAMEMODE: {
|
||||
TabListEntry entry = entries.get(uuid);
|
||||
VelocityTabListEntry entry = entries.get(uuid);
|
||||
if (entry != null) {
|
||||
entry.setLatency(item.getGameMode());
|
||||
entry.setGameModeInternal(item.getGameMode());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -47,6 +47,10 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
return this;
|
||||
}
|
||||
|
||||
void setDisplayNameInternal(@Nullable Component displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLatency() {
|
||||
return latency;
|
||||
@ -59,6 +63,10 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
return this;
|
||||
}
|
||||
|
||||
void setLatencyInternal(int latency) {
|
||||
this.latency = latency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGameMode() {
|
||||
return gameMode;
|
||||
@ -70,4 +78,8 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
tabList.updateEntry(PlayerListItem.UPDATE_GAMEMODE, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
void setGameModeInternal(int gameMode) {
|
||||
this.gameMode = gameMode;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren