diff --git a/build.gradle.kts b/build.gradle.kts index 596c735..0b0dd50 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,9 +35,11 @@ subprojects { } } +val paperServerVersion: String = project.properties["paperServerVersion"]?.toString() ?: "1.18" + concrete { minecraftServerPath.set("server") - paperServerVersionGroup.set("1.18") + paperServerVersionGroup.set(paperServerVersion) paperApiVersion.set("1.18.2-R0.1-SNAPSHOT") acceptServerEula.set(true) } 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 2da2c1e..a71fdf7 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,7 +1,5 @@ package gay.pizza.foundation.core -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 @@ -12,7 +10,8 @@ import gay.pizza.foundation.core.features.scheduler.SchedulerFeature import gay.pizza.foundation.core.features.stats.StatsFeature import gay.pizza.foundation.core.features.update.UpdateFeature import gay.pizza.foundation.core.features.world.WorldFeature -import gay.pizza.foundation.shared.PersistentStore +import gay.pizza.foundation.shared.IFoundationCore +import gay.pizza.foundation.shared.PluginMainClass import gay.pizza.foundation.shared.PluginPersistence import org.koin.dsl.module import java.nio.file.Path 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 b2edec4..54a247c 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 @@ -2,7 +2,7 @@ package gay.pizza.foundation.core.features.backup import gay.pizza.foundation.shared.Platform import gay.pizza.foundation.core.FoundationCorePlugin -import gay.pizza.foundation.core.Util +import gay.pizza.foundation.shared.MessageUtil import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.TextColor import org.bukkit.Server @@ -27,14 +27,14 @@ import java.util.zip.ZipOutputStream // TODO: Clean up dependency injection. class BackupCommand( private val plugin: FoundationCorePlugin, - private val backupsPath: Path, + private val backupFilePath: Path, private val config: BackupConfig, private val s3Client: S3Client, ) : CommandExecutor { override fun onCommand( sender: CommandSender, command: Command, label: String, args: Array ): Boolean { - if (RUNNING.get()) { + if (running.get()) { sender.sendMessage( Component .text("Backup is already running.") @@ -52,10 +52,10 @@ class BackupCommand( // TODO: Pull backup creation code into a separate service. private fun runBackup(server: Server, sender: CommandSender? = null) = try { - RUNNING.set(true) + running.set(true) server.scheduler.runTask(plugin) { -> - server.sendMessage(Util.formatSystemMessage("Backup started.")) + server.sendMessage(MessageUtil.formatSystemMessage("Backup started.")) } val backupTime = Instant.now() @@ -65,7 +65,7 @@ class BackupCommand( backupTime.toString() } val backupFileName = String.format("backup-%s.zip", backupIdentifier) - val backupPath = backupsPath.resolve(backupFileName) + val backupPath = backupFilePath.resolve(backupFileName) val backupFile = backupPath.toFile() FileOutputStream(backupFile).use { zipFileStream -> @@ -94,9 +94,9 @@ class BackupCommand( } plugin.slF4JLogger.warn("Failed to backup.", e) } finally { - RUNNING.set(false) + running.set(false) server.scheduler.runTask(plugin) { -> - server.sendMessage(Util.formatSystemMessage("Backup finished.")) + server.sendMessage(MessageUtil.formatSystemMessage("Backup finished.")) } } @@ -140,7 +140,7 @@ class BackupCommand( .filter { path -> !matchers.any { it.matches(Paths.get(path.normalize().toString())) } } .toList() val buffer = ByteArray(16 * 1024) - val backupsPath = backupsPath.toRealPath() + val backupsPath = backupFilePath.toRealPath() for (path in paths) { val realPath = path.toRealPath() @@ -163,6 +163,6 @@ class BackupCommand( } companion object { - private val RUNNING = AtomicBoolean() + private val running = AtomicBoolean() } } 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 677df3c..5867686 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 @@ -28,7 +28,7 @@ class BackupFeature : Feature() { registerCommandExecutor("fbackup", BackupCommand(plugin, backupPath, config, s3Client)) if (config.schedule.cron.isNotEmpty()) { - // Assume user never wants to modify second. I'm not sure why this is enforced in Quartz. + // Assume the user never wants to modify the second. I'm not sure why this is enforced in Quartz. val expr = "0 ${config.schedule.cron}" scheduleId = scheduler.cron(expr) { plugin.server.scheduler.runTask(plugin) { -> diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/stats/StatsFeature.kt b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/stats/StatsFeature.kt index 8a7e32f..6e2e23c 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/stats/StatsFeature.kt +++ b/foundation-core/src/main/kotlin/gay/pizza/foundation/core/features/stats/StatsFeature.kt @@ -11,6 +11,7 @@ import org.bukkit.event.EventHandler import org.koin.core.component.inject import java.time.Instant +@Suppress("IdentifierGrammar") class StatsFeature : Feature() { internal val persistence = inject() private lateinit var chatLogStore: PersistentStore diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/Util.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/MessageUtil.kt similarity index 92% rename from foundation-core/src/main/kotlin/gay/pizza/foundation/core/Util.kt rename to foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/MessageUtil.kt index 33869bc..1349d70 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/Util.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/MessageUtil.kt @@ -1,9 +1,9 @@ -package gay.pizza.foundation.core +package gay.pizza.foundation.shared import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.TextColor -object Util { +object MessageUtil { private val leftBracket: Component = Component.text('[') private val rightBracket: Component = Component.text(']') private val whitespace: Component = Component.text(' ') diff --git a/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ServerExtensions.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ServerExtensions.kt index c32190b..b6c7f83 100644 --- a/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ServerExtensions.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/ServerExtensions.kt @@ -9,7 +9,7 @@ import org.bukkit.entity.EntityType val Server.allPlayers: List get() = listOf(onlinePlayers, offlinePlayers.filter { !isPlayerOnline(it) }.toList()).flatten() -fun Server.isPlayerOnline(player: OfflinePlayer) = +fun Server.isPlayerOnline(player: OfflinePlayer): Boolean = onlinePlayers.any { onlinePlayer -> onlinePlayer.name == player.name } fun Server.allPlayerStatisticsOf( @@ -17,7 +17,7 @@ fun Server.allPlayerStatisticsOf( material: Material? = null, entityType: EntityType? = null, order: SortOrder = SortOrder.Ascending -) = allPlayers.map { player -> +): List> = allPlayers.map { player -> player to if (material != null) { player.getStatistic(statistic, material) } else if (entityType != null) { diff --git a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/TextColors.kt b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/TextColors.kt similarity index 78% rename from foundation-core/src/main/kotlin/gay/pizza/foundation/core/TextColors.kt rename to foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/TextColors.kt index 19439d5..1a22ac7 100644 --- a/foundation-core/src/main/kotlin/gay/pizza/foundation/core/TextColors.kt +++ b/foundation-shared/src/main/kotlin/gay/pizza/foundation/shared/TextColors.kt @@ -1,4 +1,4 @@ -package gay.pizza.foundation.core +package gay.pizza.foundation.shared import net.kyori.adventure.text.format.TextColor