3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

Allow Geyser-BungeeCord to continue working after /greload

We won't support reloading (neither does BungeeCord nor Waterfall), but at least Geyser will continue working after such a command is performed.
Dieser Commit ist enthalten in:
Camotoy 2021-11-09 11:44:28 -05:00
Ursprung 0274296366
Commit 62cded2daf
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 31 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -35,7 +35,12 @@ import io.netty.channel.local.LocalAddress;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.event.ProxyReloadEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.netty.PipelineUtils;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.bootstrap.GeyserBootstrap; import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.common.GeyserInjector; import org.geysermc.connector.common.GeyserInjector;
@ -43,16 +48,19 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Set; import java.util.Set;
public class GeyserBungeeInjector extends GeyserInjector { public class GeyserBungeeInjector extends GeyserInjector implements Listener {
private final Plugin plugin;
private final ProxyServer proxy; private final ProxyServer proxy;
/** /**
* Set as a variable so it is only set after the proxy has finished initializing * Set as a variable so it is only set after the proxy has finished initializing
*/ */
private ChannelInitializer<Channel> channelInitializer = null; private ChannelInitializer<Channel> channelInitializer = null;
private Set<Channel> bungeeChannels = null; private Set<Channel> bungeeChannels = null;
private boolean eventRegistered = false;
public GeyserBungeeInjector(ProxyServer proxy) { public GeyserBungeeInjector(Plugin plugin) {
this.proxy = proxy; this.plugin = plugin;
this.proxy = plugin.getProxy();
} }
@Override @Override
@ -142,6 +150,12 @@ public class GeyserBungeeInjector extends GeyserInjector {
this.localChannel = channelFuture; this.localChannel = channelFuture;
this.bungeeChannels.add(this.localChannel.channel()); this.bungeeChannels.add(this.localChannel.channel());
this.serverSocketAddress = channelFuture.channel().localAddress(); this.serverSocketAddress = channelFuture.channel().localAddress();
if (!this.eventRegistered) {
// Register reload listener
this.proxy.getPluginManager().registerListener(this.plugin, this);
this.eventRegistered = true;
}
} }
@Override @Override
@ -152,4 +166,17 @@ public class GeyserBungeeInjector extends GeyserInjector {
} }
super.shutdown(); super.shutdown();
} }
/**
* The reload process clears the listeners field. Since we need to add to the listeners for maximum compatibility,
* we also need to re-add and re-enable our listener if a reload is initiated.
*/
@EventHandler
public void onProxyReload(ProxyReloadEvent event) {
this.bungeeChannels = null;
if (this.localChannel != null) {
shutdown();
initializeLocalChannel(GeyserConnector.getInstance().getBootstrap());
}
}
} }

Datei anzeigen

@ -118,7 +118,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
this.connector = GeyserConnector.start(PlatformType.BUNGEECORD, this); this.connector = GeyserConnector.start(PlatformType.BUNGEECORD, this);
this.geyserInjector = new GeyserBungeeInjector(getProxy()); this.geyserInjector = new GeyserBungeeInjector(this);
this.geyserInjector.initializeLocalChannel(this); this.geyserInjector.initializeLocalChannel(this);
this.geyserCommandManager = new GeyserBungeeCommandManager(connector); this.geyserCommandManager = new GeyserBungeeCommandManager(connector);