Isolated Velocity

This commit is contained in:
Tim203 2024-02-25 19:57:04 +01:00
parent bc301fba60
commit d44b523acb
No known key found for this signature in database
32 changed files with 337 additions and 131 deletions

View file

@ -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<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
archiveBaseName.set("Geyser-BungeeCord")

View file

@ -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/")
}
}
}

View file

@ -0,0 +1 @@
org.geysermc.geyser.platform.bungeecord.GeyserBungeePlatform

View file

@ -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<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
archiveBaseName.set("Geyser-Spigot")

View file

@ -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/")
}
}
}

View file

@ -0,0 +1 @@
org.geysermc.geyser.platform.spigot.GeyserSpigotPlatform

View file

@ -4,6 +4,7 @@ val terminalConsoleVersion = "1.2.0"
val jlineVersion = "3.21.0"
dependencies {
api(projects.api)
api(projects.core)
implementation(libs.terminalconsoleappender) {

View file

@ -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<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
archiveBaseName.set("Geyser-Velocity")

View file

@ -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<PluginContainer> floodgate = proxyServer.getPluginManager().getPlugin("floodgate");
Path floodgateDataPath = floodgate.isPresent() ? Paths.get("plugins/floodgate/") : null;
floodgateKeyPath = FloodgateKeyLoader.getKeyPath(this, floodgateDataPath, dataFolder.toPath(), plugin.getGeyserLogger());

View file

@ -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();
}
}

View file

@ -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));
}
}

View file

@ -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/")
}
}
}

View file

@ -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();
}
}
}

View file

@ -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";
}
}
}

View file

@ -0,0 +1 @@
org.geysermc.geyser.platform.velocity.GeyserVelocityPlatform

View file

@ -0,0 +1 @@
{"id": "${id}", "name": "${name}", "version": "${version}", "description": "${description}", "url": "${url}", "authors": ["${author}"], "main": "org.geysermc.geyser.platform.velocity.IsolatedVelocityPlugin"}