mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 13:31:32 +00:00
Reform dependency structure.
This commit is contained in:
@ -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"))
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 <reified T> 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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<FoundationCorePlugin>(
|
||||
val configPath = copyDefaultConfig<FoundationCorePlugin>(
|
||||
plugin.slF4JLogger,
|
||||
plugin.pluginDataPath,
|
||||
"backup.yaml",
|
||||
|
@ -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<FoundationCorePlugin>(
|
||||
val configPath = copyDefaultConfig<FoundationCorePlugin>(
|
||||
plugin.slF4JLogger,
|
||||
plugin.pluginDataPath,
|
||||
"devupdate.yaml"
|
||||
|
@ -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<FoundationCorePlugin>(
|
||||
val configPath = copyDefaultConfig<FoundationCorePlugin>(
|
||||
plugin.slF4JLogger,
|
||||
plugin.pluginDataPath,
|
||||
"gameplay.yaml",
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<FoundationCorePlugin>(
|
||||
val configPath = copyDefaultConfig<FoundationCorePlugin>(
|
||||
plugin.slF4JLogger,
|
||||
plugin.pluginDataPath,
|
||||
"player.yaml",
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user