From d335a0b63fb7010e53a7f124f71e2c49df9d31cd Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Tue, 7 Feb 2023 04:52:54 -0500 Subject: [PATCH] Reform dependency structure. --- common-plugin/build.gradle.kts | 4 ++ .../foundation/common/FoundationCoreLoader.kt | 11 ++++++ .../foundation/common/PluginMainClass.kt | 3 -- foundation-bifrost/build.gradle.kts | 3 +- .../bifrost/FoundationBifrostPlugin.kt | 13 ++----- foundation-chaos/build.gradle.kts | 2 +- .../foundation/chaos/FoundationChaosPlugin.kt | 11 +++--- .../pizza/foundation/chaos/modules/MegaTnt.kt | 2 +- .../foundation/chaos/modules/TntAllPlayers.kt | 2 +- foundation-core/build.gradle.kts | 5 +-- .../foundation/core/FoundationCorePlugin.kt | 9 +++-- .../kotlin/gay/pizza/foundation/core/Util.kt | 37 ------------------ .../core/features/backup/BackupCommand.kt | 2 +- .../core/features/backup/BackupFeature.kt | 4 +- .../core/features/dev/DevUpdateServer.kt | 4 +- .../core/features/gameplay/GameplayFeature.kt | 4 +- .../core/features/player/GooseCommand.kt | 2 +- .../core/features/player/MegaTntCommand.kt | 2 +- .../core/features/player/PlayerFeature.kt | 4 +- .../core/features/stats/LeaderboardCommand.kt | 4 +- foundation-heimdall/build.gradle.kts | 5 ++- .../plugin/FoundationHeimdallPlugin.kt | 13 +++---- .../src/main/resources/plugin.yml | 2 +- foundation-shared/build.gradle.kts | 3 ++ .../shared}/AdvancementTitleCache.kt | 2 +- .../foundation/shared}/ChatExtensions.kt | 2 +- .../shared}/CollectionExtensions.kt | 2 +- .../foundation/shared/IFoundationCore.kt | 7 ++++ .../gay/pizza/foundation/shared}/Platform.kt | 2 +- .../foundation/shared/PluginMainClass.kt | 3 ++ .../foundation/shared}/ServerExtensions.kt | 2 +- .../gay/pizza/foundation/shared}/SortOrder.kt | 2 +- .../foundation/shared}/SpawnExtensions.kt | 2 +- .../foundation/shared/copyDefaultConfig.kt | 39 +++++++++++++++++++ settings.gradle.kts | 1 + tool-gjallarhorn/build.gradle.kts | 4 +- 36 files changed, 121 insertions(+), 98 deletions(-) create mode 100644 common-plugin/src/main/kotlin/gay/pizza/foundation/common/FoundationCoreLoader.kt delete mode 100644 common-plugin/src/main/kotlin/gay/pizza/foundation/common/PluginMainClass.kt create mode 100644 foundation-shared/build.gradle.kts rename {common-plugin/src/main/kotlin/gay/pizza/foundation/common => foundation-shared/src/main/kotlin/gay/pizza/foundation/shared}/AdvancementTitleCache.kt (98%) rename {common-plugin/src/main/kotlin/gay/pizza/foundation/common => foundation-shared/src/main/kotlin/gay/pizza/foundation/shared}/ChatExtensions.kt (78%) rename {common-plugin/src/main/kotlin/gay/pizza/foundation/common => foundation-shared/src/main/kotlin/gay/pizza/foundation/shared}/CollectionExtensions.kt (85%) create mode 100644 foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/IFoundationCore.kt rename {common-plugin/src/main/kotlin/gay/pizza/foundation/common => foundation-shared/src/main/kotlin/gay/pizza/foundation/shared}/Platform.kt (81%) create mode 100644 foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/PluginMainClass.kt rename {common-plugin/src/main/kotlin/gay/pizza/foundation/common => foundation-shared/src/main/kotlin/gay/pizza/foundation/shared}/ServerExtensions.kt (95%) rename {common-plugin/src/main/kotlin/gay/pizza/foundation/common => foundation-shared/src/main/kotlin/gay/pizza/foundation/shared}/SortOrder.kt (59%) rename {common-plugin/src/main/kotlin/gay/pizza/foundation/common => foundation-shared/src/main/kotlin/gay/pizza/foundation/shared}/SpawnExtensions.kt (91%) create mode 100644 foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/copyDefaultConfig.kt diff --git a/common-plugin/build.gradle.kts b/common-plugin/build.gradle.kts index 36dc4fa..33f4f70 100644 --- a/common-plugin/build.gradle.kts +++ b/common-plugin/build.gradle.kts @@ -1,3 +1,7 @@ plugins { id("gay.pizza.foundation.concrete-library") } + +dependencies { + compileOnly(project(":foundation-shared")) +} diff --git a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/FoundationCoreLoader.kt b/common-plugin/src/main/kotlin/gay/pizza/foundation/common/FoundationCoreLoader.kt new file mode 100644 index 0000000..dbdf3c1 --- /dev/null +++ b/common-plugin/src/main/kotlin/gay/pizza/foundation/common/FoundationCoreLoader.kt @@ -0,0 +1,11 @@ +package gay.pizza.foundation.common + +import gay.pizza.foundation.shared.IFoundationCore +import org.bukkit.Server + +object FoundationCoreLoader { + fun get(server: Server): IFoundationCore { + return server.pluginManager.getPlugin("Foundation") as IFoundationCore? + ?: throw RuntimeException("Foundation Core is not loaded!") + } +} diff --git a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/PluginMainClass.kt b/common-plugin/src/main/kotlin/gay/pizza/foundation/common/PluginMainClass.kt deleted file mode 100644 index 0850402..0000000 --- a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/PluginMainClass.kt +++ /dev/null @@ -1,3 +0,0 @@ -package gay.pizza.foundation.common - -annotation class PluginMainClass diff --git a/foundation-bifrost/build.gradle.kts b/foundation-bifrost/build.gradle.kts index 0952290..d559834 100644 --- a/foundation-bifrost/build.gradle.kts +++ b/foundation-bifrost/build.gradle.kts @@ -7,5 +7,6 @@ dependencies { exclude(module = "opus-java") } - compileOnly(project(":foundation-core")) + implementation(project(":common-plugin")) + compileOnly(project(":foundation-shared")) } diff --git a/foundation-bifrost/src/main/kotlin/gay/pizza/foundation/bifrost/FoundationBifrostPlugin.kt b/foundation-bifrost/src/main/kotlin/gay/pizza/foundation/bifrost/FoundationBifrostPlugin.kt index 0250d44..ed37f78 100644 --- a/foundation-bifrost/src/main/kotlin/gay/pizza/foundation/bifrost/FoundationBifrostPlugin.kt +++ b/foundation-bifrost/src/main/kotlin/gay/pizza/foundation/bifrost/FoundationBifrostPlugin.kt @@ -2,10 +2,8 @@ package gay.pizza.foundation.bifrost import com.charleskorn.kaml.Yaml import gay.pizza.foundation.bifrost.model.BifrostConfig -import gay.pizza.foundation.common.PluginMainClass -import gay.pizza.foundation.core.FoundationCorePlugin -import gay.pizza.foundation.core.Util -import gay.pizza.foundation.common.AdvancementTitleCache +import gay.pizza.foundation.common.FoundationCoreLoader +import gay.pizza.foundation.shared.* import io.papermc.paper.event.player.AsyncChatEvent import net.dv8tion.jda.api.EmbedBuilder import net.dv8tion.jda.api.JDA @@ -38,11 +36,8 @@ class FoundationBifrostPlugin : JavaPlugin(), DiscordEventListener, BukkitEventL override fun onEnable() { isDev = description.version == "DEV" - - val foundation = server.pluginManager.getPlugin("Foundation") as FoundationCorePlugin - slF4JLogger.info("Plugin data path: ${foundation.pluginDataPath}") - - val configPath = Util.copyDefaultConfig( + val foundation = FoundationCoreLoader.get(server) + val configPath = copyDefaultConfig( slF4JLogger, foundation.pluginDataPath, "bifrost.yaml" diff --git a/foundation-chaos/build.gradle.kts b/foundation-chaos/build.gradle.kts index b4cb561..503cbfd 100644 --- a/foundation-chaos/build.gradle.kts +++ b/foundation-chaos/build.gradle.kts @@ -4,5 +4,5 @@ plugins { dependencies { implementation(project(":common-plugin")) - compileOnly(project(":foundation-core")) + compileOnly(project(":foundation-shared")) } diff --git a/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/FoundationChaosPlugin.kt b/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/FoundationChaosPlugin.kt index 969766a..60dc5af 100644 --- a/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/FoundationChaosPlugin.kt +++ b/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/FoundationChaosPlugin.kt @@ -2,9 +2,9 @@ package gay.pizza.foundation.chaos import com.charleskorn.kaml.Yaml import gay.pizza.foundation.chaos.model.ChaosConfig -import gay.pizza.foundation.common.PluginMainClass -import gay.pizza.foundation.core.FoundationCorePlugin -import gay.pizza.foundation.core.Util +import gay.pizza.foundation.common.FoundationCoreLoader +import gay.pizza.foundation.shared.PluginMainClass +import gay.pizza.foundation.shared.copyDefaultConfig import org.bukkit.plugin.java.JavaPlugin import kotlin.io.path.inputStream @@ -17,9 +17,8 @@ class FoundationChaosPlugin : JavaPlugin() { } override fun onEnable() { - val foundation = server.pluginManager.getPlugin("Foundation") as FoundationCorePlugin - slF4JLogger.info("Plugin data path: ${foundation.pluginDataPath}") - val configPath = Util.copyDefaultConfig( + val foundation = FoundationCoreLoader.get(server) + val configPath = copyDefaultConfig( slF4JLogger, foundation.pluginDataPath, "chaos.yaml" diff --git a/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/modules/MegaTnt.kt b/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/modules/MegaTnt.kt index 1a91239..c85f421 100644 --- a/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/modules/MegaTnt.kt +++ b/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/modules/MegaTnt.kt @@ -1,6 +1,6 @@ package gay.pizza.foundation.chaos.modules -import gay.pizza.foundation.common.spawn +import gay.pizza.foundation.shared.spawn import org.bukkit.entity.TNTPrimed import org.bukkit.plugin.Plugin diff --git a/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/modules/TntAllPlayers.kt b/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/modules/TntAllPlayers.kt index c9727bb..3426c44 100644 --- a/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/modules/TntAllPlayers.kt +++ b/foundation-chaos/src/main/kotlin/gay/pizza/foundation/chaos/modules/TntAllPlayers.kt @@ -1,6 +1,6 @@ package gay.pizza.foundation.chaos.modules -import gay.pizza.foundation.common.spawn +import gay.pizza.foundation.shared.spawn import org.bukkit.entity.TNTPrimed import org.bukkit.plugin.Plugin diff --git a/foundation-core/build.gradle.kts b/foundation-core/build.gradle.kts index 371b29e..f334642 100644 --- a/foundation-core/build.gradle.kts +++ b/foundation-core/build.gradle.kts @@ -3,10 +3,9 @@ plugins { } dependencies { - // TODO: might be able to ship all dependencies in core? are we duplicating classes in JARs? + implementation(project(":foundation-shared")) + implementation("software.amazon.awssdk:s3:2.19.31") implementation("org.quartz-scheduler:quartz:2.3.2") implementation("com.google.guava:guava:31.1-jre") - - api(project(":common-plugin")) } diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/FoundationCorePlugin.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/FoundationCorePlugin.kt index 3067e5a..e457e20 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/FoundationCorePlugin.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/FoundationCorePlugin.kt @@ -1,6 +1,7 @@ package gay.pizza.foundation.core -import gay.pizza.foundation.common.PluginMainClass +import gay.pizza.foundation.shared.IFoundationCore +import gay.pizza.foundation.shared.PluginMainClass import gay.pizza.foundation.core.abstraction.FoundationPlugin import gay.pizza.foundation.core.features.backup.BackupFeature import gay.pizza.foundation.core.features.dev.DevFeature @@ -15,17 +16,17 @@ import org.koin.dsl.module import java.nio.file.Path @PluginMainClass -class FoundationCorePlugin : FoundationPlugin() { +class FoundationCorePlugin : IFoundationCore, FoundationPlugin() { private lateinit var _pluginDataPath: Path - var pluginDataPath: Path + override var pluginDataPath: Path /** * Data path of the core plugin. * Can be used as a check of sorts for dependencies to be sure the plugin is loaded. */ get() { if (!::_pluginDataPath.isInitialized) { - throw Exception("FoundationCore is not loaded!") + throw Exception("Foundation Core is not loaded!") } return _pluginDataPath } diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/Util.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/Util.kt index f1b2409..33869bc 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/Util.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/Util.kt @@ -2,8 +2,6 @@ package gay.pizza.foundation.core import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.TextColor -import org.slf4j.Logger -import java.nio.file.Path object Util { private val leftBracket: Component = Component.text('[') @@ -22,39 +20,4 @@ object Util { .append(whitespace) .append(Component.text(message)) } - - /** - * Copy the default configuration from the resource [resourceName] into the directory [targetPath]. - * @param targetPath The output directory as a path, it must exist before calling this. - * @param resourceName Path to resource, it should be in the root of the `resources` directory, - * without the leading slash. - */ - inline fun copyDefaultConfig(log: Logger, targetPath: Path, resourceName: String): Path { - if (resourceName.startsWith("/")) { - throw IllegalArgumentException("resourceName starts with slash") - } - - if (!targetPath.toFile().exists()) { - throw Exception("Configuration output path does not exist!") - } - val outPath = targetPath.resolve(resourceName) - val outFile = outPath.toFile() - if (outFile.exists()) { - log.debug("Configuration file already exists.") - return outPath - } - - val resourceStream = T::class.java.getResourceAsStream("/$resourceName") - ?: throw Exception("Configuration resource does not exist!") - val outputStream = outFile.outputStream() - - resourceStream.use { - outputStream.use { - log.info("Copied default configuration to $outPath") - resourceStream.copyTo(outputStream) - } - } - - return outPath - } } diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/backup/BackupCommand.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/backup/BackupCommand.kt index e75a4cc..b2edec4 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/backup/BackupCommand.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/backup/BackupCommand.kt @@ -1,6 +1,6 @@ package gay.pizza.foundation.core.features.backup -import gay.pizza.foundation.common.Platform +import gay.pizza.foundation.shared.Platform import gay.pizza.foundation.core.FoundationCorePlugin import gay.pizza.foundation.core.Util import net.kyori.adventure.text.Component diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/backup/BackupFeature.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/backup/BackupFeature.kt index f3e5dfc..677df3c 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/backup/BackupFeature.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/backup/BackupFeature.kt @@ -1,8 +1,8 @@ package gay.pizza.foundation.core.features.backup import com.charleskorn.kaml.Yaml +import gay.pizza.foundation.shared.copyDefaultConfig import gay.pizza.foundation.core.FoundationCorePlugin -import gay.pizza.foundation.core.Util import gay.pizza.foundation.core.abstraction.Feature import gay.pizza.foundation.core.features.scheduler.cancel import gay.pizza.foundation.core.features.scheduler.cron @@ -46,7 +46,7 @@ class BackupFeature : Feature() { override fun module() = module { single { - val configPath = Util.copyDefaultConfig( + val configPath = copyDefaultConfig( plugin.slF4JLogger, plugin.pluginDataPath, "backup.yaml", diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/dev/DevUpdateServer.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/dev/DevUpdateServer.kt index 4427997..dc85948 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/dev/DevUpdateServer.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/dev/DevUpdateServer.kt @@ -3,8 +3,8 @@ package gay.pizza.foundation.core.features.dev import com.charleskorn.kaml.Yaml import com.sun.net.httpserver.HttpExchange import com.sun.net.httpserver.HttpServer +import gay.pizza.foundation.shared.copyDefaultConfig import gay.pizza.foundation.core.FoundationCorePlugin -import gay.pizza.foundation.core.Util import gay.pizza.foundation.core.features.update.UpdateService import kotlinx.serialization.json.Json import kotlinx.serialization.json.decodeFromStream @@ -23,7 +23,7 @@ class DevUpdateServer(val plugin: FoundationCorePlugin) { } fun enable() { - val configPath = Util.copyDefaultConfig( + val configPath = copyDefaultConfig( plugin.slF4JLogger, plugin.pluginDataPath, "devupdate.yaml" diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/gameplay/GameplayFeature.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/gameplay/GameplayFeature.kt index 5647654..6bcbecf 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/gameplay/GameplayFeature.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/gameplay/GameplayFeature.kt @@ -1,8 +1,8 @@ package gay.pizza.foundation.core.features.gameplay import com.charleskorn.kaml.Yaml +import gay.pizza.foundation.shared.copyDefaultConfig import gay.pizza.foundation.core.FoundationCorePlugin -import gay.pizza.foundation.core.Util import gay.pizza.foundation.core.abstraction.Feature import org.bukkit.Bukkit import org.bukkit.Material @@ -24,7 +24,7 @@ class GameplayFeature : Feature() { override fun module() = module { single { - val configPath = Util.copyDefaultConfig( + val configPath = copyDefaultConfig( plugin.slF4JLogger, plugin.pluginDataPath, "gameplay.yaml", diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/GooseCommand.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/GooseCommand.kt index 1592995..61b1c6e 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/GooseCommand.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/GooseCommand.kt @@ -1,6 +1,6 @@ package gay.pizza.foundation.core.features.player -import gay.pizza.foundation.common.chat +import gay.pizza.foundation.shared.chat import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/MegaTntCommand.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/MegaTntCommand.kt index 6bd03f1..affc4cb 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/MegaTntCommand.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/MegaTntCommand.kt @@ -1,6 +1,6 @@ package gay.pizza.foundation.core.features.player -import gay.pizza.foundation.common.spawn +import gay.pizza.foundation.shared.spawn import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/PlayerFeature.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/PlayerFeature.kt index 7a0db1d..061c1e2 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/PlayerFeature.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/player/PlayerFeature.kt @@ -4,8 +4,8 @@ import com.charleskorn.kaml.Yaml import com.google.common.cache.Cache import com.google.common.cache.CacheBuilder import com.google.common.cache.RemovalCause +import gay.pizza.foundation.shared.copyDefaultConfig import gay.pizza.foundation.core.FoundationCorePlugin -import gay.pizza.foundation.core.Util import gay.pizza.foundation.core.abstraction.Feature import net.kyori.adventure.text.Component import org.bukkit.GameMode @@ -53,7 +53,7 @@ class PlayerFeature : Feature() { override fun module() = org.koin.dsl.module { single { - val configPath = Util.copyDefaultConfig( + val configPath = copyDefaultConfig( plugin.slF4JLogger, plugin.pluginDataPath, "player.yaml", diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/stats/LeaderboardCommand.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/stats/LeaderboardCommand.kt index 45799a2..e1d092a 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/stats/LeaderboardCommand.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/stats/LeaderboardCommand.kt @@ -1,7 +1,7 @@ package gay.pizza.foundation.core.features.stats -import gay.pizza.foundation.common.SortOrder -import gay.pizza.foundation.common.allPlayerStatisticsOf +import gay.pizza.foundation.shared.SortOrder +import gay.pizza.foundation.shared.allPlayerStatisticsOf import org.bukkit.Statistic import org.bukkit.command.Command import org.bukkit.command.CommandExecutor diff --git a/foundation-heimdall/build.gradle.kts b/foundation-heimdall/build.gradle.kts index f4add7c..4198d44 100644 --- a/foundation-heimdall/build.gradle.kts +++ b/foundation-heimdall/build.gradle.kts @@ -3,6 +3,7 @@ plugins { } dependencies { - api(project(":common-heimdall")) - compileOnly(project(":foundation-core")) + implementation(project(":common-plugin")) + compileOnly(project(":foundation-shared")) + implementation(project(":common-heimdall")) } diff --git a/foundation-heimdall/src/main/kotlin/gay/pizza/foundation/heimdall/plugin/FoundationHeimdallPlugin.kt b/foundation-heimdall/src/main/kotlin/gay/pizza/foundation/heimdall/plugin/FoundationHeimdallPlugin.kt index 9beae1f..bdf7bb9 100644 --- a/foundation-heimdall/src/main/kotlin/gay/pizza/foundation/heimdall/plugin/FoundationHeimdallPlugin.kt +++ b/foundation-heimdall/src/main/kotlin/gay/pizza/foundation/heimdall/plugin/FoundationHeimdallPlugin.kt @@ -3,8 +3,9 @@ package gay.pizza.foundation.heimdall.plugin import com.charleskorn.kaml.Yaml import com.zaxxer.hikari.HikariConfig import com.zaxxer.hikari.HikariDataSource -import gay.pizza.foundation.common.PluginMainClass -import gay.pizza.foundation.core.Util +import gay.pizza.foundation.common.FoundationCoreLoader +import gay.pizza.foundation.shared.PluginMainClass +import gay.pizza.foundation.shared.copyDefaultConfig import gay.pizza.foundation.heimdall.plugin.buffer.BufferFlushThread import gay.pizza.foundation.heimdall.plugin.buffer.EventBuffer import gay.pizza.foundation.heimdall.plugin.event.* @@ -44,12 +45,10 @@ class FoundationHeimdallPlugin : JavaPlugin(), Listener { val exportChunksCommand = getCommand("export_all_chunks") ?: throw Exception("Failed to get export_all_chunks command") exportChunksCommand.setExecutor(ExportAllChunksCommand(this)) - val pluginDataPath = dataFolder.toPath() - pluginDataPath.toFile().mkdir() - - val configPath = Util.copyDefaultConfig( + val foundation = FoundationCoreLoader.get(server) + val configPath = copyDefaultConfig( slF4JLogger, - pluginDataPath, + foundation.pluginDataPath, "heimdall.yaml" ) config = Yaml.default.decodeFromStream(HeimdallConfig.serializer(), configPath.inputStream()) diff --git a/foundation-heimdall/src/main/resources/plugin.yml b/foundation-heimdall/src/main/resources/plugin.yml index 8e91eb5..9af5b0a 100644 --- a/foundation-heimdall/src/main/resources/plugin.yml +++ b/foundation-heimdall/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: Foundation-Heimdall version: '${version}' -main: gay.pizza.foundation.heimdall.plugin.HeimdallPlugin +main: gay.pizza.foundation.heimdall.plugin.FoundationHeimdallPlugin api-version: 1.18 prefix: Foundation-Heimdall load: STARTUP diff --git a/foundation-shared/build.gradle.kts b/foundation-shared/build.gradle.kts new file mode 100644 index 0000000..36dc4fa --- /dev/null +++ b/foundation-shared/build.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("gay.pizza.foundation.concrete-library") +} diff --git a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/AdvancementTitleCache.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/AdvancementTitleCache.kt similarity index 98% rename from common-plugin/src/main/kotlin/gay/pizza/foundation/common/AdvancementTitleCache.kt rename to foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/AdvancementTitleCache.kt index 3e660f1..842896f 100644 --- a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/AdvancementTitleCache.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/AdvancementTitleCache.kt @@ -1,4 +1,4 @@ -package gay.pizza.foundation.common +package gay.pizza.foundation.shared import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer diff --git a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/ChatExtensions.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ChatExtensions.kt similarity index 78% rename from common-plugin/src/main/kotlin/gay/pizza/foundation/common/ChatExtensions.kt rename to foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ChatExtensions.kt index 0774869..e936552 100644 --- a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/ChatExtensions.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ChatExtensions.kt @@ -1,4 +1,4 @@ -package gay.pizza.foundation.common +package gay.pizza.foundation.shared import org.bukkit.entity.Player diff --git a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/CollectionExtensions.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/CollectionExtensions.kt similarity index 85% rename from common-plugin/src/main/kotlin/gay/pizza/foundation/common/CollectionExtensions.kt rename to foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/CollectionExtensions.kt index 4c2c709..0eae95e 100644 --- a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/CollectionExtensions.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/CollectionExtensions.kt @@ -1,4 +1,4 @@ -package gay.pizza.foundation.common +package gay.pizza.foundation.shared fun > Collection.sortedBy(order: SortOrder, selector: (T) -> R?): List = if (order == SortOrder.Ascending) { diff --git a/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/IFoundationCore.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/IFoundationCore.kt new file mode 100644 index 0000000..bb0695c --- /dev/null +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/IFoundationCore.kt @@ -0,0 +1,7 @@ +package gay.pizza.foundation.shared + +import java.nio.file.Path + +interface IFoundationCore { + val pluginDataPath: Path +} diff --git a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/Platform.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/Platform.kt similarity index 81% rename from common-plugin/src/main/kotlin/gay/pizza/foundation/common/Platform.kt rename to foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/Platform.kt index 30f0982..1e95b9f 100644 --- a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/Platform.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/Platform.kt @@ -1,4 +1,4 @@ -package gay.pizza.foundation.common +package gay.pizza.foundation.shared object Platform { private val os: String? = System.getProperty("os.name") diff --git a/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/PluginMainClass.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/PluginMainClass.kt new file mode 100644 index 0000000..3889eb7 --- /dev/null +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/PluginMainClass.kt @@ -0,0 +1,3 @@ +package gay.pizza.foundation.shared + +annotation class PluginMainClass diff --git a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/ServerExtensions.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ServerExtensions.kt similarity index 95% rename from common-plugin/src/main/kotlin/gay/pizza/foundation/common/ServerExtensions.kt rename to foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ServerExtensions.kt index 7bb54ec..c32190b 100644 --- a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/ServerExtensions.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ServerExtensions.kt @@ -1,4 +1,4 @@ -package gay.pizza.foundation.common +package gay.pizza.foundation.shared import org.bukkit.Material import org.bukkit.OfflinePlayer diff --git a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/SortOrder.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/SortOrder.kt similarity index 59% rename from common-plugin/src/main/kotlin/gay/pizza/foundation/common/SortOrder.kt rename to foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/SortOrder.kt index e08d84f..4d2cbd6 100644 --- a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/SortOrder.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/SortOrder.kt @@ -1,4 +1,4 @@ -package gay.pizza.foundation.common +package gay.pizza.foundation.shared enum class SortOrder { Ascending, diff --git a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/SpawnExtensions.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/SpawnExtensions.kt similarity index 91% rename from common-plugin/src/main/kotlin/gay/pizza/foundation/common/SpawnExtensions.kt rename to foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/SpawnExtensions.kt index c0f334d..79d04cf 100644 --- a/common-plugin/src/main/kotlin/gay/pizza/foundation/common/SpawnExtensions.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/SpawnExtensions.kt @@ -1,4 +1,4 @@ -package gay.pizza.foundation.common +package gay.pizza.foundation.shared import org.bukkit.Location import org.bukkit.World diff --git a/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/copyDefaultConfig.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/copyDefaultConfig.kt new file mode 100644 index 0000000..79aecfe --- /dev/null +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/copyDefaultConfig.kt @@ -0,0 +1,39 @@ +package gay.pizza.foundation.shared + +import org.slf4j.Logger +import java.nio.file.Path + +/** + * Copy the default configuration from the resource [resourceName] into the directory [targetPath]. + * @param targetPath The output directory as a path, it must exist before calling this. + * @param resourceName Path to resource, it should be in the root of the `resources` directory, + * without the leading slash. + */ +inline fun copyDefaultConfig(log: Logger, targetPath: Path, resourceName: String): Path { + if (resourceName.startsWith("/")) { + throw IllegalArgumentException("resourceName starts with slash") + } + + if (!targetPath.toFile().exists()) { + throw Exception("Configuration output path does not exist!") + } + val outPath = targetPath.resolve(resourceName) + val outFile = outPath.toFile() + if (outFile.exists()) { + log.debug("Configuration file already exists.") + return outPath + } + + val resourceStream = T::class.java.getResourceAsStream("/$resourceName") + ?: throw Exception("Configuration resource does not exist!") + val outputStream = outFile.outputStream() + + resourceStream.use { + outputStream.use { + log.info("Copied default configuration to $outPath") + resourceStream.copyTo(outputStream) + } + } + + return outPath +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 2f4a5d0..87d27a8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -12,6 +12,7 @@ include( ":common-plugin", ":common-heimdall", ":foundation-core", + ":foundation-shared", ":foundation-bifrost", ":foundation-chaos", ":foundation-heimdall", diff --git a/tool-gjallarhorn/build.gradle.kts b/tool-gjallarhorn/build.gradle.kts index 5072381..2b97a48 100644 --- a/tool-gjallarhorn/build.gradle.kts +++ b/tool-gjallarhorn/build.gradle.kts @@ -1,10 +1,10 @@ plugins { - id("gay.pizza.foundation.concrete-library") + id("gay.pizza.foundation.concrete-base") id("com.github.johnrengelman.shadow") } dependencies { - api(project(":common-heimdall")) + implementation(project(":common-heimdall")) implementation("com.github.ajalt.clikt:clikt:3.5.1") implementation("org.slf4j:slf4j-simple:2.0.6")