From 62cded2dafa96e4f70a3e8d25c223d78fe2d4e19 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 9 Nov 2021 11:44:28 -0500 Subject: [PATCH] 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. --- .../bungeecord/GeyserBungeeInjector.java | 33 +++++++++++++++++-- .../bungeecord/GeyserBungeePlugin.java | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeInjector.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeInjector.java index d5dccd1da..25b36a14e 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeInjector.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeInjector.java @@ -35,7 +35,12 @@ import io.netty.channel.local.LocalAddress; import io.netty.util.AttributeKey; import net.md_5.bungee.api.ProxyServer; 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 org.geysermc.connector.GeyserConnector; import org.geysermc.connector.bootstrap.GeyserBootstrap; import org.geysermc.connector.common.GeyserInjector; @@ -43,16 +48,19 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Set; -public class GeyserBungeeInjector extends GeyserInjector { +public class GeyserBungeeInjector extends GeyserInjector implements Listener { + private final Plugin plugin; private final ProxyServer proxy; /** * Set as a variable so it is only set after the proxy has finished initializing */ private ChannelInitializer channelInitializer = null; private Set bungeeChannels = null; + private boolean eventRegistered = false; - public GeyserBungeeInjector(ProxyServer proxy) { - this.proxy = proxy; + public GeyserBungeeInjector(Plugin plugin) { + this.plugin = plugin; + this.proxy = plugin.getProxy(); } @Override @@ -142,6 +150,12 @@ public class GeyserBungeeInjector extends GeyserInjector { this.localChannel = channelFuture; this.bungeeChannels.add(this.localChannel.channel()); this.serverSocketAddress = channelFuture.channel().localAddress(); + + if (!this.eventRegistered) { + // Register reload listener + this.proxy.getPluginManager().registerListener(this.plugin, this); + this.eventRegistered = true; + } } @Override @@ -152,4 +166,17 @@ public class GeyserBungeeInjector extends GeyserInjector { } 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()); + } + } } diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index 548ec7210..64b10c650 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -118,7 +118,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { this.connector = GeyserConnector.start(PlatformType.BUNGEECORD, this); - this.geyserInjector = new GeyserBungeeInjector(getProxy()); + this.geyserInjector = new GeyserBungeeInjector(this); this.geyserInjector.initializeLocalChannel(this); this.geyserCommandManager = new GeyserBungeeCommandManager(connector);