From bcfd52d76bbb2d2832c75ed36bd226424d8a22c3 Mon Sep 17 00:00:00 2001 From: Antti Koponen Date: Wed, 13 Oct 2021 17:44:34 +0300 Subject: [PATCH] Slimjar 1.3.0/1.2.6 & custom Injectables for Fabric and Velocity (#2126) * Update slimjar to 1.3.0/1.2.6 * Add custom Injectable impl for Fabric module * Add custom Injectable impl for Velocity --- Plan/build.gradle | 4 +- .../plan/FabricInjectable.java | 49 ++++++++++++++++++ .../net/playeranalytics/plan/PlanFabric.java | 2 +- Plan/gradle.properties | 1 - .../com/djrapitops/plan/PlanVelocity.java | 2 +- .../djrapitops/plan/VelocityInjectable.java | 50 +++++++++++++++++++ 6 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 Plan/fabric/src/main/java/net/playeranalytics/plan/FabricInjectable.java create mode 100644 Plan/velocity/src/main/java/com/djrapitops/plan/VelocityInjectable.java diff --git a/Plan/build.gradle b/Plan/build.gradle index 476c7606d..06de96a70 100644 --- a/Plan/build.gradle +++ b/Plan/build.gradle @@ -8,7 +8,7 @@ buildscript { plugins { id "com.github.johnrengelman.shadow" version "7.1.0" apply false - id "io.github.slimjar" version "1.2.2" apply false + id "io.github.slimjar" version "1.3.0" apply false id "java" id "jacoco" id "checkstyle" @@ -100,11 +100,11 @@ subprojects { maven { url = "https://repo.md-5.net/content/repositories/snapshots/" } // RedisBungee maven { url = "https://repo.velocitypowered.com/snapshots/" } // Velocity maven { url = "https://repo.playeranalytics.net/releases" } // Plan - maven { url = " https://repo.vshnv.tech/"} // slimjar } dependencies { // Dependency Injection used across the project + implementation "io.github.slimjar:slimjar:1.2.6" // Runtime dependency injection implementation "com.google.dagger:dagger:$daggerVersion" annotationProcessor "com.google.dagger:dagger-compiler:$daggerCompilerVersion" testAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerCompilerVersion" diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/FabricInjectable.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/FabricInjectable.java new file mode 100644 index 000000000..2eca24a7a --- /dev/null +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/FabricInjectable.java @@ -0,0 +1,49 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package net.playeranalytics.plan; + +import io.github.slimjar.injector.loader.Injectable; +import net.fabricmc.loader.launch.common.FabricLauncher; +import net.fabricmc.loader.launch.common.FabricLauncherBase; +import net.playeranalytics.plugin.server.FabricPluginLogger; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Paths; + +/** + * Custom {@link Injectable} implementation for Fabric. + * Appends dependencies to the classpath via Fabric's own launcher. + */ +public class FabricInjectable implements Injectable { + + private final FabricLauncher launcher; + private final FabricPluginLogger pluginLogger; + + public FabricInjectable(FabricPluginLogger pluginLogger) { + this.pluginLogger = pluginLogger; + this.launcher = FabricLauncherBase.getLauncher(); + } + + @Override + public void inject(final URL url) throws IOException, InvocationTargetException, IllegalAccessException, URISyntaxException { + pluginLogger.info("Proposed " + Paths.get(url.toURI()).getFileName().toString() + " to classpath"); + launcher.propose(url); + } +} diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/PlanFabric.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/PlanFabric.java index b889535d3..1da6a1fde 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/PlanFabric.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/PlanFabric.java @@ -168,7 +168,7 @@ public class PlanFabric implements PlanPlugin, DedicatedServerModInitializer { pluginLogger.info("Loading dependencies, this might take a while..."); try { - ApplicationBuilder.appending("Plan") + ApplicationBuilder.injecting("Plan", new FabricInjectable(pluginLogger)) .logger((message, args) -> pluginLogger.info(message, args)) // Use paper repository for downloading slimjar dependencies .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/")))) diff --git a/Plan/gradle.properties b/Plan/gradle.properties index 1f20ae052..e9157af4d 100644 --- a/Plan/gradle.properties +++ b/Plan/gradle.properties @@ -1,2 +1 @@ org.gradle.jvmargs=-Xmx1024m -slimjar.version=1.2.5 diff --git a/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java b/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java index c837e4c03..78eeccab6 100644 --- a/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java +++ b/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java @@ -101,7 +101,7 @@ public class PlanVelocity implements PlanPlugin { logger.info("Loading dependencies, this might take a while..."); try { - ApplicationBuilder.appending("Plan") + ApplicationBuilder.injecting("Plan", new VelocityInjectable(this, proxy, logger)) .logger((message, args) -> slf4jLogger.info(fixMsgParams(message), args)) // Use paper repository for downloading slimjar dependencies .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/")))) diff --git a/Plan/velocity/src/main/java/com/djrapitops/plan/VelocityInjectable.java b/Plan/velocity/src/main/java/com/djrapitops/plan/VelocityInjectable.java new file mode 100644 index 000000000..b74cccec9 --- /dev/null +++ b/Plan/velocity/src/main/java/com/djrapitops/plan/VelocityInjectable.java @@ -0,0 +1,50 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package com.djrapitops.plan; + +import com.velocitypowered.api.proxy.ProxyServer; +import io.github.slimjar.injector.loader.Injectable; +import net.playeranalytics.plugin.server.PluginLogger; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Paths; + +/** + * Custom {@link Injectable} implementation for Velocity. + * Appends dependencies to the classpath via Velocity's internal methods. + */ +public class VelocityInjectable implements Injectable { + + private final PlanPlugin plugin; + private final ProxyServer proxyServer; + private final PluginLogger logger; + + public VelocityInjectable(PlanPlugin plugin, ProxyServer proxyServer, PluginLogger logger) { + this.plugin = plugin; + this.proxyServer = proxyServer; + this.logger = logger; + } + + @Override + public void inject(URL url) throws IOException, InvocationTargetException, IllegalAccessException, URISyntaxException { + logger.info("Proposed " + Paths.get(url.toURI()).getFileName().toString() + " to classpath"); + proxyServer.getPluginManager().addToClasspath(plugin, Paths.get(url.toURI())); + } +}