Running with Redirects

This commit is contained in:
skippyall
2026-05-16 22:06:40 +02:00
parent f01f8ba570
commit 8423d9c7cd
37 changed files with 1586 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
plugins {
id 'java'
id 'eclipse'
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.8'
id("xyz.jpenilla.run-velocity") version "2.3.1"
id 'com.gradleup.shadow' version '8.3.5'
}
configurations {
shadowBundle {
canBeResolved = true
canBeConsumed = false
}
}
repositories {
mavenCentral()
maven {
name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
}
dependencies {
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
annotationProcessor("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
implementation project(":common")
shadowBundle(project(":common"))
}
shadowJar {
configurations = [project.configurations.shadowBundle]
archiveClassifier = 'dev-shadow'
relocate("de.themoep.minedown.adventure", "io.github.skippyall.minedown")
relocate("com.electronwill.nightconfig", "io.github.skippyall.nightconfig")
}
tasks {
runVelocity {
// Configure the Velocity version for our task.
// This is the only required configuration besides applying the plugin.
// Your plugin's jar (or shadowJar if present) will be used automatically.
velocityVersion("3.4.0-SNAPSHOT")
}
}
def targetJavaVersion = 21
java {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release.set(targetJavaVersion)
}
/*
def templateSource = file('src/main/templates')
def templateDest = layout.buildDirectory.dir('generated/sources/templates')
def generateTemplates = tasks.register('generateTemplates', Copy) { task ->
def props = [
'version': project.version
]
task.inputs.properties props
task.from templateSource
task.into templateDest
task.expand props
}
sourceSets.main.java.srcDir(generateTemplates.map { it.outputs })
project.idea.project.settings.taskTriggers.afterSync generateTemplates
project.eclipse.synchronizationTasks(generateTemplates)*/
@@ -0,0 +1,51 @@
package io.github.skippyall.ruler.velocity;
import com.google.inject.Inject;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import io.github.skippyall.ruler.Ruler;
import io.github.skippyall.ruler.command.Commands;
import io.github.skippyall.ruler.velocity.config.Registration;
import org.slf4j.Logger;
import java.nio.file.Path;
@Plugin(
id = "ruler-velocity",
name = "Ruler",
version = "1.0"
)
public class RulerVelocity {
public static Logger logger;
public static ProxyServer server;
public static Path configDirectory;
public static Commands<CommandSource> commands;
public static RulerVelocity instance;
@Inject
public RulerVelocity(ProxyServer server, Logger logger, @DataDirectory Path dir) {
RulerVelocity.server = server;
RulerVelocity.logger = logger;
RulerVelocity.configDirectory = dir;
instance = this;
}
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
Ruler.init(new VelocityPlatform());
commands = new Commands<>(new VelocityCommandHelper());
CommandManager manager = server.getCommandManager();
for(LiteralArgumentBuilder<CommandSource> builder : commands.getCommands()) {
BrigadierCommand command = new BrigadierCommand(builder);
manager.register(manager.metaBuilder(command).plugin(this).build(), command);
}
Registration.register();
}
}
@@ -0,0 +1,12 @@
package io.github.skippyall.ruler.velocity;
import com.velocitypowered.api.command.CommandSource;
import io.github.skippyall.ruler.command.CommandHelper;
import net.kyori.adventure.audience.Audience;
public class VelocityCommandHelper implements CommandHelper<CommandSource> {
@Override
public Audience toAudience(CommandSource source) {
return source;
}
}
@@ -0,0 +1,27 @@
package io.github.skippyall.ruler.velocity;
import io.github.skippyall.ruler.Platform;
import org.slf4j.Logger;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
public class VelocityPlatform implements Platform {
@Override
public Path getConfigDirectory() {
return RulerVelocity.configDirectory;
}
@Override
public Logger getLogger() {
return RulerVelocity.logger;
}
@Override
public <T> CompletableFuture<T> runAsync(Supplier<T> supplier) {
CompletableFuture<T> future = new CompletableFuture<>();
RulerVelocity.server.getScheduler().buildTask(RulerVelocity.instance, () -> future.complete(supplier.get())).schedule();
return future;
}
}
@@ -0,0 +1,12 @@
package io.github.skippyall.ruler.velocity.config;
import io.github.skippyall.ruler.config.condition.Conditions;
import net.kyori.adventure.key.Key;
public class Registration {
public static void register() {
Conditions.register(Key.key("ruler", "server"), object ->
new ServerCondition(object.get("server").getAsString())
);
}
}
@@ -0,0 +1,41 @@
package io.github.skippyall.ruler.velocity.config;
import com.google.gson.JsonObject;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import io.github.skippyall.ruler.config.condition.Condition;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import java.util.Optional;
public class ServerCondition implements Condition {
private String server;
public ServerCondition(String server) {
this.server = server;
}
@Override
public boolean test(Audience audience) {
if(audience instanceof Player player) {
Optional<ServerConnection> server = player.getCurrentServer();
if(server.isPresent()) {
return server.get().getServer().getServerInfo().getName().equals(this.server);
}
}
return false;
}
@Override
public Key getType() {
return Key.key("ruler", "server");
}
@Override
public JsonObject serialize() {
JsonObject object = new JsonObject();
object.addProperty("server", server);
return object;
}
}