mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 11:39:39 +00:00 
			
		
		
		
	Minor refactoring and cleanup.
This commit is contained in:
		@ -35,9 +35,11 @@ subprojects {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					val paperServerVersion: String = project.properties["paperServerVersion"]?.toString() ?: "1.18"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
concrete {
 | 
					concrete {
 | 
				
			||||||
  minecraftServerPath.set("server")
 | 
					  minecraftServerPath.set("server")
 | 
				
			||||||
  paperServerVersionGroup.set("1.18")
 | 
					  paperServerVersionGroup.set(paperServerVersion)
 | 
				
			||||||
  paperApiVersion.set("1.18.2-R0.1-SNAPSHOT")
 | 
					  paperApiVersion.set("1.18.2-R0.1-SNAPSHOT")
 | 
				
			||||||
  acceptServerEula.set(true)
 | 
					  acceptServerEula.set(true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,5 @@
 | 
				
			|||||||
package gay.pizza.foundation.core
 | 
					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.abstraction.FoundationPlugin
 | 
				
			||||||
import gay.pizza.foundation.core.features.backup.BackupFeature
 | 
					import gay.pizza.foundation.core.features.backup.BackupFeature
 | 
				
			||||||
import gay.pizza.foundation.core.features.dev.DevFeature
 | 
					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.stats.StatsFeature
 | 
				
			||||||
import gay.pizza.foundation.core.features.update.UpdateFeature
 | 
					import gay.pizza.foundation.core.features.update.UpdateFeature
 | 
				
			||||||
import gay.pizza.foundation.core.features.world.WorldFeature
 | 
					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 gay.pizza.foundation.shared.PluginPersistence
 | 
				
			||||||
import org.koin.dsl.module
 | 
					import org.koin.dsl.module
 | 
				
			||||||
import java.nio.file.Path
 | 
					import java.nio.file.Path
 | 
				
			||||||
 | 
				
			|||||||
@ -2,7 +2,7 @@ package gay.pizza.foundation.core.features.backup
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import gay.pizza.foundation.shared.Platform
 | 
					import gay.pizza.foundation.shared.Platform
 | 
				
			||||||
import gay.pizza.foundation.core.FoundationCorePlugin
 | 
					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.Component
 | 
				
			||||||
import net.kyori.adventure.text.format.TextColor
 | 
					import net.kyori.adventure.text.format.TextColor
 | 
				
			||||||
import org.bukkit.Server
 | 
					import org.bukkit.Server
 | 
				
			||||||
@ -27,14 +27,14 @@ import java.util.zip.ZipOutputStream
 | 
				
			|||||||
// TODO: Clean up dependency injection.
 | 
					// TODO: Clean up dependency injection.
 | 
				
			||||||
class BackupCommand(
 | 
					class BackupCommand(
 | 
				
			||||||
  private val plugin: FoundationCorePlugin,
 | 
					  private val plugin: FoundationCorePlugin,
 | 
				
			||||||
  private val backupsPath: Path,
 | 
					  private val backupFilePath: Path,
 | 
				
			||||||
  private val config: BackupConfig,
 | 
					  private val config: BackupConfig,
 | 
				
			||||||
  private val s3Client: S3Client,
 | 
					  private val s3Client: S3Client,
 | 
				
			||||||
) : CommandExecutor {
 | 
					) : CommandExecutor {
 | 
				
			||||||
  override fun onCommand(
 | 
					  override fun onCommand(
 | 
				
			||||||
    sender: CommandSender, command: Command, label: String, args: Array<String>
 | 
					    sender: CommandSender, command: Command, label: String, args: Array<String>
 | 
				
			||||||
  ): Boolean {
 | 
					  ): Boolean {
 | 
				
			||||||
    if (RUNNING.get()) {
 | 
					    if (running.get()) {
 | 
				
			||||||
      sender.sendMessage(
 | 
					      sender.sendMessage(
 | 
				
			||||||
        Component
 | 
					        Component
 | 
				
			||||||
          .text("Backup is already running.")
 | 
					          .text("Backup is already running.")
 | 
				
			||||||
@ -52,10 +52,10 @@ class BackupCommand(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // TODO: Pull backup creation code into a separate service.
 | 
					  // TODO: Pull backup creation code into a separate service.
 | 
				
			||||||
  private fun runBackup(server: Server, sender: CommandSender? = null) = try {
 | 
					  private fun runBackup(server: Server, sender: CommandSender? = null) = try {
 | 
				
			||||||
    RUNNING.set(true)
 | 
					    running.set(true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    server.scheduler.runTask(plugin) { ->
 | 
					    server.scheduler.runTask(plugin) { ->
 | 
				
			||||||
      server.sendMessage(Util.formatSystemMessage("Backup started."))
 | 
					      server.sendMessage(MessageUtil.formatSystemMessage("Backup started."))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    val backupTime = Instant.now()
 | 
					    val backupTime = Instant.now()
 | 
				
			||||||
@ -65,7 +65,7 @@ class BackupCommand(
 | 
				
			|||||||
      backupTime.toString()
 | 
					      backupTime.toString()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    val backupFileName = String.format("backup-%s.zip", backupIdentifier)
 | 
					    val backupFileName = String.format("backup-%s.zip", backupIdentifier)
 | 
				
			||||||
    val backupPath = backupsPath.resolve(backupFileName)
 | 
					    val backupPath = backupFilePath.resolve(backupFileName)
 | 
				
			||||||
    val backupFile = backupPath.toFile()
 | 
					    val backupFile = backupPath.toFile()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    FileOutputStream(backupFile).use { zipFileStream ->
 | 
					    FileOutputStream(backupFile).use { zipFileStream ->
 | 
				
			||||||
@ -94,9 +94,9 @@ class BackupCommand(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    plugin.slF4JLogger.warn("Failed to backup.", e)
 | 
					    plugin.slF4JLogger.warn("Failed to backup.", e)
 | 
				
			||||||
  } finally {
 | 
					  } finally {
 | 
				
			||||||
    RUNNING.set(false)
 | 
					    running.set(false)
 | 
				
			||||||
    server.scheduler.runTask(plugin) { ->
 | 
					    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())) } }
 | 
					      .filter { path -> !matchers.any { it.matches(Paths.get(path.normalize().toString())) } }
 | 
				
			||||||
      .toList()
 | 
					      .toList()
 | 
				
			||||||
    val buffer = ByteArray(16 * 1024)
 | 
					    val buffer = ByteArray(16 * 1024)
 | 
				
			||||||
    val backupsPath = backupsPath.toRealPath()
 | 
					    val backupsPath = backupFilePath.toRealPath()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (path in paths) {
 | 
					    for (path in paths) {
 | 
				
			||||||
      val realPath = path.toRealPath()
 | 
					      val realPath = path.toRealPath()
 | 
				
			||||||
@ -163,6 +163,6 @@ class BackupCommand(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  companion object {
 | 
					  companion object {
 | 
				
			||||||
    private val RUNNING = AtomicBoolean()
 | 
					    private val running = AtomicBoolean()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ class BackupFeature : Feature() {
 | 
				
			|||||||
    registerCommandExecutor("fbackup", BackupCommand(plugin, backupPath, config, s3Client))
 | 
					    registerCommandExecutor("fbackup", BackupCommand(plugin, backupPath, config, s3Client))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (config.schedule.cron.isNotEmpty()) {
 | 
					    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}"
 | 
					      val expr = "0 ${config.schedule.cron}"
 | 
				
			||||||
      scheduleId = scheduler.cron(expr) {
 | 
					      scheduleId = scheduler.cron(expr) {
 | 
				
			||||||
        plugin.server.scheduler.runTask(plugin) { ->
 | 
					        plugin.server.scheduler.runTask(plugin) { ->
 | 
				
			||||||
 | 
				
			|||||||
@ -11,6 +11,7 @@ import org.bukkit.event.EventHandler
 | 
				
			|||||||
import org.koin.core.component.inject
 | 
					import org.koin.core.component.inject
 | 
				
			||||||
import java.time.Instant
 | 
					import java.time.Instant
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Suppress("IdentifierGrammar")
 | 
				
			||||||
class StatsFeature : Feature() {
 | 
					class StatsFeature : Feature() {
 | 
				
			||||||
  internal val persistence = inject<PluginPersistence>()
 | 
					  internal val persistence = inject<PluginPersistence>()
 | 
				
			||||||
  private lateinit var chatLogStore: PersistentStore
 | 
					  private lateinit var chatLogStore: PersistentStore
 | 
				
			||||||
 | 
				
			|||||||
@ -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.Component
 | 
				
			||||||
import net.kyori.adventure.text.format.TextColor
 | 
					import net.kyori.adventure.text.format.TextColor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
object Util {
 | 
					object MessageUtil {
 | 
				
			||||||
  private val leftBracket: Component = Component.text('[')
 | 
					  private val leftBracket: Component = Component.text('[')
 | 
				
			||||||
  private val rightBracket: Component = Component.text(']')
 | 
					  private val rightBracket: Component = Component.text(']')
 | 
				
			||||||
  private val whitespace: Component = Component.text(' ')
 | 
					  private val whitespace: Component = Component.text(' ')
 | 
				
			||||||
@ -9,7 +9,7 @@ import org.bukkit.entity.EntityType
 | 
				
			|||||||
val Server.allPlayers: List<OfflinePlayer>
 | 
					val Server.allPlayers: List<OfflinePlayer>
 | 
				
			||||||
  get() = listOf(onlinePlayers, offlinePlayers.filter { !isPlayerOnline(it) }.toList()).flatten()
 | 
					  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 }
 | 
					  onlinePlayers.any { onlinePlayer -> onlinePlayer.name == player.name }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fun Server.allPlayerStatisticsOf(
 | 
					fun Server.allPlayerStatisticsOf(
 | 
				
			||||||
@ -17,7 +17,7 @@ fun Server.allPlayerStatisticsOf(
 | 
				
			|||||||
  material: Material? = null,
 | 
					  material: Material? = null,
 | 
				
			||||||
  entityType: EntityType? = null,
 | 
					  entityType: EntityType? = null,
 | 
				
			||||||
  order: SortOrder = SortOrder.Ascending
 | 
					  order: SortOrder = SortOrder.Ascending
 | 
				
			||||||
) = allPlayers.map { player ->
 | 
					): List<Pair<OfflinePlayer, Int>> = allPlayers.map { player ->
 | 
				
			||||||
  player to if (material != null) {
 | 
					  player to if (material != null) {
 | 
				
			||||||
    player.getStatistic(statistic, material)
 | 
					    player.getStatistic(statistic, material)
 | 
				
			||||||
  } else if (entityType != null) {
 | 
					  } else if (entityType != null) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,4 @@
 | 
				
			|||||||
package gay.pizza.foundation.core
 | 
					package gay.pizza.foundation.shared
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import net.kyori.adventure.text.format.TextColor
 | 
					import net.kyori.adventure.text.format.TextColor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Reference in New Issue
	
	Block a user