Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01: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:
Ursprung
115ac92d5c
Commit
908dd96015
@ -17,29 +17,36 @@
|
|||||||
|
|
||||||
package com.velocitypowered.proxy.event;
|
package com.velocitypowered.proxy.event;
|
||||||
|
|
||||||
import com.google.common.collect.HashMultimap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
class EventTypeTracker {
|
class EventTypeTracker {
|
||||||
|
|
||||||
private final Multimap<Class<?>, Class<?>> friends;
|
private final ConcurrentMap<Class<?>, ImmutableSet<Class<?>>> friends;
|
||||||
|
|
||||||
public EventTypeTracker() {
|
public EventTypeTracker() {
|
||||||
this.friends = HashMultimap.create();
|
this.friends = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Class<?>> getFriendsOf(final Class<?> eventType) {
|
public Collection<Class<?>> getFriendsOf(final Class<?> eventType) {
|
||||||
if (friends.containsKey(eventType)) {
|
if (friends.containsKey(eventType)) {
|
||||||
return ImmutableSet.copyOf(friends.get(eventType));
|
return friends.get(eventType);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Collection<Class<?>> types = getFriendTypes(eventType);
|
final Collection<Class<?>> types = getFriendTypes(eventType);
|
||||||
for (Class<?> type : types) {
|
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;
|
return types;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren