2929import net .md_5 .bungee .BungeeCord ;
3030import net .md_5 .bungee .Util ;
3131import net .md_5 .bungee .api .CommandSender ;
32+ import net .md_5 .bungee .api .ProxyServer ;
3233import net .md_5 .bungee .api .config .ListenerInfo ;
3334import net .md_5 .bungee .api .plugin .Plugin ;
3435import net .md_5 .bungee .protocol .ProtocolConstants ;
3536import org .checkerframework .checker .nullness .qual .NonNull ;
3637import org .checkerframework .checker .nullness .qual .Nullable ;
3738import org .geysermc .floodgate .core .skin .SkinApplier ;
39+ import org .geysermc .floodgate .isolation .IsolatedPlatform ;
40+ import org .geysermc .floodgate .isolation .library .LibraryManager ;
3841import org .geysermc .geyser .FloodgateKeyLoader ;
3942import org .geysermc .geyser .GeyserBootstrap ;
4043import org .geysermc .geyser .GeyserImpl ;
6669import java .util .Optional ;
6770import java .util .concurrent .TimeUnit ;
6871
69- public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
72+ public class GeyserBungeePlatform implements GeyserBootstrap , IsolatedPlatform {
73+
74+ private final ProxyServer proxyServer = ProxyServer .getInstance ();
75+ private final Plugin plugin ;
76+ private final GeyserBungeeLogger geyserLogger ;
7077
7178 private CommandRegistry commandRegistry ;
7279 private GeyserPluginConfig geyserConfig ;
7380 private GeyserBungeeInjector geyserInjector ;
74- private final GeyserBungeeLogger geyserLogger = new GeyserBungeeLogger (getLogger ());
7581 private IGeyserPingPassthrough geyserBungeePingPassthrough ;
7682 private GeyserImpl geyser ;
7783
84+ final LibraryManager manager ; // don't remove! We don't need it in Geyser, but in Floodgate
85+
86+ public GeyserBungeePlatform (LibraryManager manager , Plugin plugin ) {
87+ this .manager = manager ;
88+ this .plugin = plugin ;
89+ this .geyserLogger = new GeyserBungeeLogger (plugin .getLogger ());
90+ }
91+
7892 @ Override
79- public void onLoad () {
93+ public void load () {
8094 onGeyserInitialize ();
8195 }
8296
@@ -90,7 +104,7 @@ public void onGeyserInitialize() {
90104 geyserLogger .error (" / \\ " );
91105 geyserLogger .error (" / \\ " );
92106 geyserLogger .error (" / | \\ " );
93- geyserLogger .error (" / | \\ " + GeyserLocale .getLocaleStringLog ("geyser.bootstrap.unsupported_proxy" , getProxy () .getName ()));
107+ geyserLogger .error (" / | \\ " + GeyserLocale .getLocaleStringLog ("geyser.bootstrap.unsupported_proxy" , proxyServer .getName ()));
94108 geyserLogger .error (" / \\ " + GeyserLocale .getLocaleStringLog ("geyser.may_not_work_as_intended_all_caps" ));
95109 geyserLogger .error (" / o \\ " );
96110 geyserLogger .error ("/_____________\\ " );
@@ -109,27 +123,27 @@ public void onGeyserInitialize() {
109123 return ;
110124 }
111125 this .geyser = GeyserImpl .load (this );
112- this .geyserInjector = new GeyserBungeeInjector (this );
126+ this .geyserInjector = new GeyserBungeeInjector (plugin );
113127
114128 // Registration of listeners occurs only once
115- this . getProxy (). getPluginManager ().registerListener (this , new GeyserBungeeUpdateListener ());
129+ proxyServer . getPluginManager ().registerListener (plugin , new GeyserBungeeUpdateListener ());
116130 }
117131
118132 @ Override
119- public void onEnable () {
133+ public void enable () {
120134 if (geyser == null ) {
121135 return ; // Config did not load properly!
122136 }
123137
124138 // After Geyser initialize for parity with other platforms.
125139 var sourceConverter = new CommandSourceConverter <>(
126140 CommandSender .class ,
127- id -> getProxy (). getPlayer ( id ) ,
128- () -> getProxy (). getConsole () ,
141+ proxyServer :: getPlayer ,
142+ proxyServer :: getConsole ,
129143 BungeeCommandSource ::new
130144 );
131145 CommandManager <GeyserCommandSource > cloud = new BungeeCommandManager <>(
132- this ,
146+ plugin ,
133147 ExecutionCoordinator .simpleCoordinator (),
134148 sourceConverter
135149 );
@@ -158,7 +172,7 @@ private void awaitStartupCompletion(int tries) {
158172
159173 Collection <Channel > listeners = (Collection <Channel >) listenersField .get (BungeeCord .getInstance ());
160174 if (listeners .isEmpty ()) {
161- this . getProxy (). getScheduler ().schedule (this , this ::onGeyserEnable , tries , TimeUnit .SECONDS );
175+ proxyServer . getScheduler ().schedule (plugin , this ::onGeyserEnable , tries , TimeUnit .SECONDS );
162176 } else {
163177 this .awaitStartupCompletion (++tries );
164178 }
@@ -176,7 +190,7 @@ public void onGeyserEnable() {
176190 }
177191
178192 // Force-disable query if enabled, or else Geyser won't enable
179- for (ListenerInfo info : getProxy () .getConfig ().getListeners ()) {
193+ for (ListenerInfo info : proxyServer .getConfig ().getListeners ()) {
180194 if (info .isQueryEnabled () && info .getQueryPort () == geyserConfig .bedrock ().port ()) {
181195 try {
182196 Field queryField = ListenerInfo .class .getDeclaredField ("queryEnabled" );
@@ -193,20 +207,20 @@ public void onGeyserEnable() {
193207 }
194208 }
195209
196- if (getProxy () .getPluginManager ().getPlugin ("floodgate" ) != null ) {
210+ if (proxyServer .getPluginManager ().getPlugin ("floodgate" ) != null ) {
197211 geyserLogger .warning ("WHY DO YOU HAVE FLOODGATE INSTALLED???1/" );
198212 }
199213
200214 if (geyserConfig .java ().authType () == AuthType .FLOODGATE ) {
201- getProxy () .getPluginManager ().registerListener (this , new BungeeHybridListener ());
215+ proxyServer .getPluginManager ().registerListener (plugin , new BungeeHybridListener ());
202216 }
203217
204218 GeyserImpl .start ();
205219
206220 if (!geyserConfig .motd ().integratedPingPassthrough ()) {
207221 this .geyserBungeePingPassthrough = GeyserLegacyPingPassthrough .init (geyser );
208222 } else {
209- this .geyserBungeePingPassthrough = new GeyserBungeePingPassthrough (getProxy () );
223+ this .geyserBungeePingPassthrough = new GeyserBungeePingPassthrough (proxyServer );
210224 }
211225
212226 // No need to re-register commands or re-init injector when reloading
@@ -235,7 +249,12 @@ public void onGeyserShutdown() {
235249 }
236250
237251 @ Override
238- public void onDisable () {
252+ public void disable () {
253+ this .onGeyserDisable ();
254+ }
255+
256+ @ Override
257+ public void shutdown () {
239258 this .onGeyserShutdown ();
240259 }
241260
@@ -266,22 +285,22 @@ public IGeyserPingPassthrough getGeyserPingPassthrough() {
266285
267286 @ Override
268287 public Path getConfigFolder () {
269- return getDataFolder ().toPath ();
288+ return plugin . getDataFolder ().toPath ();
270289 }
271290
272291 @ Override
273292 public BootstrapDumpInfo getDumpInfo () {
274- return new GeyserBungeeDumpInfo (getProxy () );
293+ return new GeyserBungeeDumpInfo (proxyServer );
275294 }
276295
277296 @ Override
278297 public Path getLogsPath () {
279- return Paths .get (getProxy () .getName ().equals ("BungeeCord" ) ? "proxy.log.0" : "logs/latest.log" );
298+ return Paths .get (proxyServer .getName ().equals ("BungeeCord" ) ? "proxy.log.0" : "logs/latest.log" );
280299 }
281300
282301 @ Override
283302 public @ NonNull String getServerPlatform () {
284- return getProxy () .getName ();
303+ return proxyServer .getName ();
285304 }
286305
287306 @ Nullable
@@ -303,13 +322,13 @@ public int getServerPort() {
303322
304323 @ Override
305324 public boolean testFloodgatePluginPresent () {
306- return getProxy () .getPluginManager ().getPlugin ("floodgate" ) != null ;
325+ return proxyServer .getPluginManager ().getPlugin ("floodgate" ) != null ;
307326 }
308327
309328 @ Override
310329 public Path getFloodgateKeyPath () {
311- Plugin floodgate = getProxy () .getPluginManager ().getPlugin ("floodgate" );
312- Path geyserDataFolder = getDataFolder ().toPath ();
330+ Plugin floodgate = proxyServer .getPluginManager ().getPlugin ("floodgate" );
331+ Path geyserDataFolder = plugin . getDataFolder ().toPath ();
313332 Path floodgateDataFolder = floodgate != null ? floodgate .getDataFolder ().toPath () : null ;
314333
315334 return FloodgateKeyLoader .getKeyPath (geyserConfig , floodgateDataFolder , geyserDataFolder , geyserLogger );
@@ -318,7 +337,7 @@ public Path getFloodgateKeyPath() {
318337 @ Override
319338 public MetricsPlatform createMetricsPlatform () {
320339 try {
321- return new BungeeMetrics (this );
340+ return new BungeeMetrics (plugin );
322341 } catch (IOException e ) {
323342 this .geyserLogger .debug ("Integrated bStats support failed to load." );
324343 if (this .config ().debugMode ()) {
@@ -329,7 +348,7 @@ public MetricsPlatform createMetricsPlatform() {
329348 }
330349
331350 private Optional <InetSocketAddress > findCompatibleListener () {
332- var listeners = getProxy () .getConfig ().getListeners ();
351+ var listeners = proxyServer .getConfig ().getListeners ();
333352 if (listeners .size () == 1 ) {
334353 return listeners .stream ()
335354 .filter (info -> info .getSocketAddress () instanceof InetSocketAddress )
0 commit comments