mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-09 01:47:39 +01:00
parent
e4999ba072
commit
efd3b75a29
@ -8,7 +8,6 @@ buildscript {
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "com.github.johnrengelman.shadow" version "7.1.0" apply false
|
id "com.github.johnrengelman.shadow" version "7.1.0" apply false
|
||||||
// id "io.github.slimjar" version "1.3.0" apply false
|
|
||||||
id "java"
|
id "java"
|
||||||
id "jacoco"
|
id "jacoco"
|
||||||
id "checkstyle"
|
id "checkstyle"
|
||||||
@ -49,7 +48,6 @@ logger.lifecycle("Building artifact for version $fullVersion")
|
|||||||
subprojects {
|
subprojects {
|
||||||
// Build plugins
|
// Build plugins
|
||||||
apply plugin: "com.github.johnrengelman.shadow"
|
apply plugin: "com.github.johnrengelman.shadow"
|
||||||
// apply plugin: "io.github.slimjar"
|
|
||||||
apply plugin: "java"
|
apply plugin: "java"
|
||||||
apply plugin: "maven-publish"
|
apply plugin: "maven-publish"
|
||||||
|
|
||||||
@ -104,7 +102,6 @@ subprojects {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Dependency Injection used across the project
|
// Dependency Injection used across the project
|
||||||
// implementation "io.github.slimjar:slimjar:1.2.6" // Runtime dependency injection
|
|
||||||
implementation "com.google.dagger:dagger:$daggerVersion"
|
implementation "com.google.dagger:dagger:$daggerVersion"
|
||||||
annotationProcessor "com.google.dagger:dagger-compiler:$daggerCompilerVersion"
|
annotationProcessor "com.google.dagger:dagger-compiler:$daggerCompilerVersion"
|
||||||
testAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerCompilerVersion"
|
testAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerCompilerVersion"
|
||||||
|
@ -61,22 +61,6 @@ public class Plan extends JavaPlugin implements PlanPlugin {
|
|||||||
abstractionLayer = new BukkitPlatformLayer(this);
|
abstractionLayer = new BukkitPlatformLayer(this);
|
||||||
pluginLogger = abstractionLayer.getPluginLogger();
|
pluginLogger = abstractionLayer.getPluginLogger();
|
||||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||||
|
|
||||||
// getLogger().log(Level.INFO, "Loading dependencies, this might take a while...");
|
|
||||||
// try {
|
|
||||||
// ApplicationBuilder.appending("Plan")
|
|
||||||
// .logger((message, args) -> getLogger().log(Level.INFO, message, args))
|
|
||||||
// // Use paper repository for downloading slimjar dependencies
|
|
||||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
|
||||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
|
||||||
// .build();
|
|
||||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
|
||||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
|
||||||
// getLogger().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
|
||||||
// getLogger().log(Level.SEVERE, "Plan failed to load its dependencies correctly!");
|
|
||||||
// getLogger().log(Level.SEVERE, "This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
|
||||||
// onDisable();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -230,4 +214,4 @@ public class Plan extends JavaPlugin implements PlanPlugin {
|
|||||||
public PlanSystem getSystem() {
|
public PlanSystem getSystem() {
|
||||||
return system;
|
return system;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,22 +52,6 @@ public class PlanBungee extends Plugin implements PlanPlugin {
|
|||||||
abstractionLayer = new BungeePlatformLayer(this);
|
abstractionLayer = new BungeePlatformLayer(this);
|
||||||
logger = abstractionLayer.getPluginLogger();
|
logger = abstractionLayer.getPluginLogger();
|
||||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||||
|
|
||||||
// getLogger().log(Level.INFO, "Loading dependencies, this might take a while...");
|
|
||||||
// try {
|
|
||||||
// ApplicationBuilder.appending("Plan")
|
|
||||||
// .logger((message, args) -> getLogger().log(Level.INFO, message, args))
|
|
||||||
// // Use paper repository for downloading slimjar dependencies
|
|
||||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
|
||||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
|
||||||
// .build();
|
|
||||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
|
||||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
|
||||||
// getLogger().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
|
||||||
// getLogger().log(Level.SEVERE, "Plan failed to load its dependencies correctly!");
|
|
||||||
// getLogger().log(Level.SEVERE, "This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
|
||||||
// onDisable();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,3 +1,32 @@
|
|||||||
|
import dev.vankka.dependencydownload.task.GenerateDependencyDownloadResourceTask
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id "dev.vankka.dependencydownload.plugin" version "1.1.4"
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
mysqlDriver
|
||||||
|
sqliteDriver
|
||||||
|
testImplementation.extendsFrom mysqlDriver, sqliteDriver
|
||||||
|
compileOnly.extendsFrom mysqlDriver, sqliteDriver
|
||||||
|
}
|
||||||
|
|
||||||
|
task generateResourceForMySQLDriver(type: GenerateDependencyDownloadResourceTask) {
|
||||||
|
var conf = configurations.mysqlDriver
|
||||||
|
configuration = conf
|
||||||
|
file = "assets/plan/dependencies/" + conf.name + ".txt"
|
||||||
|
// Not necessary to include in the resource
|
||||||
|
includeShadowJarRelocations = false
|
||||||
|
}
|
||||||
|
|
||||||
|
task generateResourceForSQLiteDriver(type: GenerateDependencyDownloadResourceTask) {
|
||||||
|
var conf = configurations.sqliteDriver
|
||||||
|
configuration = conf
|
||||||
|
file = "assets/plan/dependencies/" + conf.name + ".txt"
|
||||||
|
// Not necessary to include in the resource
|
||||||
|
includeShadowJarRelocations = false
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "net.playeranalytics:platform-abstraction-layer-api:$palVersion"
|
implementation "net.playeranalytics:platform-abstraction-layer-api:$palVersion"
|
||||||
implementation project(":api")
|
implementation project(":api")
|
||||||
@ -6,14 +35,18 @@ dependencies {
|
|||||||
implementation "org.apache.commons:commons-text:$commonsTextVersion"
|
implementation "org.apache.commons:commons-text:$commonsTextVersion"
|
||||||
implementation "org.apache.commons:commons-compress:$commonsCompressVersion"
|
implementation "org.apache.commons:commons-compress:$commonsCompressVersion"
|
||||||
implementation "com.github.ben-manes.caffeine:caffeine:$caffeineVersion"
|
implementation "com.github.ben-manes.caffeine:caffeine:$caffeineVersion"
|
||||||
implementation "mysql:mysql-connector-java:$mysqlVersion"
|
|
||||||
implementation "org.xerial:sqlite-jdbc:$sqliteVersion"
|
|
||||||
implementation "com.zaxxer:HikariCP:$hikariVersion"
|
implementation "com.zaxxer:HikariCP:$hikariVersion"
|
||||||
implementation "org.slf4j:slf4j-nop:$slf4jVersion"
|
implementation "org.slf4j:slf4j-nop:$slf4jVersion"
|
||||||
implementation "org.slf4j:slf4j-api:$slf4jVersion"
|
implementation "org.slf4j:slf4j-api:$slf4jVersion"
|
||||||
implementation "com.maxmind.geoip2:geoip2:$geoIpVersion"
|
implementation "com.maxmind.geoip2:geoip2:$geoIpVersion"
|
||||||
implementation "com.google.code.gson:gson:$gsonVersion"
|
implementation "com.google.code.gson:gson:$gsonVersion"
|
||||||
// implementation slimjar("1.2.5")
|
|
||||||
|
implementation("dev.vankka.dependencydownload:runtime:1.1.4") {
|
||||||
|
// Effectively disables relocating
|
||||||
|
exclude module: "jar-relocator"
|
||||||
|
}
|
||||||
|
mysqlDriver "mysql:mysql-connector-java:$mysqlVersion"
|
||||||
|
sqliteDriver "org.xerial:sqlite-jdbc:$sqliteVersion"
|
||||||
|
|
||||||
testImplementation project(":api")
|
testImplementation project(":api")
|
||||||
testImplementation "com.google.code.gson:gson:$gsonVersion"
|
testImplementation "com.google.code.gson:gson:$gsonVersion"
|
||||||
@ -55,7 +88,7 @@ task determineWebAssetModifications {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
dependsOn determineWebAssetModifications
|
dependsOn determineWebAssetModifications, generateResourceForMySQLDriver, generateResourceForSQLiteDriver
|
||||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||||
dependsOn updateVersion
|
dependsOn updateVersion
|
||||||
from 'build/sources/resources'
|
from 'build/sources/resources'
|
||||||
@ -96,4 +129,4 @@ shadowJar {
|
|||||||
exclude "org/jayway/**/*"
|
exclude "org/jayway/**/*"
|
||||||
exclude "google/protobuf/**/*"
|
exclude "google/protobuf/**/*"
|
||||||
exclude "jargs/gnu/**/*"
|
exclude "jargs/gnu/**/*"
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import com.djrapitops.plan.settings.config.PlanConfig;
|
|||||||
import com.djrapitops.plan.settings.config.paths.DatabaseSettings;
|
import com.djrapitops.plan.settings.config.paths.DatabaseSettings;
|
||||||
import com.djrapitops.plan.settings.locale.Locale;
|
import com.djrapitops.plan.settings.locale.Locale;
|
||||||
import com.djrapitops.plan.settings.locale.lang.PluginLang;
|
import com.djrapitops.plan.settings.locale.lang.PluginLang;
|
||||||
|
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
@ -34,11 +35,13 @@ import net.playeranalytics.plugin.server.PluginLogger;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.Driver;
|
import java.sql.Driver;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -56,12 +59,13 @@ public class MySQLDB extends SQLDB {
|
|||||||
public MySQLDB(
|
public MySQLDB(
|
||||||
Locale locale,
|
Locale locale,
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
|
PlanFiles files,
|
||||||
Lazy<ServerInfo> serverInfo,
|
Lazy<ServerInfo> serverInfo,
|
||||||
RunnableFactory runnableFactory,
|
RunnableFactory runnableFactory,
|
||||||
PluginLogger pluginLogger,
|
PluginLogger pluginLogger,
|
||||||
ErrorLogger errorLogger
|
ErrorLogger errorLogger
|
||||||
) {
|
) {
|
||||||
super(() -> serverInfo.get().getServerUUID(), locale, config, runnableFactory, pluginLogger, errorLogger);
|
super(() -> serverInfo.get().getServerUUID(), locale, config, files, runnableFactory, pluginLogger, errorLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized void increment() {
|
private static synchronized void increment() {
|
||||||
@ -73,11 +77,12 @@ public class MySQLDB extends SQLDB {
|
|||||||
return DBType.MYSQL;
|
return DBType.MYSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadMySQLDriver() {
|
@Override
|
||||||
|
protected List<String> getDependencyResource() {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
return files.getResourceFromJar("dependencies/mysqlDriver.txt").asLines();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (IOException e) {
|
||||||
errorLogger.critical(e, ErrorContext.builder().whatToDo("Install MySQL Driver to the server").build());
|
throw new RuntimeException("Failed to get MySQL dependency information", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,9 +91,18 @@ public class MySQLDB extends SQLDB {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setupDataSource() {
|
public void setupDataSource() {
|
||||||
try {
|
if (driverClassLoader == null) {
|
||||||
loadMySQLDriver();
|
logger.info("Downloading MySQL Driver, this may take a while...");
|
||||||
|
downloadDriver();
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread currentThread = Thread.currentThread();
|
||||||
|
ClassLoader previousClassLoader = currentThread.getContextClassLoader();
|
||||||
|
|
||||||
|
// Set the context class loader to the driver class loader for Hikari to use for finding the Driver
|
||||||
|
currentThread.setContextClassLoader(driverClassLoader);
|
||||||
|
|
||||||
|
try {
|
||||||
HikariConfig hikariConfig = new HikariConfig();
|
HikariConfig hikariConfig = new HikariConfig();
|
||||||
|
|
||||||
String host = config.get(DatabaseSettings.MYSQL_HOST);
|
String host = config.get(DatabaseSettings.MYSQL_HOST);
|
||||||
@ -129,6 +143,9 @@ public class MySQLDB extends SQLDB {
|
|||||||
} finally {
|
} finally {
|
||||||
unloadMySQLDriver();
|
unloadMySQLDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the context classloader back to what it was originally set to, now that the DataSource is created
|
||||||
|
currentThread.setContextClassLoader(previousClassLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unloadMySQLDriver() {
|
private void unloadMySQLDriver() {
|
||||||
|
@ -32,9 +32,14 @@ import com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransa
|
|||||||
import com.djrapitops.plan.storage.database.transactions.init.OperationCriticalTransaction;
|
import com.djrapitops.plan.storage.database.transactions.init.OperationCriticalTransaction;
|
||||||
import com.djrapitops.plan.storage.database.transactions.init.RemoveIncorrectTebexPackageDataPatch;
|
import com.djrapitops.plan.storage.database.transactions.init.RemoveIncorrectTebexPackageDataPatch;
|
||||||
import com.djrapitops.plan.storage.database.transactions.patches.*;
|
import com.djrapitops.plan.storage.database.transactions.patches.*;
|
||||||
|
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||||
import com.djrapitops.plan.utilities.java.ThrowableUtils;
|
import com.djrapitops.plan.utilities.java.ThrowableUtils;
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||||
|
import dev.vankka.dependencydownload.DependencyManager;
|
||||||
|
import dev.vankka.dependencydownload.classloader.IsolatedClassLoader;
|
||||||
|
import dev.vankka.dependencydownload.repository.Repository;
|
||||||
|
import dev.vankka.dependencydownload.repository.StandardRepository;
|
||||||
import net.playeranalytics.plugin.scheduling.PluginRunnable;
|
import net.playeranalytics.plugin.scheduling.PluginRunnable;
|
||||||
import net.playeranalytics.plugin.scheduling.RunnableFactory;
|
import net.playeranalytics.plugin.scheduling.RunnableFactory;
|
||||||
import net.playeranalytics.plugin.scheduling.TimeAmount;
|
import net.playeranalytics.plugin.scheduling.TimeAmount;
|
||||||
@ -43,10 +48,7 @@ import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
|||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@ -58,14 +60,22 @@ import java.util.function.Supplier;
|
|||||||
*/
|
*/
|
||||||
public abstract class SQLDB extends AbstractDatabase {
|
public abstract class SQLDB extends AbstractDatabase {
|
||||||
|
|
||||||
|
private static final List<Repository> DRIVER_REPOSITORIES = Arrays.asList(
|
||||||
|
new StandardRepository("https://papermc.io/repo/repository/maven-public/"),
|
||||||
|
new StandardRepository("https://repo1.maven.org/maven2/")
|
||||||
|
);
|
||||||
|
|
||||||
private final Supplier<ServerUUID> serverUUIDSupplier;
|
private final Supplier<ServerUUID> serverUUIDSupplier;
|
||||||
|
|
||||||
protected final Locale locale;
|
protected final Locale locale;
|
||||||
protected final PlanConfig config;
|
protected final PlanConfig config;
|
||||||
|
protected final PlanFiles files;
|
||||||
protected final RunnableFactory runnableFactory;
|
protected final RunnableFactory runnableFactory;
|
||||||
protected final PluginLogger logger;
|
protected final PluginLogger logger;
|
||||||
protected final ErrorLogger errorLogger;
|
protected final ErrorLogger errorLogger;
|
||||||
|
|
||||||
|
protected IsolatedClassLoader driverClassLoader;
|
||||||
|
|
||||||
private Supplier<ExecutorService> transactionExecutorServiceProvider;
|
private Supplier<ExecutorService> transactionExecutorServiceProvider;
|
||||||
private ExecutorService transactionExecutor;
|
private ExecutorService transactionExecutor;
|
||||||
|
|
||||||
@ -73,6 +83,7 @@ public abstract class SQLDB extends AbstractDatabase {
|
|||||||
Supplier<ServerUUID> serverUUIDSupplier,
|
Supplier<ServerUUID> serverUUIDSupplier,
|
||||||
Locale locale,
|
Locale locale,
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
|
PlanFiles files,
|
||||||
RunnableFactory runnableFactory,
|
RunnableFactory runnableFactory,
|
||||||
PluginLogger logger,
|
PluginLogger logger,
|
||||||
ErrorLogger errorLogger
|
ErrorLogger errorLogger
|
||||||
@ -80,6 +91,7 @@ public abstract class SQLDB extends AbstractDatabase {
|
|||||||
this.serverUUIDSupplier = serverUUIDSupplier;
|
this.serverUUIDSupplier = serverUUIDSupplier;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
this.files = files;
|
||||||
this.runnableFactory = runnableFactory;
|
this.runnableFactory = runnableFactory;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.errorLogger = errorLogger;
|
this.errorLogger = errorLogger;
|
||||||
@ -98,6 +110,18 @@ public abstract class SQLDB extends AbstractDatabase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract List<String> getDependencyResource();
|
||||||
|
|
||||||
|
public void downloadDriver() {
|
||||||
|
DependencyManager dependencyManager = new DependencyManager(files.getDataDirectory().resolve("libraries"));
|
||||||
|
dependencyManager.loadFromResource(getDependencyResource());
|
||||||
|
dependencyManager.download(null, DRIVER_REPOSITORIES);
|
||||||
|
|
||||||
|
IsolatedClassLoader classLoader = new IsolatedClassLoader();
|
||||||
|
dependencyManager.load(null, classLoader);
|
||||||
|
this.driverClassLoader = classLoader;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
List<Runnable> unfinishedTransactions = closeTransactionExecutor(transactionExecutor);
|
List<Runnable> unfinishedTransactions = closeTransactionExecutor(transactionExecutor);
|
||||||
|
@ -25,7 +25,6 @@ import com.djrapitops.plan.storage.file.PlanFiles;
|
|||||||
import com.djrapitops.plan.storage.upkeep.DBKeepAliveTask;
|
import com.djrapitops.plan.storage.upkeep.DBKeepAliveTask;
|
||||||
import com.djrapitops.plan.utilities.MiscUtils;
|
import com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import com.djrapitops.plan.utilities.SemaphoreAccessCounter;
|
import com.djrapitops.plan.utilities.SemaphoreAccessCounter;
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||||
import dagger.Lazy;
|
import dagger.Lazy;
|
||||||
import net.playeranalytics.plugin.scheduling.RunnableFactory;
|
import net.playeranalytics.plugin.scheduling.RunnableFactory;
|
||||||
@ -35,10 +34,14 @@ import net.playeranalytics.plugin.server.PluginLogger;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author AuroraLS3
|
* @author AuroraLS3
|
||||||
@ -57,20 +60,32 @@ public class SQLiteDB extends SQLDB {
|
|||||||
*/
|
*/
|
||||||
private final SemaphoreAccessCounter connectionLock = new SemaphoreAccessCounter();
|
private final SemaphoreAccessCounter connectionLock = new SemaphoreAccessCounter();
|
||||||
|
|
||||||
|
private Constructor<?> connectionConstructor;
|
||||||
|
|
||||||
private SQLiteDB(
|
private SQLiteDB(
|
||||||
File databaseFile,
|
File databaseFile,
|
||||||
Locale locale,
|
Locale locale,
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
|
PlanFiles files,
|
||||||
Lazy<ServerInfo> serverInfo,
|
Lazy<ServerInfo> serverInfo,
|
||||||
RunnableFactory runnableFactory,
|
RunnableFactory runnableFactory,
|
||||||
PluginLogger logger,
|
PluginLogger logger,
|
||||||
ErrorLogger errorLogger
|
ErrorLogger errorLogger
|
||||||
) {
|
) {
|
||||||
super(() -> serverInfo.get().getServerUUID(), locale, config, runnableFactory, logger, errorLogger);
|
super(() -> serverInfo.get().getServerUUID(), locale, config, files, runnableFactory, logger, errorLogger);
|
||||||
dbName = databaseFile.getName();
|
dbName = databaseFile.getName();
|
||||||
this.databaseFile = databaseFile;
|
this.databaseFile = databaseFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<String> getDependencyResource() {
|
||||||
|
try {
|
||||||
|
return files.getResourceFromJar("dependencies/sqliteDriver.txt").asLines();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to get SQLite dependency information", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setupDataSource() {
|
public void setupDataSource() {
|
||||||
try {
|
try {
|
||||||
@ -84,13 +99,10 @@ public class SQLiteDB extends SQLDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Connection getNewConnection(File dbFile) throws SQLException {
|
public Connection getNewConnection(File dbFile) throws SQLException {
|
||||||
try {
|
if (driverClassLoader == null) {
|
||||||
Class.forName("org.sqlite.JDBC");
|
logger.info("Downloading SQLite Driver, this may take a while...");
|
||||||
} catch (ClassNotFoundException e) {
|
downloadDriver();
|
||||||
errorLogger.critical(e, ErrorContext.builder().whatToDo("Install SQLite Driver to the server").build());
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String dbFilePath = dbFile.getAbsolutePath();
|
String dbFilePath = dbFile.getAbsolutePath();
|
||||||
|
|
||||||
Connection newConnection = getConnectionFor(dbFilePath);
|
Connection newConnection = getConnectionFor(dbFilePath);
|
||||||
@ -99,11 +111,42 @@ public class SQLiteDB extends SQLDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnectionFor(String dbFilePath) throws SQLException {
|
private Connection getConnectionFor(String dbFilePath) throws SQLException {
|
||||||
|
ensureConstructorIsAvailable();
|
||||||
|
return tryToConnect(dbFilePath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureConstructorIsAvailable() {
|
||||||
|
if (connectionConstructor != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return DriverManager.getConnection("jdbc:sqlite:" + dbFilePath + "?journal_mode=WAL");
|
Class<?> connectionClass = driverClassLoader.loadClass("org.sqlite.jdbc4.JDBC4Connection");
|
||||||
} catch (SQLException ignored) {
|
connectionConstructor = connectionClass.getConstructor(String.class, String.class, Properties.class);
|
||||||
|
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||||
|
throw new DBInitException("Failed to initialize SQLite Driver", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Connection tryToConnect(String dbFilePath, boolean withWAL) throws SQLException {
|
||||||
|
try {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
if (withWAL) properties.put("journal_mode", "WAL");
|
||||||
|
|
||||||
|
return (Connection) connectionConstructor.newInstance("jdbc:sqlite:" + dbFilePath, dbFilePath, properties);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
if (!withWAL && cause instanceof SQLException) {
|
||||||
|
throw (SQLException) cause;
|
||||||
|
} else if (!(cause instanceof SQLException)) {
|
||||||
|
throw new DBInitException("Failed to initialize SQLite Driver", cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the method again with withWAL set to false, if it fails again, an exception will be thrown above
|
||||||
logger.info(locale.getString(PluginLang.DB_NOTIFY_SQLITE_WAL));
|
logger.info(locale.getString(PluginLang.DB_NOTIFY_SQLITE_WAL));
|
||||||
return DriverManager.getConnection("jdbc:sqlite:" + dbFilePath);
|
return tryToConnect(dbFilePath, false);
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
throw new DBInitException("Failed to initialize SQLite Driver", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +259,7 @@ public class SQLiteDB extends SQLDB {
|
|||||||
|
|
||||||
public SQLiteDB usingFile(File databaseFile) {
|
public SQLiteDB usingFile(File databaseFile) {
|
||||||
return new SQLiteDB(databaseFile,
|
return new SQLiteDB(databaseFile,
|
||||||
locale, config, serverInfo,
|
locale, config, files, serverInfo,
|
||||||
runnableFactory, logger, errorLogger1
|
runnableFactory, logger, errorLogger1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ public class OldDependencyCacheDeletionTask extends TaskSystem.Task {
|
|||||||
|
|
||||||
private final File oldDependencyCache;
|
private final File oldDependencyCache;
|
||||||
private final File dependencyCache;
|
private final File dependencyCache;
|
||||||
|
private final File librariesCache;
|
||||||
|
|
||||||
private final ErrorLogger errorLogger;
|
private final ErrorLogger errorLogger;
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ public class OldDependencyCacheDeletionTask extends TaskSystem.Task {
|
|||||||
) {
|
) {
|
||||||
oldDependencyCache = files.getDataDirectory().resolve("dependency_cache").toFile();
|
oldDependencyCache = files.getDataDirectory().resolve("dependency_cache").toFile();
|
||||||
dependencyCache = files.getDataDirectory().resolve("dep_cache").toFile();
|
dependencyCache = files.getDataDirectory().resolve("dep_cache").toFile();
|
||||||
|
librariesCache = files.getDataDirectory().resolve("libraries").toFile();
|
||||||
this.errorLogger = errorLogger;
|
this.errorLogger = errorLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +60,17 @@ public class OldDependencyCacheDeletionTask extends TaskSystem.Task {
|
|||||||
public void run() {
|
public void run() {
|
||||||
tryToDeleteDirectory(oldDependencyCache);
|
tryToDeleteDirectory(oldDependencyCache);
|
||||||
tryToDeleteDirectory(dependencyCache);
|
tryToDeleteDirectory(dependencyCache);
|
||||||
|
|
||||||
|
if (librariesCache.exists()) {
|
||||||
|
// Only delete sub folders as jar files in the directory are still needed
|
||||||
|
File[] files = librariesCache.listFiles();
|
||||||
|
if (files == null) return;
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
tryToDeleteDirectory(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryToDeleteDirectory(File directory) {
|
private void tryToDeleteDirectory(File directory) {
|
||||||
|
@ -69,8 +69,8 @@
|
|||||||
|
|
||||||
<!-- Metrics -->
|
<!-- Metrics -->
|
||||||
<module name="ClassFanOutComplexity">
|
<module name="ClassFanOutComplexity">
|
||||||
<!-- This value is high. Notable: SQLDB: 61 -->
|
<!-- This value is high. Notable: SQLDB: 66 -->
|
||||||
<property name="max" value="65"/>
|
<property name="max" value="70"/>
|
||||||
</module>
|
</module>
|
||||||
<module name="CyclomaticComplexity">
|
<module name="CyclomaticComplexity">
|
||||||
<!-- This value is high. Notable: ThemeConfig: 16 -->
|
<!-- This value is high. Notable: ThemeConfig: 16 -->
|
||||||
|
@ -49,11 +49,6 @@ processResources {
|
|||||||
from 'build/sources/resources'
|
from 'build/sources/resources'
|
||||||
}
|
}
|
||||||
|
|
||||||
//slimJar {
|
|
||||||
// relocate 'com.mysql', 'plan.com.mysql'
|
|
||||||
// relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
|
||||||
//}
|
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
configurations = [project.configurations.shadow]
|
configurations = [project.configurations.shadow]
|
||||||
exclude('net.fabricmc:*')
|
exclude('net.fabricmc:*')
|
||||||
@ -63,13 +58,13 @@ shadowJar {
|
|||||||
exclude 'org/apache/logging/**'
|
exclude 'org/apache/logging/**'
|
||||||
}
|
}
|
||||||
relocate 'dagger', 'plan.dagger'
|
relocate 'dagger', 'plan.dagger'
|
||||||
// Don't relocate SQLite since the org.sqlite.NativeDB class calls are not relocated properly
|
// Don't relocate MySQL or SQLite since they are loaded with a isolated class loader
|
||||||
// relocate 'org.sqlite', 'plan.org.sqlite'
|
// relocate 'org.sqlite', 'plan.org.sqlite'
|
||||||
|
// relocate 'com.mysql', 'plan.com.mysql'
|
||||||
|
// relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
||||||
relocate 'javax.inject', 'plan.javax.inject'
|
relocate 'javax.inject', 'plan.javax.inject'
|
||||||
relocate 'com.github.benmanes', 'plan.com.github.benmanes'
|
relocate 'com.github.benmanes', 'plan.com.github.benmanes'
|
||||||
|
relocate 'dev.vankka.dependencydownload', 'plan.dev.vankka.dependencydownload'
|
||||||
relocate 'com.mysql', 'plan.com.mysql'
|
|
||||||
relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
remapJar {
|
remapJar {
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 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 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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -158,22 +158,6 @@ public class PlanFabric implements PlanPlugin, DedicatedServerModInitializer {
|
|||||||
pluginLogger = (FabricPluginLogger) abstractionLayer.getPluginLogger();
|
pluginLogger = (FabricPluginLogger) abstractionLayer.getPluginLogger();
|
||||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||||
|
|
||||||
// pluginLogger.info("Loading dependencies, this might take a while...");
|
|
||||||
// try {
|
|
||||||
// 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/"))))
|
|
||||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
|
||||||
// .build();
|
|
||||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
|
||||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
|
||||||
// pluginLogger.error(this.getClass().getSimpleName() + "-v" + version, e);
|
|
||||||
// pluginLogger.error("Plan failed to load its dependencies correctly!");
|
|
||||||
// pluginLogger.error("This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
|
||||||
// onDisable();
|
|
||||||
// }
|
|
||||||
|
|
||||||
ServerLifecycleEvents.SERVER_STARTING.register(server -> {
|
ServerLifecycleEvents.SERVER_STARTING.register(server -> {
|
||||||
this.server = (MinecraftDedicatedServer) server;
|
this.server = (MinecraftDedicatedServer) server;
|
||||||
onEnable();
|
onEnable();
|
||||||
|
@ -66,22 +66,6 @@ public class PlanNukkit extends PluginBase implements PlanPlugin {
|
|||||||
abstractionLayer = new NukkitPlatformLayer(this);
|
abstractionLayer = new NukkitPlatformLayer(this);
|
||||||
logger = abstractionLayer.getPluginLogger();
|
logger = abstractionLayer.getPluginLogger();
|
||||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||||
|
|
||||||
// getLogger().info( "Loading dependencies, this might take a while...");
|
|
||||||
// try {
|
|
||||||
// ApplicationBuilder.appending("Plan")
|
|
||||||
// .logger((message, args) -> Logger.getGlobal().log(Level.INFO, message, args))
|
|
||||||
// // Use paper repository for downloading slimjar dependencies
|
|
||||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
|
||||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
|
||||||
// .build();
|
|
||||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
|
||||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
|
||||||
// Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
|
||||||
// getLogger().error("Plan failed to load its dependencies correctly!");
|
|
||||||
// getLogger().error( "This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
|
||||||
// onDisable();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -210,4 +194,4 @@ public class PlanNukkit extends PluginBase implements PlanPlugin {
|
|||||||
}).runTask();
|
}).runTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,22 +13,18 @@ dependencies {
|
|||||||
testImplementation project(path: ":velocity", configuration: 'testArtifacts')
|
testImplementation project(path: ":velocity", configuration: 'testArtifacts')
|
||||||
}
|
}
|
||||||
|
|
||||||
//slimJar {
|
|
||||||
// relocate 'com.mysql', 'plan.com.mysql'
|
|
||||||
// relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
|
||||||
//}
|
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
relocate('org.apache', 'plan.org.apache') {
|
relocate('org.apache', 'plan.org.apache') {
|
||||||
exclude 'org/apache/logging/**'
|
exclude 'org/apache/logging/**'
|
||||||
}
|
}
|
||||||
relocate 'dagger', 'plan.dagger'
|
relocate 'dagger', 'plan.dagger'
|
||||||
// Don't relocate SQLite since the org.sqlite.NativeDB class calls are not relocated properly
|
// Don't relocate MySQL or SQLite since they are loaded with a isolated class loader
|
||||||
// relocate 'org.sqlite', 'plan.org.sqlite'
|
// relocate 'org.sqlite', 'plan.org.sqlite'
|
||||||
|
// relocate 'com.mysql', 'plan.com.mysql'
|
||||||
|
// relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
||||||
relocate 'javax.inject', 'plan.javax.inject'
|
relocate 'javax.inject', 'plan.javax.inject'
|
||||||
relocate 'com.github.benmanes', 'plan.com.github.benmanes'
|
relocate 'com.github.benmanes', 'plan.com.github.benmanes'
|
||||||
relocate 'com.mysql', 'plan.com.mysql'
|
relocate 'dev.vankka.dependencydownload', 'plan.dev.vankka.dependencydownload'
|
||||||
relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
|
||||||
|
|
||||||
destinationDirectory.set(file("$rootDir/builds/"))
|
destinationDirectory.set(file("$rootDir/builds/"))
|
||||||
archiveBaseName.set('Plan')
|
archiveBaseName.set('Plan')
|
||||||
@ -49,4 +45,4 @@ publishing {
|
|||||||
artifact shadowJar
|
artifact shadowJar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,22 +115,6 @@ public class PlanSponge implements PlanPlugin {
|
|||||||
abstractionLayer = new SpongePlatformLayer(this, dataFolder, slf4jLogger);
|
abstractionLayer = new SpongePlatformLayer(this, dataFolder, slf4jLogger);
|
||||||
logger = abstractionLayer.getPluginLogger();
|
logger = abstractionLayer.getPluginLogger();
|
||||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||||
|
|
||||||
// logger.info("Loading dependencies, this might take a while...");
|
|
||||||
// try {
|
|
||||||
// ApplicationBuilder.appending("Plan")
|
|
||||||
// .logger((message, args) -> java.util.logging.Logger.getGlobal().log(Level.INFO, message, args))
|
|
||||||
// // Use paper repository for downloading slimjar dependencies
|
|
||||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
|
||||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
|
||||||
// .build();
|
|
||||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
|
||||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
|
||||||
// java.util.logging.Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
|
||||||
// logger.error("Plan failed to load its dependencies correctly!");
|
|
||||||
// logger.error("This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
|
||||||
// onDisable();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
@ -91,22 +91,6 @@ public class PlanVelocity implements PlanPlugin {
|
|||||||
logger = abstractionLayer.getPluginLogger();
|
logger = abstractionLayer.getPluginLogger();
|
||||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||||
|
|
||||||
// logger.info("Loading dependencies, this might take a while...");
|
|
||||||
// try {
|
|
||||||
// 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/"))))
|
|
||||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
|
||||||
// .build();
|
|
||||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
|
||||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
|
||||||
// java.util.logging.Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
|
||||||
// logger.error("Plan failed to load its dependencies correctly!");
|
|
||||||
// logger.error("This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
|
||||||
// onDisable();
|
|
||||||
// }
|
|
||||||
|
|
||||||
onEnable();
|
onEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 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 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()));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user