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,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

@ -1,43 +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;
import org.geysermc.geyser.GeyserMain;
public class GeyserVelocityMain extends GeyserMain {
public static void main(String[] args) {
new GeyserVelocityMain().displayMessage();
}
public String getPluginType() {
return "Velocity";
}
public String getPluginFolder() {
return "plugins";
}
}

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