Skip to content

Commit

Permalink
Fix pack support.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 11, 2024
1 parent 16222f6 commit bc47830
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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
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
Expand All @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -61,6 +62,7 @@ fabricModJson {
suggests = mapOf(
"luckperms" to listOf("*"),
"polymer-resource-pack" to listOf("*"),
"polymer-autohost" to listOf("*"),
"placeholder-api" to listOf("*")
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, (YamlObject) -> HudTrigger<*>>
get() = mapOf()
override val listeners: Map<String, (YamlObject) -> (UpdateEvent) -> HudListener>
get() = mapOf()
override val numbers: Map<String, HudPlaceholder<Number>>
get() = mapOf()
override val strings: Map<String, HudPlaceholder<String>>
get() = mapOf()
override val booleans: Map<String, HudPlaceholder<Boolean>>
get() = mapOf()

override fun start() {
(PLUGIN.bootstrap() as FabricBootstrapImpl).skipInitialReload = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +19,9 @@ object CompatibilityManager {
},
"polymer-resource-pack" to {
PolymerResourcePackCompatibility()
},
"polymer-autohost" to {
PolymerAutoHostCompatibility()
}
)

Expand Down
18 changes: 6 additions & 12 deletions dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -117,9 +113,7 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap) : BetterHud {
}
result
}.join()
synchronized(this) {
onReload = false
}
onReload.set(false)
return result
}

Expand Down Expand Up @@ -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)
}

0 comments on commit bc47830

Please sign in to comment.