From d44b523acb97336c28ceb5b15417aa2f871318c1 Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sun, 25 Feb 2024 19:57:04 +0100 Subject: [PATCH] Isolated Velocity --- api/build.gradle.kts | 2 +- .../api/event/bedrock/ClientEmoteEvent.java | 16 +++- .../api/event/bedrock/SessionLoginEvent.java | 24 +++++- .../downstream/ServerDefineCommandsEvent.java | 16 +++- .../event/java/ServerDefineCommandsEvent.java | 16 +++- bootstrap/bungeecord/base/build.gradle.kts | 8 +- .../bungeecord/isolated/build.gradle.kts | 35 ++++++++ .../src/main/resources/org.geysermc.mainClass | 1 + bootstrap/spigot/base/build.gradle.kts | 8 +- bootstrap/spigot/isolated/build.gradle.kts | 35 ++++++++ .../src/main/resources/org.geysermc.mainClass | 1 + bootstrap/standalone/build.gradle.kts | 1 + bootstrap/velocity/base/build.gradle.kts | 9 +- .../velocity/GeyserVelocityConfiguration.java | 2 +- ...lugin.java => GeyserVelocityPlatform.java} | 83 +++++++++---------- .../velocity/floodgate/FloodgateModule.java | 44 ---------- bootstrap/velocity/isolated/build.gradle.kts | 35 ++++++++ .../velocity/IsolatedVelocityPlugin.java | 80 ++++++++++++++++++ .../platform/velocity/VelocityMain.java} | 9 +- .../src/main/resources/org.geysermc.mainClass | 1 + .../src/main/resources/velocity-plugin.json | 1 + build.gradle.kts | 5 +- core/build.gradle.kts | 5 +- .../geyser/session/GeyserSession.java | 2 +- .../entity/player/BedrockEmoteTranslator.java | 2 +- .../protocol/java/JavaCommandsTranslator.java | 4 +- ...ronaut.core.convert.TypeConverterRegistrar | 10 +++ gradle.properties | 2 +- gradle/libs.versions.toml | 2 +- isolation/build.gradle.kts | 8 ++ .../java/org/geysermc/geyser/GeyserMain.java | 0 settings.gradle.kts | 1 + 32 files changed, 337 insertions(+), 131 deletions(-) create mode 100644 bootstrap/bungeecord/isolated/build.gradle.kts create mode 100644 bootstrap/bungeecord/isolated/src/main/resources/org.geysermc.mainClass create mode 100644 bootstrap/spigot/isolated/build.gradle.kts create mode 100644 bootstrap/spigot/isolated/src/main/resources/org.geysermc.mainClass rename bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/{GeyserVelocityPlugin.java => GeyserVelocityPlatform.java} (84%) delete mode 100644 bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/floodgate/FloodgateModule.java create mode 100644 bootstrap/velocity/isolated/build.gradle.kts create mode 100644 bootstrap/velocity/isolated/src/main/java/org/geysermc/geyser/platform/velocity/IsolatedVelocityPlugin.java rename bootstrap/velocity/{base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityMain.java => isolated/src/main/java/org/geysermc/geyser/platform/velocity/VelocityMain.java} (89%) create mode 100644 bootstrap/velocity/isolated/src/main/resources/org.geysermc.mainClass create mode 100644 bootstrap/velocity/isolated/src/main/resources/velocity-plugin.json create mode 100644 core/src/main/resources/META-INF/services/io.micronaut.core.convert.TypeConverterRegistrar create mode 100644 isolation/build.gradle.kts rename {core => isolation}/src/main/java/org/geysermc/geyser/GeyserMain.java (100%) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index bd54a9ce4..d0bb85e09 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("geyser.publish-conventions") + id("geyser.shadow-conventions") } dependencies { diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/ClientEmoteEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/ClientEmoteEvent.java index 35b6a9e73..d29a83f33 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/ClientEmoteEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/ClientEmoteEvent.java @@ -55,12 +55,24 @@ public final class ClientEmoteEvent extends ConnectionEvent implements Cancellab * event is cancelled, but other Bedrock players will not see. */ @Override - public boolean isCancelled() { + public boolean cancelled() { return cancelled; } @Override - public void setCancelled(boolean cancelled) { + public void cancelled(boolean cancelled) { this.cancelled = cancelled; } + + @Override + @Deprecated + public boolean isCancelled() { + return cancelled(); + } + + @Override + @Deprecated + public void setCancelled(boolean cancelled) { + cancelled(cancelled); + } } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoginEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoginEvent.java index c3c8198c1..28b99c635 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoginEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionLoginEvent.java @@ -52,7 +52,7 @@ public final class SessionLoginEvent extends ConnectionEvent implements Cancella * @return The cancel status of the event. */ @Override - public boolean isCancelled() { + public boolean cancelled() { return this.cancelled; } @@ -64,10 +64,11 @@ public final class SessionLoginEvent extends ConnectionEvent implements Cancella * @param cancelled If the login event should be cancelled. */ @Override - public void setCancelled(boolean cancelled) { + public void cancelled(boolean cancelled) { this.cancelled = cancelled; } + /** * Cancels the login event, and disconnects the player with the specified reason. * If cancelled, the player disconnects without connecting to the remote server. @@ -75,11 +76,28 @@ public final class SessionLoginEvent extends ConnectionEvent implements Cancella * @param cancelled If the login event should be cancelled. * @param disconnectReason The reason for the cancellation. */ - public void setCancelled(boolean cancelled, @NonNull String disconnectReason) { + public void cancelled(boolean cancelled, @NonNull String disconnectReason) { this.cancelled = cancelled; this.disconnectReason = disconnectReason; } + @Override + @Deprecated + public boolean isCancelled() { + return cancelled(); + } + + @Override + @Deprecated + public void setCancelled(boolean cancelled) { + cancelled(cancelled); + } + + @Deprecated + public void setCancelled(boolean cancelled, @NonNull String disconnectReason) { + cancelled(cancelled, disconnectReason); + } + /** * Returns the reason for the cancellation, or null if there is no reason given. * diff --git a/api/src/main/java/org/geysermc/geyser/api/event/downstream/ServerDefineCommandsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/downstream/ServerDefineCommandsEvent.java index ff4a1d074..893451fe4 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/downstream/ServerDefineCommandsEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/downstream/ServerDefineCommandsEvent.java @@ -58,15 +58,27 @@ public class ServerDefineCommandsEvent extends ConnectionEvent implements Cancel } @Override - public boolean isCancelled() { + public boolean cancelled() { return this.cancelled; } @Override - public void setCancelled(boolean cancelled) { + public void cancelled(boolean cancelled) { this.cancelled = cancelled; } + @Override + @Deprecated + public boolean isCancelled() { + return cancelled(); + } + + @Override + @Deprecated + public void setCancelled(boolean cancelled) { + cancelled(cancelled); + } + @Deprecated(forRemoval = true) public interface CommandInfo { /** diff --git a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerDefineCommandsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerDefineCommandsEvent.java index 299c9d6dd..ddca1fd10 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerDefineCommandsEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerDefineCommandsEvent.java @@ -58,15 +58,27 @@ public class ServerDefineCommandsEvent extends ConnectionEvent implements Cancel } @Override - public boolean isCancelled() { + public boolean cancelled() { return this.cancelled; } @Override - public void setCancelled(boolean cancelled) { + public void cancelled(boolean cancelled) { this.cancelled = cancelled; } + @Override + @Deprecated + public boolean isCancelled() { + return cancelled(); + } + + @Override + @Deprecated + public void setCancelled(boolean cancelled) { + cancelled(cancelled); + } + public interface CommandInfo { /** * Gets the name of the command. diff --git a/bootstrap/bungeecord/base/build.gradle.kts b/bootstrap/bungeecord/base/build.gradle.kts index d751a846c..66b507db0 100644 --- a/bootstrap/bungeecord/base/build.gradle.kts +++ b/bootstrap/bungeecord/base/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + id("geyser.publish-conventions") +} + dependencies { api(projects.core) @@ -15,10 +19,6 @@ platformRelocate("org.yaml") // Broken as of 1.20 // These dependencies are already present on the platform provided(libs.bungeecord.proxy) -application { - mainClass.set("org.geysermc.geyser.platform.bungeecord.GeyserBungeeMain") -} - tasks.withType { archiveBaseName.set("Geyser-BungeeCord") diff --git a/bootstrap/bungeecord/isolated/build.gradle.kts b/bootstrap/bungeecord/isolated/build.gradle.kts new file mode 100644 index 000000000..6516ba401 --- /dev/null +++ b/bootstrap/bungeecord/isolated/build.gradle.kts @@ -0,0 +1,35 @@ +plugins { + java +} + +dependencies { + api(projects.isolation) + compileOnlyApi(libs.velocity.api) +} + +application { + mainClass.set("org.geysermc.geyser.platform.bungeecord.BungeeMain") +} + +tasks { + jar { + dependsOn(":bungeecord-base:build", configurations.runtimeClasspath) + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) + + archiveBaseName = "geyser-${project.name}" + archiveVersion = "" + archiveClassifier = "" + + val libsDir = project.projects + .bungeecordBase.dependencyProject + .layout.buildDirectory.dir("libs") + + from(libsDir) { + include("Geyser-BungeeCord.jar") + rename("Geyser-BungeeCord.jar", "platform-base.jar") + into("bundled/") + } + } +} \ No newline at end of file diff --git a/bootstrap/bungeecord/isolated/src/main/resources/org.geysermc.mainClass b/bootstrap/bungeecord/isolated/src/main/resources/org.geysermc.mainClass new file mode 100644 index 000000000..ef05e2ceb --- /dev/null +++ b/bootstrap/bungeecord/isolated/src/main/resources/org.geysermc.mainClass @@ -0,0 +1 @@ +org.geysermc.geyser.platform.bungeecord.GeyserBungeePlatform \ No newline at end of file diff --git a/bootstrap/spigot/base/build.gradle.kts b/bootstrap/spigot/base/build.gradle.kts index 99436a27d..01895e585 100644 --- a/bootstrap/spigot/base/build.gradle.kts +++ b/bootstrap/spigot/base/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + id("geyser.publish-conventions") +} + dependencies { api(projects.core) api(libs.erosion.bukkit.common) { @@ -30,10 +34,6 @@ platformRelocate("org.yaml") // Broken as of 1.20 provided(libs.viaversion) provided("com.mojang", "authlib", "1.5.21") -application { - mainClass.set("org.geysermc.geyser.platform.spigot.GeyserSpigotMain") -} - tasks.withType { archiveBaseName.set("Geyser-Spigot") diff --git a/bootstrap/spigot/isolated/build.gradle.kts b/bootstrap/spigot/isolated/build.gradle.kts new file mode 100644 index 000000000..df1711f8a --- /dev/null +++ b/bootstrap/spigot/isolated/build.gradle.kts @@ -0,0 +1,35 @@ +plugins { + java +} + +dependencies { + api(projects.isolation) + compileOnlyApi(libs.velocity.api) +} + +application { + mainClass.set("org.geysermc.geyser.platform.spigot.SpigotMain") +} + +tasks { + jar { + dependsOn(":spigot-base:build", configurations.runtimeClasspath) + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) + + archiveBaseName = "geyser-${project.name}" + archiveVersion = "" + archiveClassifier = "" + + val libsDir = project.projects + .spigotBase.dependencyProject + .layout.buildDirectory.dir("libs") + + from(libsDir) { + include("Geyser-Spigot.jar") + rename("Geyser-Spigot.jar", "platform-base.jar") + into("bundled/") + } + } +} \ No newline at end of file diff --git a/bootstrap/spigot/isolated/src/main/resources/org.geysermc.mainClass b/bootstrap/spigot/isolated/src/main/resources/org.geysermc.mainClass new file mode 100644 index 000000000..447ac758f --- /dev/null +++ b/bootstrap/spigot/isolated/src/main/resources/org.geysermc.mainClass @@ -0,0 +1 @@ +org.geysermc.geyser.platform.spigot.GeyserSpigotPlatform \ No newline at end of file diff --git a/bootstrap/standalone/build.gradle.kts b/bootstrap/standalone/build.gradle.kts index eaf895108..29934f5e1 100644 --- a/bootstrap/standalone/build.gradle.kts +++ b/bootstrap/standalone/build.gradle.kts @@ -4,6 +4,7 @@ val terminalConsoleVersion = "1.2.0" val jlineVersion = "3.21.0" dependencies { + api(projects.api) api(projects.core) implementation(libs.terminalconsoleappender) { diff --git a/bootstrap/velocity/base/build.gradle.kts b/bootstrap/velocity/base/build.gradle.kts index 7b7bd17e0..8d60795ef 100644 --- a/bootstrap/velocity/base/build.gradle.kts +++ b/bootstrap/velocity/base/build.gradle.kts @@ -1,5 +1,8 @@ +plugins { + id("geyser.publish-conventions") +} + dependencies { - annotationProcessor(libs.velocity.api) implementation(libs.floodgate.velocity) api(projects.core) @@ -38,10 +41,6 @@ exclude("net.kyori:adventure-text-serializer-gson:*") exclude("net.kyori:adventure-text-serializer-legacy:*") exclude("net.kyori:adventure-nbt:*") -application { - mainClass.set("org.geysermc.geyser.platform.velocity.GeyserVelocityMain") -} - tasks.withType { archiveBaseName.set("Geyser-Velocity") diff --git a/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityConfiguration.java b/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityConfiguration.java index 4c8ea53cc..6115fa532 100644 --- a/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityConfiguration.java +++ b/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityConfiguration.java @@ -44,7 +44,7 @@ public final class GeyserVelocityConfiguration extends GeyserJacksonConfiguratio @JsonIgnore private Path floodgateKeyPath; - public void loadFloodgate(GeyserVelocityPlugin plugin, ProxyServer proxyServer, File dataFolder) { + public void loadFloodgate(GeyserVelocityPlatform plugin, ProxyServer proxyServer, File dataFolder) { Optional floodgate = proxyServer.getPluginManager().getPlugin("floodgate"); Path floodgateDataPath = floodgate.isPresent() ? Paths.get("plugins/floodgate/") : null; floodgateKeyPath = FloodgateKeyLoader.getKeyPath(this, floodgateDataPath, dataFolder.toPath(), plugin.getGeyserLogger()); diff --git a/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java b/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlatform.java similarity index 84% rename from bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java rename to bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlatform.java index f0c6edd73..b9eb228fc 100644 --- a/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java +++ b/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlatform.java @@ -28,18 +28,22 @@ package org.geysermc.geyser.platform.velocity; import com.google.inject.Inject; import com.google.inject.Injector; import com.velocitypowered.api.command.CommandManager; -import com.velocitypowered.api.event.Subscribe; -import com.velocitypowered.api.event.proxy.ListenerBoundEvent; -import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; -import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; -import com.velocitypowered.api.network.ListenerType; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.proxy.ProxyServer; +import java.io.File; +import java.io.IOException; +import java.net.SocketAddress; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; +import java.util.UUID; import lombok.Getter; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.floodgate.core.FloodgatePlatform; +import org.geysermc.floodgate.isolation.IsolatedPlatform; +import org.geysermc.floodgate.isolation.library.LibraryManager; import org.geysermc.floodgate.velocity.VelocityPlatform; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; @@ -54,21 +58,11 @@ import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough; import org.geysermc.geyser.ping.IGeyserPingPassthrough; import org.geysermc.geyser.platform.velocity.command.GeyserVelocityCommandExecutor; -import org.geysermc.geyser.platform.velocity.floodgate.FloodgateModule; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.FileUtils; import org.slf4j.Logger; -import java.io.File; -import java.io.IOException; -import java.net.SocketAddress; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Map; -import java.util.UUID; - -@Plugin(id = "geyser", name = GeyserImpl.NAME + "-Velocity", version = GeyserImpl.VERSION, url = "https://geysermc.org", authors = "GeyserMC") -public class GeyserVelocityPlugin implements GeyserBootstrap { +public class GeyserVelocityPlatform implements GeyserBootstrap, IsolatedPlatform { @Inject private Logger logger; @@ -87,10 +81,12 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { private GeyserImpl geyser; @Getter - private final Path configFolder = Paths.get("plugins/" + GeyserImpl.NAME + "-Velocity/"); + private final Path configFolder = Paths.get("plugins/" + GeyserImpl.NAME + "-Velocity/"); //todo remove - @Inject - private Injector guice; + @Inject Injector guice; + @Inject LibraryManager manager; // don't remove! We don't need it in Geyser, but in Floodgate. Weird Guice stuff + + @Inject PluginContainer container; @Override public void onGeyserInitialize() { @@ -114,7 +110,7 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { FloodgatePlatform platform = null; if (geyserConfig.getRemote().authType() == AuthType.FLOODGATE) { - platform = guice.createChildInjector(new FloodgateModule(configFolder)).getInstance(VelocityPlatform.class); + platform = guice.getInstance(VelocityPlatform.class); } this.geyser = GeyserImpl.load(PlatformType.VELOCITY, this, platform); @@ -157,7 +153,7 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { this.commandManager.register(entry.getKey().description().id(), new GeyserVelocityCommandExecutor(this.geyser, commands)); } - proxyServer.getEventManager().register(this, new GeyserVelocityUpdateListener()); + proxyServer.getEventManager().register(container, new GeyserVelocityUpdateListener()); } @Override @@ -197,29 +193,6 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { return geyserPingPassthrough; } - @Subscribe - public void onInit(ProxyInitializeEvent event) { - this.onGeyserInitialize(); - } - - @Subscribe - public void onShutdown(ProxyShutdownEvent event) { - this.onGeyserShutdown(); - } - - @Subscribe - public void onProxyBound(ListenerBoundEvent event) { - if (event.getListenerType() == ListenerType.MINECRAFT) { - // Once listener is bound, do our startup process - this.onGeyserEnable(); - - if (geyserInjector != null) { - // After this bound, we know that the channel initializer cannot change without it being ineffective for Velocity, too - geyserInjector.initializeLocalChannel(this); - } - } - } - @Override public BootstrapDumpInfo getDumpInfo() { return new GeyserVelocityDumpInfo(proxyServer); @@ -268,4 +241,24 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { } return true; } + + @Override + public void load() { + this.onGeyserInitialize(); + } + + @Override + public void enable() { + this.onGeyserEnable(); + + if (geyserInjector != null) { + // After this bound, we know that the channel initializer cannot change without it being ineffective for Velocity, too + geyserInjector.initializeLocalChannel(this); + } + } + + @Override + public void disable() { + this.onGeyserDisable(); + } } diff --git a/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/floodgate/FloodgateModule.java b/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/floodgate/FloodgateModule.java deleted file mode 100644 index 887ec3d2e..000000000 --- a/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/floodgate/FloodgateModule.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.platform.velocity.floodgate; - -import com.google.inject.AbstractModule; -import java.nio.file.Path; -import org.geysermc.floodgate.isolation.library.LibraryManager; - -public class FloodgateModule extends AbstractModule { - private final Path dataDirectory; - - public FloodgateModule(Path dataDirectory) { - this.dataDirectory = dataDirectory; - } - - @Override - protected void configure() { - var libsDirectory = dataDirectory.resolve("libs"); - bind(LibraryManager.class).toInstance(new LibraryManager(getClass().getClassLoader(), libsDirectory, true)); - } -} diff --git a/bootstrap/velocity/isolated/build.gradle.kts b/bootstrap/velocity/isolated/build.gradle.kts new file mode 100644 index 000000000..5dab639c2 --- /dev/null +++ b/bootstrap/velocity/isolated/build.gradle.kts @@ -0,0 +1,35 @@ +plugins { + java +} + +dependencies { + api(projects.isolation) + compileOnlyApi(libs.velocity.api) +} + +application { + mainClass.set("org.geysermc.geyser.platform.velocity.VelocityMain") +} + +tasks { + jar { + dependsOn(":velocity-base:build", configurations.runtimeClasspath) + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) + + archiveBaseName = "geyser-${project.name}" + archiveVersion = "" + archiveClassifier = "" + + val libsDir = project.projects + .velocityBase.dependencyProject + .layout.buildDirectory.dir("libs") + + from(libsDir) { + include("Geyser-Velocity.jar") + rename("Geyser-Velocity.jar", "platform-base.jar") + into("bundled/") + } + } +} \ No newline at end of file diff --git a/bootstrap/velocity/isolated/src/main/java/org/geysermc/geyser/platform/velocity/IsolatedVelocityPlugin.java b/bootstrap/velocity/isolated/src/main/java/org/geysermc/geyser/platform/velocity/IsolatedVelocityPlugin.java new file mode 100644 index 000000000..285656cba --- /dev/null +++ b/bootstrap/velocity/isolated/src/main/java/org/geysermc/geyser/platform/velocity/IsolatedVelocityPlugin.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2019-2024 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ +package org.geysermc.geyser.platform.velocity; + +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Injector; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ListenerBoundEvent; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; +import com.velocitypowered.api.network.ListenerType; +import com.velocitypowered.api.plugin.annotation.DataDirectory; +import java.nio.file.Path; +import org.geysermc.floodgate.isolation.library.LibraryManager; +import org.geysermc.floodgate.isolation.loader.PlatformHolder; +import org.geysermc.floodgate.isolation.loader.PlatformLoader; + +public final class IsolatedVelocityPlugin { + private final PlatformHolder holder; + + @Inject + public IsolatedVelocityPlugin(Injector guice, @DataDirectory Path dataDirectory) { + try { + var libsDirectory = dataDirectory.resolve("libs"); + + holder = PlatformLoader.loadDefault(getClass().getClassLoader(), libsDirectory); + Injector child = guice.createChildInjector(new AbstractModule() { + @Override + protected void configure() { + bind(LibraryManager.class).toInstance(holder.manager()); + } + }); + + holder.platformInstance(child.getInstance(holder.platformClass())); + } catch (Exception exception) { + throw new RuntimeException("Failed to load Floodgate", exception); + } + } + + @Subscribe + public void onInit(ProxyInitializeEvent event) { + holder.load(); + } + + @Subscribe + public void onShutdown(ProxyShutdownEvent event) { + holder.disable(); + } + + @Subscribe + public void onProxyBound(ListenerBoundEvent event) { + if (event.getListenerType() == ListenerType.MINECRAFT) { + // Once listener is bound, do our startup process + holder.enable(); + } + } +} diff --git a/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityMain.java b/bootstrap/velocity/isolated/src/main/java/org/geysermc/geyser/platform/velocity/VelocityMain.java similarity index 89% rename from bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityMain.java rename to bootstrap/velocity/isolated/src/main/java/org/geysermc/geyser/platform/velocity/VelocityMain.java index 8e469b03b..b24b14c7c 100644 --- a/bootstrap/velocity/base/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityMain.java +++ b/bootstrap/velocity/isolated/src/main/java/org/geysermc/geyser/platform/velocity/VelocityMain.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org + * Copyright (c) 2019-2024 GeyserMC. http://geysermc.org * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,10 +27,9 @@ package org.geysermc.geyser.platform.velocity; import org.geysermc.geyser.GeyserMain; -public class GeyserVelocityMain extends GeyserMain { - +public class VelocityMain extends GeyserMain { public static void main(String[] args) { - new GeyserVelocityMain().displayMessage(); + new VelocityMain().displayMessage(); } public String getPluginType() { @@ -40,4 +39,4 @@ public class GeyserVelocityMain extends GeyserMain { public String getPluginFolder() { return "plugins"; } -} +} \ No newline at end of file diff --git a/bootstrap/velocity/isolated/src/main/resources/org.geysermc.mainClass b/bootstrap/velocity/isolated/src/main/resources/org.geysermc.mainClass new file mode 100644 index 000000000..b60845f11 --- /dev/null +++ b/bootstrap/velocity/isolated/src/main/resources/org.geysermc.mainClass @@ -0,0 +1 @@ +org.geysermc.geyser.platform.velocity.GeyserVelocityPlatform \ No newline at end of file diff --git a/bootstrap/velocity/isolated/src/main/resources/velocity-plugin.json b/bootstrap/velocity/isolated/src/main/resources/velocity-plugin.json new file mode 100644 index 000000000..866dd5d9a --- /dev/null +++ b/bootstrap/velocity/isolated/src/main/resources/velocity-plugin.json @@ -0,0 +1 @@ +{"id": "${id}", "name": "${name}", "version": "${version}", "description": "${description}", "url": "${url}", "authors": ["${author}"], "main": "org.geysermc.geyser.platform.velocity.IsolatedVelocityPlugin"} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 9fa1fe60f..36294eaaf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ plugins { `java-library` // Ensure AP works in eclipse (no effect on other IDEs) - `eclipse` + eclipse id("geyser.build-logic") id("io.freefair.lombok") version "8.3" apply false } @@ -21,12 +21,9 @@ java { val platforms = setOf( projects.fabric, projects.bungeecord, - projects.bungeecordBase, projects.spigot, - projects.spigotBase, projects.standalone, projects.velocity, - projects.velocityBase ).map { it.dependencyProject } subprojects { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 8d81611bc..7e54cc725 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -8,9 +8,8 @@ plugins { dependencies { api(libs.floodgate.core) - api(libs.floodgate.isolation) - annotationProcessor(libs.floodgate.core) - api(projects.api) + compileOnlyApi(libs.base.api) + compileOnlyApi(projects.isolation) // Jackson JSON and YAML serialization api(libs.bundles.jackson) diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index b4f260d69..c58d3d4dc 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -929,7 +929,7 @@ public class GeyserSession extends FloodgateConnection implements GeyserConnecti private void connectDownstream() { SessionLoginEvent loginEvent = new SessionLoginEvent(this, remoteServer); GeyserImpl.getInstance().eventBus().fire(loginEvent); - if (loginEvent.isCancelled()) { + if (loginEvent.cancelled()) { String disconnectReason = loginEvent.disconnectReason() == null ? BedrockDisconnectReasons.DISCONNECTED : loginEvent.disconnectReason(); disconnect(disconnectReason); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java index 7a37aa72e..cce450d99 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java @@ -51,7 +51,7 @@ public class BedrockEmoteTranslator extends PacketTranslator { // For the future: could have a method that exposes which players will see the emote ClientEmoteEvent event = new ClientEmoteEvent(session, packet.getEmoteId()); session.getGeyser().eventBus().fire(event); - if (event.isCancelled()) { + if (event.cancelled()) { return; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCommandsTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCommandsTranslator.java index 0d7f45c7d..9db725b35 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCommandsTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaCommandsTranslator.java @@ -152,13 +152,13 @@ public class JavaCommandsTranslator extends PacketTranslator