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
This commit is contained in:
Antti Koponen 2021-10-13 17:44:34 +03:00 committed by GitHub
parent 7d8b797b42
commit bcfd52d76b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 103 additions and 5 deletions

View File

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

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

View File

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

View File

@ -1,2 +1 @@
org.gradle.jvmargs=-Xmx1024m
slimjar.version=1.2.5

View File

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

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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()));
}
}