1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2026-01-06 15:42:03 +00:00

Merge remote-tracking branch 'origin/feature/weak-references' into development

This commit is contained in:
Tim203
2022-12-29 00:32:33 +01:00
3 changed files with 41 additions and 26 deletions

View File

@@ -26,18 +26,17 @@
package org.geysermc.floodgate.inject;
import io.netty.channel.Channel;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import lombok.AccessLevel;
import lombok.Getter;
import java.util.WeakHashMap;
import org.geysermc.floodgate.api.inject.InjectorAddon;
import org.geysermc.floodgate.api.inject.PlatformInjector;
public abstract class CommonPlatformInjector implements PlatformInjector {
@Getter(AccessLevel.PROTECTED)
private final Set<Channel> injectedClients = new HashSet<>();
private final Set<Channel> injectedClients =
Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));
private final Map<Class<?>, InjectorAddon> addons = new HashMap<>();
@@ -49,6 +48,10 @@ public abstract class CommonPlatformInjector implements PlatformInjector {
return injectedClients.remove(channel);
}
public Set<Channel> injectedClients() {
return injectedClients;
}
@Override
public boolean addAddon(InjectorAddon addon) {
return addons.putIfAbsent(addon.getClass(), addon) == null;