diff --git a/buildscript/relocations.gradle b/buildscript/relocations.gradle index 0f9b3938..48f977d0 100644 --- a/buildscript/relocations.gradle +++ b/buildscript/relocations.gradle @@ -28,6 +28,9 @@ shadowJar { 'io.leangen.geantyref', 'org.yaml.snakeyaml', + // HikariCP + 'com.zaxxer.hikari', + // Adventure, EnhancedLegacyText, MCDiscordReserializer 'net.kyori', 'dev.vankka.enhancedlegacytext', diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java b/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java index ac01d94b..4e49fde8 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java @@ -38,6 +38,7 @@ import com.discordsrv.common.logging.Logger; import com.discordsrv.common.messageforwarding.game.MinecraftToDiscordChatModule; import com.discordsrv.common.plugin.PluginManager; import com.discordsrv.common.server.ServerDiscordSRV; +import dev.vankka.dependencydownload.classpath.ClasspathAppender; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.Server; import org.bukkit.plugin.ServicePriority; @@ -150,6 +151,11 @@ public class BukkitDiscordSRV extends ServerDiscordSRV connectionConfigManager() { return connectionConfigManager; diff --git a/bungee/src/main/java/com/discordsrv/bungee/BungeeDiscordSRV.java b/bungee/src/main/java/com/discordsrv/bungee/BungeeDiscordSRV.java index 7820e3b3..2f7e4eb8 100644 --- a/bungee/src/main/java/com/discordsrv/bungee/BungeeDiscordSRV.java +++ b/bungee/src/main/java/com/discordsrv/bungee/BungeeDiscordSRV.java @@ -30,6 +30,7 @@ import com.discordsrv.common.logging.Logger; import com.discordsrv.common.plugin.PluginManager; import com.discordsrv.common.scheduler.StandardScheduler; import com.discordsrv.proxy.ProxyDiscordSRV; +import dev.vankka.dependencydownload.classpath.ClasspathAppender; import net.kyori.adventure.platform.bungeecord.BungeeAudiences; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.plugin.Plugin; @@ -114,6 +115,11 @@ public class BungeeDiscordSRV extends ProxyDiscordSRV connectionConfigManager() { return null; diff --git a/common/build.gradle b/common/build.gradle index 473df2c8..78e3769c 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -4,7 +4,7 @@ configurations { hikari h2Driver mysqlDriver - compileOnly.extendsFrom hikari + compileOnly.extendsFrom hikari, h2Driver, mysqlDriver testRuntimeOnly.extendsFrom runtimeDownloadOnly } @@ -13,6 +13,7 @@ task generateResourceForHikari(type: GenerateDependencyDownloadResourceTask) { configuration = conf file = 'dependencies/' + conf.name + '.txt' relocate 'com.zaxxer.hikari', 'com.discordsrv.dependencies.com.zaxxer.hikari' + relocate 'org.slf4j', 'com.discordsrv.dependencies.org.slf4j' } task generateResourceForH2Driver(type: GenerateDependencyDownloadResourceTask) { var conf = configurations.h2Driver diff --git a/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java b/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java index f131edab..2c314bf3 100644 --- a/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java +++ b/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java @@ -33,12 +33,14 @@ import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.manager.ConnectionConfigManager; import com.discordsrv.common.config.manager.MainConfigManager; +import com.discordsrv.common.dependency.DependencyLoader; import com.discordsrv.common.discord.api.DiscordAPIEventModule; import com.discordsrv.common.discord.api.DiscordAPIImpl; import com.discordsrv.common.discord.connection.DiscordConnectionManager; import com.discordsrv.common.discord.connection.jda.JDAConnectionManager; import com.discordsrv.common.discord.details.DiscordConnectionDetailsImpl; import com.discordsrv.common.event.bus.EventBusImpl; +import com.discordsrv.common.exception.StorageException; import com.discordsrv.common.function.CheckedFunction; import com.discordsrv.common.function.CheckedRunnable; import com.discordsrv.common.groupsync.GroupSyncModule; @@ -60,6 +62,7 @@ import com.discordsrv.common.placeholder.PlaceholderServiceImpl; import com.discordsrv.common.placeholder.context.GlobalTextHandlingContext; import com.discordsrv.common.profile.ProfileManager; import com.discordsrv.common.storage.Storage; +import com.discordsrv.common.storage.StorageType; import net.dv8tion.jda.api.JDA; import org.jetbrains.annotations.NotNull; @@ -68,6 +71,7 @@ import java.util.Locale; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReentrantLock; @@ -333,6 +337,29 @@ public abstract class AbstractDiscordSRV. + */ + package com.discordsrv.common.config.connection; import org.spongepowered.configurate.objectmapping.ConfigSerializable; diff --git a/common/src/main/java/com/discordsrv/common/dependency/DependencyLoader.java b/common/src/main/java/com/discordsrv/common/dependency/DependencyLoader.java index dfd09a51..83a36aa7 100644 --- a/common/src/main/java/com/discordsrv/common/dependency/DependencyLoader.java +++ b/common/src/main/java/com/discordsrv/common/dependency/DependencyLoader.java @@ -33,6 +33,10 @@ import java.util.concurrent.Executor; public class DependencyLoader { + public static DependencyLoader hikari(DiscordSRV discordSRV) { + return new DependencyLoader(discordSRV, new String[] {"dependencies/hikari.txt"}); + } + public static DependencyLoader h2(DiscordSRV discordSRV) { return new DependencyLoader(discordSRV, new String[] {"dependencies/h2Driver.txt"}); } diff --git a/common/src/main/java/com/discordsrv/common/exception/StorageException.java b/common/src/main/java/com/discordsrv/common/exception/StorageException.java index 6b1c9edb..51256e2a 100644 --- a/common/src/main/java/com/discordsrv/common/exception/StorageException.java +++ b/common/src/main/java/com/discordsrv/common/exception/StorageException.java @@ -1,12 +1,45 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.discordsrv.common.exception; +import com.discordsrv.common.DiscordSRV; + public class StorageException extends RuntimeException { public StorageException(Throwable cause) { - super(cause); + super(null, cause); } public StorageException(String message) { super(message); } + + public void log(DiscordSRV discordSRV) { + String baseMessage = "Failed to initialize storage"; + Throwable cause = getCause(); + String message = getMessage(); + if (cause != null && message != null) { + discordSRV.logger().error(baseMessage, this); + } else if (message != null) { + discordSRV.logger().error(baseMessage + ": " + message); + } else if (cause != null) { + discordSRV.logger().error(baseMessage, cause); + } + } } diff --git a/common/src/main/java/com/discordsrv/common/function/CheckedConsumer.java b/common/src/main/java/com/discordsrv/common/function/CheckedConsumer.java index 7ebf7426..52bee715 100644 --- a/common/src/main/java/com/discordsrv/common/function/CheckedConsumer.java +++ b/common/src/main/java/com/discordsrv/common/function/CheckedConsumer.java @@ -1,3 +1,21 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.discordsrv.common.function; @FunctionalInterface diff --git a/common/src/main/java/com/discordsrv/common/logging/impl/DependencyLoggingHandler.java b/common/src/main/java/com/discordsrv/common/logging/impl/DependencyLoggingHandler.java index a54eb189..93c47ac9 100644 --- a/common/src/main/java/com/discordsrv/common/logging/impl/DependencyLoggingHandler.java +++ b/common/src/main/java/com/discordsrv/common/logging/impl/DependencyLoggingHandler.java @@ -34,6 +34,7 @@ public class DependencyLoggingHandler implements LogAppender { static { // Class names here will get relocated, which is fine LOGGER_MAPPINGS.put("net.dv8tion.jda", "JDA"); + LOGGER_MAPPINGS.put("com.zaxxer.hikari", "Hikari"); BLACKLISTED_MESSAGES.put("net.dv8tion.jda", Arrays.asList( // We have our own more informative log messages for this @@ -42,6 +43,10 @@ public class DependencyLoggingHandler implements LogAppender { "There was an I/O error while executing a REST request: ", "There was an unexpected error while executing a REST request" )); + BLACKLISTED_MESSAGES.put("com.zaxxer.hikari", Collections.singletonList( + // This is fine, we don't need a warning about it + "was not found, trying direct instantiation." // "Registered driver with driverClassName={} was not found, trying direct instantiation." + )); } private final DiscordSRV discordSRV; diff --git a/common/src/main/java/com/discordsrv/common/storage/StorageType.java b/common/src/main/java/com/discordsrv/common/storage/StorageType.java new file mode 100644 index 00000000..23f67b9e --- /dev/null +++ b/common/src/main/java/com/discordsrv/common/storage/StorageType.java @@ -0,0 +1,47 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.discordsrv.common.storage; + +import com.discordsrv.common.DiscordSRV; +import com.discordsrv.common.storage.impl.sql.file.H2Storage; +import com.discordsrv.common.storage.impl.sql.hikari.MySQLStorage; + +import java.util.function.Function; + +public enum StorageType { + + H2(H2Storage::new, false), + MYSQL(MySQLStorage::new, true); + + private final Function storageFunction; + private final boolean hikari; + + StorageType(Function storageFunction, boolean hikari) { + this.storageFunction = storageFunction; + this.hikari = hikari; + } + + public Function storageFunction() { + return storageFunction; + } + + public boolean hikari() { + return hikari; + } +} diff --git a/common/src/main/java/com/discordsrv/common/storage/impl/package-info.java b/common/src/main/java/com/discordsrv/common/storage/impl/package-info.java index a871c9e3..26f3544b 100644 --- a/common/src/main/java/com/discordsrv/common/storage/impl/package-info.java +++ b/common/src/main/java/com/discordsrv/common/storage/impl/package-info.java @@ -1 +1,19 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.discordsrv.common.storage.impl; diff --git a/common/src/main/java/com/discordsrv/common/storage/impl/sql/SQLStorage.java b/common/src/main/java/com/discordsrv/common/storage/impl/sql/SQLStorage.java index 3aea4ad4..0d43c421 100644 --- a/common/src/main/java/com/discordsrv/common/storage/impl/sql/SQLStorage.java +++ b/common/src/main/java/com/discordsrv/common/storage/impl/sql/SQLStorage.java @@ -1,3 +1,21 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.discordsrv.common.storage.impl.sql; import com.discordsrv.common.exception.StorageException; @@ -7,16 +25,14 @@ import com.discordsrv.common.storage.Storage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Statement; +import java.sql.*; import java.util.UUID; public abstract class SQLStorage implements Storage { public abstract Connection getConnection(); public abstract boolean isAutoCloseConnections(); + public abstract void createTables(Connection connection) throws SQLException; private void useConnection(CheckedConsumer connectionConsumer) throws StorageException { useConnection(connection -> { @@ -47,11 +63,7 @@ public abstract class SQLStorage implements Storage { @Override public void initialize() { - useConnection(connection -> { - try (Statement statement = connection.createStatement()) { - statement.execute("create table if not exists LINKED_ACCOUNTS (ID int not null auto_increment, PLAYER_UUID uuid, USER_ID bigint)"); - } - }); + useConnection(this::createTables); } @Override diff --git a/common/src/main/java/com/discordsrv/common/storage/impl/sql/file/H2Storage.java b/common/src/main/java/com/discordsrv/common/storage/impl/sql/file/H2Storage.java index e534ef6c..af5152d7 100644 --- a/common/src/main/java/com/discordsrv/common/storage/impl/sql/file/H2Storage.java +++ b/common/src/main/java/com/discordsrv/common/storage/impl/sql/file/H2Storage.java @@ -1,3 +1,21 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.discordsrv.common.storage.impl.sql.file; import com.discordsrv.common.DiscordSRV; @@ -11,6 +29,7 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.sql.Connection; import java.sql.SQLException; +import java.sql.Statement; import java.util.Properties; public class H2Storage extends SQLStorage { @@ -40,7 +59,7 @@ public class H2Storage extends SQLStorage { Properties.class, // info String.class, // username Object.class, // password - Boolean.class // forbidCreation + boolean.class // forbidCreation ); connection = (Connection) constructor.newInstance( "jdbc:h2:" + discordSRV.dataDirectory().resolve("h2-database").toAbsolutePath(), @@ -80,4 +99,17 @@ public class H2Storage extends SQLStorage { public boolean isAutoCloseConnections() { return false; } + + @Override + public void createTables(Connection connection) throws SQLException { + try (Statement statement = connection.createStatement()) { + statement.execute( + "create table if not exists LINKED_ACCOUNTS " + + "(ID int not null auto_increment, " + + "PLAYER_UUID varchar(36), " + + "USER_ID bigint, " + + "constraint LINKED_ACCOUNTS_PK primary key (ID)" + + ")"); + } + } } diff --git a/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/HikariStorage.java b/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/HikariStorage.java index 6fc88cfe..92c80f2b 100644 --- a/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/HikariStorage.java +++ b/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/HikariStorage.java @@ -1,3 +1,21 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.discordsrv.common.storage.impl.sql.hikari; import com.discordsrv.common.DiscordSRV; @@ -6,6 +24,7 @@ import com.discordsrv.common.exception.StorageException; import com.discordsrv.common.storage.impl.sql.SQLStorage; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; +import com.zaxxer.hikari.pool.HikariPool; import java.sql.Connection; import java.sql.SQLException; @@ -21,7 +40,7 @@ public abstract class HikariStorage extends SQLStorage { protected abstract void applyConfiguration(HikariConfig config, StorageConfig storageConfig); - protected T initializeWithContext(T classLoader) { + protected void initializeWithContext(ClassLoader classLoader) { Thread currentThread = Thread.currentThread(); ClassLoader originalContext = currentThread.getContextClassLoader(); try { @@ -30,7 +49,6 @@ public abstract class HikariStorage extends SQLStorage { } finally { currentThread.setContextClassLoader(originalContext); } - return classLoader; } private void initializeInternal() { @@ -48,7 +66,16 @@ public abstract class HikariStorage extends SQLStorage { config.setKeepaliveTime(poolConfig.keepaliveTime); applyConfiguration(config, storageConfig); - hikariDataSource = new HikariDataSource(config); + try { + hikariDataSource = new HikariDataSource(config); + } catch (RuntimeException e) { + // Avoid running into runtime ClassNotFoundException by not using this as the catch + if (e instanceof HikariPool.PoolInitializationException) { + // Already logged by Hikari, so we'll throw an empty exception + throw new StorageException((Throwable) null); + } + throw e; + } super.initialize(); } diff --git a/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/MySQLStorage.java b/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/MySQLStorage.java index 5c9d6826..e3e2127a 100644 --- a/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/MySQLStorage.java +++ b/common/src/main/java/com/discordsrv/common/storage/impl/sql/hikari/MySQLStorage.java @@ -1,3 +1,21 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.discordsrv.common.storage.impl.sql.hikari; import com.discordsrv.common.DiscordSRV; @@ -8,6 +26,9 @@ import com.zaxxer.hikari.HikariConfig; import dev.vankka.dependencydownload.classloader.IsolatedClassLoader; import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; import java.util.Map; public class MySQLStorage extends HikariStorage { @@ -30,10 +51,23 @@ public class MySQLStorage extends HikariStorage { } } + @Override + public void createTables(Connection connection) throws SQLException { + try (Statement statement = connection.createStatement()) { + statement.execute( + "create table if not exists LINKED_ACCOUNTS " + + "(ID int not null auto_increment, " + + "PLAYER_UUID varchar(36), " + + "USER_ID bigint, " + + "constraint LINKED_ACCOUNTS_PK primary key (ID)" + + ")"); + } + } + @Override public void initialize() { try { - classLoader = initializeWithContext(DependencyLoader.mysql(discordSRV).loadIntoIsolated()); + initializeWithContext(classLoader = DependencyLoader.mysql(discordSRV).loadIntoIsolated()); } catch (IOException e) { throw new StorageException(e); } @@ -46,7 +80,7 @@ public class MySQLStorage extends HikariStorage { address += ":3306"; } - config.setDriverClassName("com.mysql.cj.jdbc.Driver"); + config.setDriverClassName("com.mysql.cj.jdbc.NonRegisteringDriver"); config.setJdbcUrl("jdbc:mysql://" + address + "/" + storageConfig.remote.databaseName); for (Map.Entry entry : storageConfig.getDriverProperties().entrySet()) { config.addDataSourceProperty((String) entry.getKey(), entry.getValue()); diff --git a/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java b/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java index dd8a2ddf..06a2369d 100644 --- a/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java +++ b/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java @@ -30,6 +30,7 @@ import com.discordsrv.common.player.provider.AbstractPlayerProvider; import com.discordsrv.common.plugin.PluginManager; import com.discordsrv.common.scheduler.Scheduler; import com.discordsrv.common.scheduler.StandardScheduler; +import dev.vankka.dependencydownload.classpath.ClasspathAppender; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -96,6 +97,11 @@ public class MockDiscordSRV extends AbstractDiscordSRV playerProvider() { return null; diff --git a/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java b/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java index e49b543d..589d7af6 100644 --- a/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java +++ b/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java @@ -29,6 +29,7 @@ import com.discordsrv.common.logging.Logger; import com.discordsrv.common.player.provider.AbstractPlayerProvider; import com.discordsrv.common.plugin.PluginManager; import com.discordsrv.common.scheduler.Scheduler; +import dev.vankka.dependencydownload.classpath.ClasspathAppender; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; @@ -71,6 +72,11 @@ public class MockDiscordSRV extends AbstractDiscordSRV playerProvider() { return null; diff --git a/sponge/src/main/java/com/discordsrv/sponge/DiscordSRVSpongeBootstrap.java b/sponge/src/main/java/com/discordsrv/sponge/DiscordSRVSpongeBootstrap.java index 1eb0ca27..6b8a71a5 100644 --- a/sponge/src/main/java/com/discordsrv/sponge/DiscordSRVSpongeBootstrap.java +++ b/sponge/src/main/java/com/discordsrv/sponge/DiscordSRVSpongeBootstrap.java @@ -22,6 +22,7 @@ import com.discordsrv.common.dependency.InitialDependencyLoader; import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl; import com.discordsrv.sponge.bootstrap.ISpongeBootstrap; +import dev.vankka.dependencydownload.classpath.ClasspathAppender; import dev.vankka.mcdependencydownload.bootstrap.AbstractBootstrap; import dev.vankka.mcdependencydownload.bootstrap.classpath.JarInJarClasspathAppender; import dev.vankka.mcdependencydownload.classloader.JarInJarClassLoader; @@ -35,27 +36,27 @@ import java.nio.file.Path; public class DiscordSRVSpongeBootstrap extends AbstractBootstrap implements ISpongeBootstrap { private final Logger logger; + private final ClasspathAppender classpathAppender; private final InitialDependencyLoader dependencies; private SpongeDiscordSRV discordSRV; private final PluginContainer pluginContainer; private final Game game; - private final JarInJarClassLoader classLoader; private final Path dataDirectory; public DiscordSRVSpongeBootstrap(PluginContainer pluginContainer, Game game, JarInJarClassLoader classLoader, Path dataDirectory) throws IOException { // Don't change these parameters super(classLoader); this.logger = new Log4JLoggerImpl(pluginContainer.logger()); + this.classpathAppender = new JarInJarClasspathAppender(classLoader); this.dependencies = new InitialDependencyLoader( logger, dataDirectory, new String[] {"dependencies/runtimeDownload-sponge.txt"}, - new JarInJarClasspathAppender(classLoader) + classpathAppender ); this.pluginContainer = pluginContainer; this.game = game; - this.classLoader = classLoader; this.dataDirectory = dataDirectory; } @@ -66,7 +67,7 @@ public class DiscordSRVSpongeBootstrap extends AbstractBootstrap implements ISpo @Override public void onStarted() { - dependencies.enable(() -> this.discordSRV = new SpongeDiscordSRV(logger, pluginContainer, game, classLoader, dataDirectory)); + dependencies.enable(() -> this.discordSRV = new SpongeDiscordSRV(logger, classpathAppender, dataDirectory, pluginContainer, game)); if (discordSRV != null) { discordSRV.invokeServerStarted(); } diff --git a/sponge/src/main/java/com/discordsrv/sponge/SpongeDiscordSRV.java b/sponge/src/main/java/com/discordsrv/sponge/SpongeDiscordSRV.java index 7284acca..8a5de485 100644 --- a/sponge/src/main/java/com/discordsrv/sponge/SpongeDiscordSRV.java +++ b/sponge/src/main/java/com/discordsrv/sponge/SpongeDiscordSRV.java @@ -31,7 +31,7 @@ import com.discordsrv.sponge.console.SpongeConsole; import com.discordsrv.sponge.player.SpongePlayerProvider; import com.discordsrv.sponge.plugin.SpongePluginManager; import com.discordsrv.sponge.scheduler.SpongeScheduler; -import dev.vankka.mcdependencydownload.classloader.JarInJarClassLoader; +import dev.vankka.dependencydownload.classpath.ClasspathAppender; import org.jetbrains.annotations.NotNull; import org.spongepowered.api.Game; import org.spongepowered.api.event.Listener; @@ -46,17 +46,19 @@ public class SpongeDiscordSRV extends ServerDiscordSRV connectionConfigManager() { return null; diff --git a/velocity/src/main/java/com/discordsrv/velocity/DiscordSRVVelocityBootstrap.java b/velocity/src/main/java/com/discordsrv/velocity/DiscordSRVVelocityBootstrap.java index e48fe8ac..7c144407 100644 --- a/velocity/src/main/java/com/discordsrv/velocity/DiscordSRVVelocityBootstrap.java +++ b/velocity/src/main/java/com/discordsrv/velocity/DiscordSRVVelocityBootstrap.java @@ -30,6 +30,7 @@ import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.ProxyServer; +import dev.vankka.dependencydownload.classpath.ClasspathAppender; import dev.vankka.mcdependencydownload.velocity.classpath.VelocityClasspathAppender; import java.io.IOException; @@ -46,6 +47,7 @@ import java.nio.file.Path; public class DiscordSRVVelocityBootstrap { private final Logger logger; + private final ClasspathAppender classpathAppender; private final InitialDependencyLoader dependencies; private final ProxyServer proxyServer; private final PluginContainer pluginContainer; @@ -55,11 +57,12 @@ public class DiscordSRVVelocityBootstrap { @Inject public DiscordSRVVelocityBootstrap(com.discordsrv.x.slf4j.Logger logger, ProxyServer proxyServer, PluginContainer pluginContainer, @DataDirectory Path dataDirectory) throws IOException { this.logger = new SLF4JLoggerImpl(logger); + this.classpathAppender = new VelocityClasspathAppender(this, proxyServer); this.dependencies = new InitialDependencyLoader( this.logger, dataDirectory, new String[] {"dependencies/runtimeDownload-velocity.txt"}, - new VelocityClasspathAppender(this, proxyServer) + classpathAppender ); this.proxyServer = proxyServer; this.pluginContainer = pluginContainer; @@ -68,7 +71,7 @@ public class DiscordSRVVelocityBootstrap { @Subscribe public void onProxyInitialize(ProxyInitializeEvent event) { - dependencies.loadAndEnable(() -> this.discordSRV = new VelocityDiscordSRV(this, logger, proxyServer, pluginContainer, dataDirectory)); + dependencies.loadAndEnable(() -> this.discordSRV = new VelocityDiscordSRV(this, logger, classpathAppender, proxyServer, pluginContainer, dataDirectory)); } @Subscribe diff --git a/velocity/src/main/java/com/discordsrv/velocity/VelocityDiscordSRV.java b/velocity/src/main/java/com/discordsrv/velocity/VelocityDiscordSRV.java index 0ad5f310..a8cb5177 100644 --- a/velocity/src/main/java/com/discordsrv/velocity/VelocityDiscordSRV.java +++ b/velocity/src/main/java/com/discordsrv/velocity/VelocityDiscordSRV.java @@ -32,6 +32,7 @@ import com.discordsrv.velocity.player.VelocityPlayerProvider; import com.discordsrv.velocity.plugin.VelocityPluginManager; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.proxy.ProxyServer; +import dev.vankka.dependencydownload.classpath.ClasspathAppender; import org.jetbrains.annotations.NotNull; import java.nio.file.Path; @@ -43,17 +44,19 @@ public class VelocityDiscordSRV extends ProxyDiscordSRV connectionConfigManager() { return null;