mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 05:30:55 +00:00
Reform dependency structure.
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
plugins {
|
||||
id("gay.pizza.foundation.concrete-library")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":foundation-shared"))
|
||||
}
|
||||
|
@ -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!")
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
package gay.pizza.foundation.common
|
||||
|
||||
annotation class PluginMainClass
|
@ -7,5 +7,6 @@ dependencies {
|
||||
exclude(module = "opus-java")
|
||||
}
|
||||
|
||||
compileOnly(project(":foundation-core"))
|
||||
implementation(project(":common-plugin"))
|
||||
compileOnly(project(":foundation-shared"))
|
||||
}
|
||||
|
@ -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<FoundationBifrostPlugin>(
|
||||
val foundation = FoundationCoreLoader.get(server)
|
||||
val configPath = copyDefaultConfig<FoundationBifrostPlugin>(
|
||||
slF4JLogger,
|
||||
foundation.pluginDataPath,
|
||||
"bifrost.yaml"
|
||||
|
@ -4,5 +4,5 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":common-plugin"))
|
||||
compileOnly(project(":foundation-core"))
|
||||
compileOnly(project(":foundation-shared"))
|
||||
}
|
||||
|
@ -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<FoundationChaosPlugin>(
|
||||
val foundation = FoundationCoreLoader.get(server)
|
||||
val configPath = copyDefaultConfig<FoundationChaosPlugin>(
|
||||
slF4JLogger,
|
||||
foundation.pluginDataPath,
|
||||
"chaos.yaml"
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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"))
|
||||
}
|
||||
|
@ -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<FoundationHeimdallPlugin>(
|
||||
val foundation = FoundationCoreLoader.get(server)
|
||||
val configPath = copyDefaultConfig<FoundationHeimdallPlugin>(
|
||||
slF4JLogger,
|
||||
pluginDataPath,
|
||||
foundation.pluginDataPath,
|
||||
"heimdall.yaml"
|
||||
)
|
||||
config = Yaml.default.decodeFromStream(HeimdallConfig.serializer(), configPath.inputStream())
|
||||
|
@ -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
|
||||
|
3
foundation-shared/build.gradle.kts
Normal file
3
foundation-shared/build.gradle.kts
Normal file
@ -0,0 +1,3 @@
|
||||
plugins {
|
||||
id("gay.pizza.foundation.concrete-library")
|
||||
}
|
@ -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
|
@ -1,4 +1,4 @@
|
||||
package gay.pizza.foundation.common
|
||||
package gay.pizza.foundation.shared
|
||||
|
||||
import org.bukkit.entity.Player
|
||||
|
@ -1,4 +1,4 @@
|
||||
package gay.pizza.foundation.common
|
||||
package gay.pizza.foundation.shared
|
||||
|
||||
fun <T, R : Comparable<R>> Collection<T>.sortedBy(order: SortOrder, selector: (T) -> R?): List<T> =
|
||||
if (order == SortOrder.Ascending) {
|
@ -0,0 +1,7 @@
|
||||
package gay.pizza.foundation.shared
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
interface IFoundationCore {
|
||||
val pluginDataPath: Path
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package gay.pizza.foundation.common
|
||||
package gay.pizza.foundation.shared
|
||||
|
||||
object Platform {
|
||||
private val os: String? = System.getProperty("os.name")
|
@ -0,0 +1,3 @@
|
||||
package gay.pizza.foundation.shared
|
||||
|
||||
annotation class PluginMainClass
|
@ -1,4 +1,4 @@
|
||||
package gay.pizza.foundation.common
|
||||
package gay.pizza.foundation.shared
|
||||
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.OfflinePlayer
|
@ -1,4 +1,4 @@
|
||||
package gay.pizza.foundation.common
|
||||
package gay.pizza.foundation.shared
|
||||
|
||||
enum class SortOrder {
|
||||
Ascending,
|
@ -1,4 +1,4 @@
|
||||
package gay.pizza.foundation.common
|
||||
package gay.pizza.foundation.shared
|
||||
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.World
|
@ -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 <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
|
||||
}
|
@ -12,6 +12,7 @@ include(
|
||||
":common-plugin",
|
||||
":common-heimdall",
|
||||
":foundation-core",
|
||||
":foundation-shared",
|
||||
":foundation-bifrost",
|
||||
":foundation-chaos",
|
||||
":foundation-heimdall",
|
||||
|
@ -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")
|
||||
|
Reference in New Issue
Block a user