3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 06:30:16 +02:00

Make EventTypeTracker actually thread-safe

Although I don't think anyone has actually triggered this bug in practice, we should still fix this.
Dieser Commit ist enthalten in:
Andrew Steinborn 2023-10-27 21:55:44 -04:00
Ursprung 115ac92d5c
Commit 908dd96015

Datei anzeigen

@ -17,29 +17,36 @@
package com.velocitypowered.proxy.event;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.reflect.TypeToken;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
class EventTypeTracker {
private final Multimap<Class<?>, Class<?>> friends;
private final ConcurrentMap<Class<?>, ImmutableSet<Class<?>>> friends;
public EventTypeTracker() {
this.friends = HashMultimap.create();
this.friends = new ConcurrentHashMap<>();
}
public Collection<Class<?>> getFriendsOf(final Class<?> eventType) {
if (friends.containsKey(eventType)) {
return ImmutableSet.copyOf(friends.get(eventType));
return friends.get(eventType);
}
final Collection<Class<?>> types = getFriendTypes(eventType);
for (Class<?> type : types) {
friends.put(type, eventType);
this.friends.merge(
type,
ImmutableSet.of(eventType),
(oldVal, newSingleton) -> ImmutableSet.<Class<?>>builder()
.addAll(oldVal)
.addAll(newSingleton)
.build()
);
}
return types;
}