From bc478301ff5529713fa6c113cb236eb39aabe6b6 Mon Sep 17 00:00:00 2001 From: Yang Seong Mo Date: Wed, 11 Dec 2024 16:34:21 +0900 Subject: [PATCH] Fix pack support. --- .../compatibility/nexo/NexoCompatibility.kt | 4 ++- .../oraxen/OraxenCompatibility.kt | 4 +++ bootstrap/fabric/build.gradle.kts | 2 ++ .../PolymerAutoHostCompatibility.kt | 29 +++++++++++++++++++ .../PolymerResourcePackCompatibility.kt | 2 -- .../fabric/manager/CompatibilityManager.kt | 4 +++ .../kotlin/kr/toxicity/hud/BetterHudImpl.kt | 18 ++++-------- 7 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/compatibility/PolymerAutoHostCompatibility.kt diff --git a/bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/compatibility/nexo/NexoCompatibility.kt b/bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/compatibility/nexo/NexoCompatibility.kt index ee6f19db..2f2e347d 100644 --- a/bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/compatibility/nexo/NexoCompatibility.kt +++ b/bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/compatibility/nexo/NexoCompatibility.kt @@ -1,6 +1,8 @@ package kr.toxicity.hud.bootstrap.bukkit.compatibility.nexo import com.nexomc.nexo.api.events.resourcepack.NexoPrePackGenerateEvent +import com.nexomc.nexo.configs.Settings +import com.nexomc.nexo.pack.server.PackServerType import kr.toxicity.hud.api.listener.HudListener import kr.toxicity.hud.api.placeholder.HudPlaceholder import kr.toxicity.hud.api.plugin.ReloadState.* @@ -31,7 +33,7 @@ class NexoCompatibility : Compatibility { get() = mapOf() override fun start() { - (BOOTSTRAP as BukkitBootstrapImpl).skipInitialReload = true + if (Settings.PACK_SERVER_TYPE.value != PackServerType.NONE.name) (BOOTSTRAP as BukkitBootstrapImpl).skipInitialReload = true registerListener(object : Listener { @EventHandler fun NexoPrePackGenerateEvent.generate() { diff --git a/bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/compatibility/oraxen/OraxenCompatibility.kt b/bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/compatibility/oraxen/OraxenCompatibility.kt index 2139e94e..be617509 100644 --- a/bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/compatibility/oraxen/OraxenCompatibility.kt +++ b/bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/compatibility/oraxen/OraxenCompatibility.kt @@ -1,6 +1,7 @@ package kr.toxicity.hud.bootstrap.bukkit.compatibility.oraxen import io.th0rgal.oraxen.api.events.OraxenPackGeneratedEvent +import io.th0rgal.oraxen.config.Settings import io.th0rgal.oraxen.utils.VirtualFile import kr.toxicity.hud.api.listener.HudListener import kr.toxicity.hud.api.placeholder.HudPlaceholder @@ -8,8 +9,10 @@ import kr.toxicity.hud.api.plugin.ReloadState.* import kr.toxicity.hud.api.trigger.HudTrigger import kr.toxicity.hud.api.update.UpdateEvent import kr.toxicity.hud.api.yaml.YamlObject +import kr.toxicity.hud.bootstrap.bukkit.BukkitBootstrapImpl import kr.toxicity.hud.bootstrap.bukkit.compatibility.Compatibility import kr.toxicity.hud.bootstrap.bukkit.util.registerListener +import kr.toxicity.hud.util.BOOTSTRAP import kr.toxicity.hud.util.PLUGIN import kr.toxicity.hud.util.info import kr.toxicity.hud.util.warn @@ -32,6 +35,7 @@ class OraxenCompatibility : Compatibility { get() = mapOf() override fun start() { + if (Settings.UPLOAD.toBool()) (BOOTSTRAP as BukkitBootstrapImpl).skipInitialReload = true registerListener(object : Listener { @EventHandler fun OraxenPackGeneratedEvent.generate() { diff --git a/bootstrap/fabric/build.gradle.kts b/bootstrap/fabric/build.gradle.kts index 3f2241c5..dda24955 100644 --- a/bootstrap/fabric/build.gradle.kts +++ b/bootstrap/fabric/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { }) //Other mod dependency modCompileOnly("eu.pb4:polymer-resource-pack:0.11.1+1.21.4") + modCompileOnly("eu.pb4:polymer-autohost:0.11.1+1.21.4") modCompileOnly("eu.pb4:placeholder-api:2.5.1+1.21.3") modCompileOnly("net.luckperms:api:5.4") @@ -61,6 +62,7 @@ fabricModJson { suggests = mapOf( "luckperms" to listOf("*"), "polymer-resource-pack" to listOf("*"), + "polymer-autohost" to listOf("*"), "placeholder-api" to listOf("*") ) } diff --git a/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/compatibility/PolymerAutoHostCompatibility.kt b/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/compatibility/PolymerAutoHostCompatibility.kt new file mode 100644 index 00000000..a565d270 --- /dev/null +++ b/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/compatibility/PolymerAutoHostCompatibility.kt @@ -0,0 +1,29 @@ +package kr.toxicity.hud.bootstrap.fabric.compatibility + +import kr.toxicity.hud.api.listener.HudListener +import kr.toxicity.hud.api.placeholder.HudPlaceholder +import kr.toxicity.hud.api.trigger.HudTrigger +import kr.toxicity.hud.api.update.UpdateEvent +import kr.toxicity.hud.api.yaml.YamlObject +import kr.toxicity.hud.bootstrap.fabric.FabricBootstrapImpl +import kr.toxicity.hud.util.PLUGIN + +class PolymerAutoHostCompatibility : Compatibility { + + override val website: String = "https://modrinth.com/mod/polymer" + + override val triggers: Map HudTrigger<*>> + get() = mapOf() + override val listeners: Map (UpdateEvent) -> HudListener> + get() = mapOf() + override val numbers: Map> + get() = mapOf() + override val strings: Map> + get() = mapOf() + override val booleans: Map> + get() = mapOf() + + override fun start() { + (PLUGIN.bootstrap() as FabricBootstrapImpl).skipInitialReload = true + } +} \ No newline at end of file diff --git a/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/compatibility/PolymerResourcePackCompatibility.kt b/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/compatibility/PolymerResourcePackCompatibility.kt index 332fd7ac..7cfc8ed9 100644 --- a/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/compatibility/PolymerResourcePackCompatibility.kt +++ b/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/compatibility/PolymerResourcePackCompatibility.kt @@ -7,7 +7,6 @@ import kr.toxicity.hud.api.plugin.ReloadState.* import kr.toxicity.hud.api.trigger.HudTrigger import kr.toxicity.hud.api.update.UpdateEvent import kr.toxicity.hud.api.yaml.YamlObject -import kr.toxicity.hud.bootstrap.fabric.FabricBootstrapImpl import kr.toxicity.hud.manager.ConfigManagerImpl import kr.toxicity.hud.util.PLUGIN import kr.toxicity.hud.util.info @@ -29,7 +28,6 @@ class PolymerResourcePackCompatibility : Compatibility { get() = mapOf() override fun start() { - (PLUGIN.bootstrap() as FabricBootstrapImpl).skipInitialReload = true PolymerResourcePackUtils.RESOURCE_PACK_CREATION_EVENT.register { builder -> when (val state = PLUGIN.reload()) { is Success -> { diff --git a/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/manager/CompatibilityManager.kt b/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/manager/CompatibilityManager.kt index 50e752c2..d9806b08 100644 --- a/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/manager/CompatibilityManager.kt +++ b/bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/manager/CompatibilityManager.kt @@ -2,6 +2,7 @@ package kr.toxicity.hud.bootstrap.fabric.manager import kr.toxicity.hud.api.update.UpdateEvent import kr.toxicity.hud.bootstrap.fabric.compatibility.Compatibility +import kr.toxicity.hud.bootstrap.fabric.compatibility.PolymerAutoHostCompatibility import kr.toxicity.hud.bootstrap.fabric.compatibility.PolymerResourcePackCompatibility import kr.toxicity.hud.bootstrap.fabric.compatibility.TextPlaceholderAPICompatibility import kr.toxicity.hud.util.CONSOLE @@ -18,6 +19,9 @@ object CompatibilityManager { }, "polymer-resource-pack" to { PolymerResourcePackCompatibility() + }, + "polymer-autohost" to { + PolymerAutoHostCompatibility() } ) diff --git a/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt index e9b55a5a..ac8be802 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt @@ -17,6 +17,7 @@ import net.kyori.adventure.key.Key import java.io.File import java.io.InputStream import java.util.concurrent.CompletableFuture +import java.util.concurrent.atomic.AtomicBoolean import java.util.function.BiConsumer import java.util.function.Consumer import java.util.jar.JarFile @@ -82,16 +83,11 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap) : BetterHud { } } - @Volatile - private var onReload = false + private val onReload = AtomicBoolean() override fun reload(sender: Audience): ReloadState { - synchronized(this) { - if (onReload) { - return ReloadState.ON_RELOAD - } - onReload = true - } + if (onReload.get()) return ReloadState.ON_RELOAD + onReload.set(true) val time = System.currentTimeMillis() val result = CompletableFuture.supplyAsync { reloadStartTask.forEach { @@ -117,9 +113,7 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap) : BetterHud { } result }.join() - synchronized(this) { - onReload = false - } + onReload.set(false) return result } @@ -178,7 +172,7 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap) : BetterHud { override fun getConfigManager(): ConfigManager = ConfigManagerImpl override fun getPlayerManager(): PlayerManager = PlayerManagerImpl override fun getTextManager(): TextManager = TextManagerImpl - override fun isOnReload(): Boolean = onReload + override fun isOnReload(): Boolean = onReload.get() override fun getDefaultKey(): Key = DEFAULT_KEY override fun translate(locale: String, key: String): String? = TextManagerImpl.translate(locale, key) } \ No newline at end of file