mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 13:31:32 +00:00
Core: Backup cleanup and fixes for Windows.
This commit is contained in:
@ -8,6 +8,13 @@ class FoundationGradlePlugin : Plugin<Project> {
|
|||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
project.extensions.create<FoundationExtension>("foundation")
|
project.extensions.create<FoundationExtension>("foundation")
|
||||||
val setupPaperServer = project.tasks.create<SetupPaperServer>("setupPaperServer")
|
val setupPaperServer = project.tasks.create<SetupPaperServer>("setupPaperServer")
|
||||||
|
project.afterEvaluate { ->
|
||||||
|
setupPaperServer.dependsOn(*project.subprojects
|
||||||
|
.filter { it.name.startsWith("foundation-") }
|
||||||
|
.map { it.tasks.getByName("build") }
|
||||||
|
.toTypedArray()
|
||||||
|
)
|
||||||
|
}
|
||||||
val runPaperServer = project.tasks.create<RunPaperServer>("runPaperServer")
|
val runPaperServer = project.tasks.create<RunPaperServer>("runPaperServer")
|
||||||
runPaperServer.dependsOn(setupPaperServer)
|
runPaperServer.dependsOn(setupPaperServer)
|
||||||
}
|
}
|
||||||
|
@ -57,4 +57,9 @@ object Util {
|
|||||||
|
|
||||||
return outPath
|
return outPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isPlatformWindows(): Boolean {
|
||||||
|
val os = System.getProperty("os.name")
|
||||||
|
return os != null && os.lowercase().startsWith("windows")
|
||||||
|
}
|
||||||
}
|
}
|
@ -42,25 +42,28 @@ class BackupCommand(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
val server = sender.server
|
||||||
val server = sender.server
|
server.scheduler.runTaskAsynchronously(plugin) { ->
|
||||||
server.scheduler.runTaskAsynchronously(plugin, Runnable {
|
runBackup(server, sender)
|
||||||
runBackup(server)
|
|
||||||
})
|
|
||||||
} catch (e: Exception) {
|
|
||||||
sender.sendMessage(String.format("Failed to backup: %s", e.message))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Pull backup creation code into a separate service.
|
// TODO: Pull backup creation code into a separate service.
|
||||||
private fun runBackup(server: Server) = try {
|
private fun runBackup(server: Server, sender: CommandSender? = null) = try {
|
||||||
RUNNING.set(true)
|
RUNNING.set(true)
|
||||||
|
|
||||||
server.sendMessage(Util.formatSystemMessage("Backup started."))
|
server.scheduler.runTask(plugin) { ->
|
||||||
|
server.sendMessage(Util.formatSystemMessage("Backup started."))
|
||||||
|
}
|
||||||
|
|
||||||
val backupFileName = String.format("backup-%s.zip", Instant.now().toString())
|
val backupTime = Instant.now()
|
||||||
|
val backupIdentifier = if (Util.isPlatformWindows()) {
|
||||||
|
backupTime.toEpochMilli().toString()
|
||||||
|
} else {
|
||||||
|
backupTime.toString()
|
||||||
|
}
|
||||||
|
val backupFileName = String.format("backup-%s.zip", backupIdentifier)
|
||||||
val backupPath = backupsPath.resolve(backupFileName)
|
val backupPath = backupsPath.resolve(backupFileName)
|
||||||
val backupFile = backupPath.toFile()
|
val backupFile = backupPath.toFile()
|
||||||
|
|
||||||
@ -82,9 +85,18 @@ class BackupCommand(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Unit
|
Unit
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (sender != null) {
|
||||||
|
server.scheduler.runTask(plugin) { ->
|
||||||
|
sender.sendMessage(String.format("Failed to backup: %s", e.message))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plugin.slF4JLogger.warn("Failed to backup.", e)
|
||||||
} finally {
|
} finally {
|
||||||
RUNNING.set(false)
|
RUNNING.set(false)
|
||||||
server.sendMessage(Util.formatSystemMessage("Backup finished."))
|
server.scheduler.runTask(plugin) { ->
|
||||||
|
server.sendMessage(Util.formatSystemMessage("Backup finished."))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun backupPlugins(server: Server, zipStream: ZipOutputStream) {
|
private fun backupPlugins(server: Server, zipStream: ZipOutputStream) {
|
||||||
@ -92,7 +104,7 @@ class BackupCommand(
|
|||||||
addDirectoryToZip(zipStream, server.pluginsFolder.toPath())
|
addDirectoryToZip(zipStream, server.pluginsFolder.toPath())
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
// TODO: Add error handling.
|
// TODO: Add error handling.
|
||||||
e.printStackTrace()
|
plugin.slF4JLogger.warn("Failed to backup plugins.", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user