Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-26 00:00:55 +01:00
Fixed possible ConcurrentModificationException when iterating across TabList entries (#1204)
Dieser Commit ist enthalten in:
Ursprung
523d750f2b
Commit
d4a661870e
@ -38,7 +38,6 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -62,7 +61,7 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
public VelocityTabList(ConnectedPlayer player) {
|
public VelocityTabList(ConnectedPlayer player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.connection = player.getConnection();
|
this.connection = player.getConnection();
|
||||||
this.entries = Maps.newHashMap();
|
this.entries = Maps.newConcurrentMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,12 +100,11 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
Preconditions.checkNotNull(entry.getProfile(), "Profile cannot be null");
|
Preconditions.checkNotNull(entry.getProfile(), "Profile cannot be null");
|
||||||
Preconditions.checkNotNull(entry.getProfile().getId(), "Profile ID cannot be null");
|
Preconditions.checkNotNull(entry.getProfile().getId(), "Profile ID cannot be null");
|
||||||
|
|
||||||
TabListEntry previousEntry = this.entries.put(entry.getProfile().getId(), entry);
|
this.entries.compute(entry.getProfile().getId(), (uuid, previousEntry) -> {
|
||||||
|
|
||||||
if (previousEntry != null) {
|
if (previousEntry != null) {
|
||||||
// we should merge entries here
|
// we should merge entries here
|
||||||
if (previousEntry.equals(entry)) {
|
if (previousEntry.equals(entry)) {
|
||||||
return; // nothing else to do, this entry is perfect
|
return previousEntry; // nothing else to do, this entry is perfect
|
||||||
}
|
}
|
||||||
if (!Objects.equals(previousEntry.getDisplayNameComponent().orElse(null),
|
if (!Objects.equals(previousEntry.getDisplayNameComponent().orElse(null),
|
||||||
entry.getDisplayNameComponent().orElse(null))) {
|
entry.getDisplayNameComponent().orElse(null))) {
|
||||||
@ -165,6 +163,9 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
playerInfoEntry.setLatency(entry.getLatency());
|
playerInfoEntry.setLatency(entry.getLatency());
|
||||||
playerInfoEntry.setListed(entry.isListed());
|
playerInfoEntry.setListed(entry.isListed());
|
||||||
}
|
}
|
||||||
|
return entry;
|
||||||
|
});
|
||||||
|
|
||||||
this.connection.write(new UpsertPlayerInfoPacket(actions, List.of(playerInfoEntry)));
|
this.connection.write(new UpsertPlayerInfoPacket(actions, List.of(playerInfoEntry)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +187,7 @@ public class VelocityTabList implements InternalTabList {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<TabListEntry> getEntries() {
|
public Collection<TabListEntry> getEntries() {
|
||||||
return this.entries.values().stream().map(e -> (TabListEntry) e).collect(Collectors.toList());
|
return List.copyOf(this.entries.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren