From 1b855d687beba3e1ace9bdcba391e9a55c4b03e4 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Thu, 2 Nov 2023 21:03:30 +0100 Subject: [PATCH] Updated ViaProxy API usage --- bootstrap/viaproxy/build.gradle.kts | 1 - .../viaproxy/GeyserViaProxyBootstrap.java | 2 +- .../viaproxy/GeyserViaProxyDumpInfo.java | 3 +- .../viaproxy/GeyserViaProxyPlugin.java | 30 ++++++++++++------- .../viaproxy/src/main/resources/viaproxy.yml | 2 +- gradle/libs.versions.toml | 2 +- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/bootstrap/viaproxy/build.gradle.kts b/bootstrap/viaproxy/build.gradle.kts index 31173ff5d..0a05f0e82 100644 --- a/bootstrap/viaproxy/build.gradle.kts +++ b/bootstrap/viaproxy/build.gradle.kts @@ -11,7 +11,6 @@ dependencies { platformRelocate("net.kyori") platformRelocate("org.yaml") platformRelocate("it.unimi.dsi.fastutil") -platformRelocate("com.mojang") platformRelocate("org.cloudburstmc.netty") // These dependencies are already present on the platform diff --git a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyBootstrap.java b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyBootstrap.java index 57027dc3c..c807cd7e6 100644 --- a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyBootstrap.java +++ b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyBootstrap.java @@ -73,7 +73,7 @@ public class GeyserViaProxyBootstrap implements GeyserBootstrap { return; } - config.getRemote().setAuthType(Options.ONLINE_MODE ? AuthType.ONLINE : AuthType.OFFLINE); + config.getRemote().setAuthType(AuthType.OFFLINE); GeyserConfiguration.checkGeyserConfiguration(this.config, this.logger); this.geyser = GeyserImpl.load(PlatformType.VIAPROXY, this); diff --git a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyDumpInfo.java b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyDumpInfo.java index 39056e8e2..0a073e509 100644 --- a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyDumpInfo.java +++ b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyDumpInfo.java @@ -27,7 +27,6 @@ package org.geysermc.geyser.platform.viaproxy; import lombok.Getter; import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.cli.options.Options; -import net.raphimc.viaproxy.plugins.PluginManager; import net.raphimc.viaproxy.plugins.ViaProxyPlugin; import org.geysermc.geyser.dump.BootstrapDumpInfo; import org.geysermc.geyser.text.AsteriskSerializer; @@ -54,7 +53,7 @@ public class GeyserViaProxyDumpInfo extends BootstrapDumpInfo { this.serverPort = Options.BIND_PORT; this.plugins = new ArrayList<>(); - for (ViaProxyPlugin plugin : PluginManager.getPlugins()) { + for (ViaProxyPlugin plugin : ViaProxy.getPluginManager().getPlugins()) { this.plugins.add(new PluginInfo(true, plugin.getName(), plugin.getVersion(), "unknown", Collections.singletonList(plugin.getAuthor()))); } } diff --git a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyPlugin.java b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyPlugin.java index 2c2941e9d..5bcb2fb18 100644 --- a/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyPlugin.java +++ b/bootstrap/viaproxy/src/main/java/org/geysermc/geyser/platform/viaproxy/GeyserViaProxyPlugin.java @@ -26,17 +26,20 @@ package org.geysermc.geyser.platform.viaproxy; import net.lenni0451.lambdaevents.EventHandler; +import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.plugins.PluginManager; import net.raphimc.viaproxy.plugins.ViaProxyPlugin; import net.raphimc.viaproxy.plugins.events.ConsoleCommandEvent; import net.raphimc.viaproxy.plugins.events.ProxyStartEvent; -import net.raphimc.viaproxy.plugins.events.ProxyStopEvent; +import net.raphimc.viaproxy.plugins.events.ShouldVerifyOnlineModeEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.text.GeyserLocale; import java.io.File; +import java.util.UUID; public class GeyserViaProxyPlugin extends ViaProxyPlugin { @@ -52,13 +55,12 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin { this.bootstrap = new GeyserViaProxyBootstrap(LOGGER, ROOT_FOLDER); GeyserLocale.init(this.bootstrap); this.bootstrap.onEnable(); - GeyserImpl.getInstance().shutdown(); - PluginManager.EVENT_MANAGER.register(this); + ViaProxy.EVENT_MANAGER.register(this); } @EventHandler - public void onConsoleCommand(final ConsoleCommandEvent event) { + private void onConsoleCommand(final ConsoleCommandEvent event) { if (event.getCommand().equals("geyser") || event.getCommand().equals("/geyser")) { event.setCancelled(true); @@ -66,17 +68,23 @@ public class GeyserViaProxyPlugin extends ViaProxyPlugin { } } - // Code below split apart from GeyserImpl.getInstance().reload(); - @EventHandler - public void onProxyStart(final ProxyStartEvent event) { - GeyserImpl.getInstance().extensionManager().enableExtensions(); - this.bootstrap.onEnable(); + private void onShouldVerifyOnlineModeEvent(final ShouldVerifyOnlineModeEvent event) { + final UUID uuid = event.getProxyConnection().getGameProfile().getId(); + if (uuid == null) return; + + final GeyserSession connection = GeyserImpl.getInstance().onlineConnections().stream().filter(s -> s.javaUuid().equals(uuid)).findAny().orElse(null); + if (connection == null) return; + + if (connection.javaUsername().equals(event.getProxyConnection().getGameProfile().getName())) { + event.setCancelled(true); + } } @EventHandler - public void onProxyStop(final ProxyStopEvent event) { - GeyserImpl.getInstance().shutdown(); + private void onProxyStart(final ProxyStartEvent event) { + GeyserImpl.getInstance().getSessionManager().disconnectAll("geyser.commands.reload.kick"); + GeyserImpl.getInstance().reload(); } } diff --git a/bootstrap/viaproxy/src/main/resources/viaproxy.yml b/bootstrap/viaproxy/src/main/resources/viaproxy.yml index 06a1c3e6b..22031df6e 100644 --- a/bootstrap/viaproxy/src/main/resources/viaproxy.yml +++ b/bootstrap/viaproxy/src/main/resources/viaproxy.yml @@ -2,4 +2,4 @@ name: "${name}-ViaProxy" version: "${version}" author: "${author}" main: "org.geysermc.geyser.platform.viaproxy.GeyserViaProxyPlugin" -min-version: "3.0.21" +min-version: "3.0.23" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 00c5fd582..2cba71745 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -28,7 +28,7 @@ adapters = "1.10-SNAPSHOT" commodore = "2.2" bungeecord = "a7c6ede" velocity = "3.1.1" -viaproxy = "3.0.21" +viaproxy = "3.0.23-SNAPSHOT" fabric-minecraft = "1.20.2" fabric-loader = "0.14.21" fabric-api = "0.89.0+1.20.2"