Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Uni0305 committed Oct 24, 2024
2 parents 638f07b + cbf4263 commit bd4d85f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "me.uni0305"
version = "0.1.1"
version = "0.1.2"

repositories {
mavenCentral()
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/me/uni0305/oraxen/OraxenExtrasCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class OraxenExtrasCommand(private val plugin: JavaPlugin) : BukkitCommand("oraxe

when (args[1].lowercase()) {
"reload" -> {
OraxenExtrasPlugin.externalPackImportService.importPacks()
OraxenPack.reloadPack()
sender.sendRichMessage("<gold>Reloaded Oraxen pack.")
sender.sendRichMessage("<gold>Reloading Oraxen pack...")
OraxenExtrasPlugin.externalPackImportService.importPacks().thenAcceptAsync {
OraxenPack.reloadPack()
sender.sendRichMessage("<gold>Reloaded Oraxen pack.")
}
return true
}
"upload" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ExternalPackImportConfig(private val config: FileConfiguration) {
fun isEnabled() = config.getBoolean("$SECTION_PATH.enabled", false)

fun getPacks(): List<File> = config.getStringList("$SECTION_PATH.packs")
.map { File(Bukkit.getServer().pluginsFolder, it).resolve("assets") }
.filter { it.exists() }
.map { File(Bukkit.getServer().pluginsFolder, it) }
.filter { it.isDirectory && it.exists() }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package me.uni0305.oraxen.service

import io.th0rgal.oraxen.api.OraxenPack
import io.th0rgal.oraxen.OraxenPlugin
import me.uni0305.oraxen.config.ExternalPackImportConfig
import org.bukkit.plugin.java.JavaPlugin
import org.slf4j.LoggerFactory
import java.util.concurrent.CompletableFuture

class ExternalPackImportService(private val plugin: JavaPlugin) {
private val logger = LoggerFactory.getLogger(this.javaClass)
Expand All @@ -12,21 +13,30 @@ class ExternalPackImportService(private val plugin: JavaPlugin) {

fun getPacks() = if (config.isEnabled()) config.getPacks() else emptyList()

fun importPacks() {
fun importPacks(): CompletableFuture<Void> = CompletableFuture.runAsync {
if (!config.isEnabled()) {
logger.warn("External pack import is disabled")
return
return@runAsync
}

val packs = config.getPacks()
if (packs.isEmpty()) {
val directories = config.getPacks()
if (directories.isEmpty()) {
logger.warn("No external packs to import")
return
return@runAsync
}

try {
OraxenPack.addFilesToPack(packs.toTypedArray())
logger.info("Imported ${packs.size} external packs")
val packFolder = OraxenPlugin.get().resourcePack.packFolder
for (directory in directories) {
val files = directory.walkTopDown().filter { it.isFile && it.exists() }
for (file in files) {
val relativePath = directory.toPath().relativize(file.toPath()).toString()
val targetFile = packFolder.resolve(relativePath)
if (targetFile.exists() && targetFile.readBytes().contentEquals(file.readBytes())) continue
file.copyTo(targetFile, true)
}
}
logger.info("Successfully imported external packs")
} catch (e: Exception) {
logger.error("Failed to import external packs", e)
}
Expand Down

0 comments on commit bd4d85f

Please sign in to comment.