mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 13:31:32 +00:00
Minor refactoring and cleanup.
This commit is contained in:
@ -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
|
||||
|
@ -1,7 +0,0 @@
|
||||
package gay.pizza.foundation.core
|
||||
|
||||
import net.kyori.adventure.text.format.TextColor
|
||||
|
||||
object TextColors {
|
||||
val AmaranthPink = TextColor.fromHexString("#F7A8B8")!!
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package gay.pizza.foundation.core
|
||||
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.format.TextColor
|
||||
|
||||
object Util {
|
||||
private val leftBracket: Component = Component.text('[')
|
||||
private val rightBracket: Component = Component.text(']')
|
||||
private val whitespace: Component = Component.text(' ')
|
||||
private val foundationName: Component = Component.text("Foundation")
|
||||
|
||||
fun formatSystemMessage(message: String): Component {
|
||||
return formatSystemMessage(TextColors.AmaranthPink, message)
|
||||
}
|
||||
|
||||
fun formatSystemMessage(prefixColor: TextColor, message: String): Component {
|
||||
return leftBracket
|
||||
.append(foundationName.color(prefixColor))
|
||||
.append(rightBracket)
|
||||
.append(whitespace)
|
||||
.append(Component.text(message))
|
||||
}
|
||||
}
|
@ -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<String>
|
||||
): 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()
|
||||
}
|
||||
}
|
||||
|
@ -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) { ->
|
||||
|
@ -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<PluginPersistence>()
|
||||
private lateinit var chatLogStore: PersistentStore
|
||||
|
Reference in New Issue
Block a user