Skip to content

Commit

Permalink
Supports resource pack auto-merge with Oraxen.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Nov 3, 2024
1 parent cab81bd commit 5d81471
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 21 deletions.
2 changes: 2 additions & 0 deletions bootstrap/bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ repositories {
maven("https://repo.alessiodp.com/releases/") //Parties
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") //PlaceholderAPI
maven("https://mvn.lumine.io/repository/maven/") //MythicMobs
maven("https://repo.oraxen.com/releases") //Oraxen
}

dependencies {
compileOnly("io.th0rgal:oraxen:1.183.0")
compileOnly("io.lumine:Mythic-Dist:5.7.2")
compileOnly("io.lumine:MythicLib-dist:1.7.1-SNAPSHOT")
compileOnly("net.Indyuce:MMOCore-API:1.13.1-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package kr.toxicity.hud.bootstrap.bukkit.compatibility.oraxen

import io.th0rgal.oraxen.api.events.OraxenPackGeneratedEvent
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.Failure
import kr.toxicity.hud.api.plugin.ReloadState.OnReload
import kr.toxicity.hud.api.plugin.ReloadState.Success
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.compatibility.Compatibility
import kr.toxicity.hud.bootstrap.bukkit.util.registerListener
import kr.toxicity.hud.manager.ConfigManagerImpl
import kr.toxicity.hud.util.PLUGIN
import kr.toxicity.hud.util.info
import kr.toxicity.hud.util.warn
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import java.io.ByteArrayInputStream

class OraxenCompatibility : Compatibility {
override val website: String = "https://www.spigotmc.org/resources/72448/"
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() {
registerListener(object : Listener {
@EventHandler
fun generate(event: OraxenPackGeneratedEvent) {
when (val state = PLUGIN.reload()) {
is Success -> {
val output = event.output
state.resourcePack.forEach {
output.add(
VirtualFile(
it.key.substringBeforeLast('/'),
it.key.substringAfterLast('/'),
ByteArrayInputStream(it.value).buffered()
)
)
}
info("Successfully merged with Oraxen: (${state.time} ms)")
}
is Failure -> {
val reason = mutableListOf(
"Fail to merge the resource pack with Oraxen.",
"Reason: ${state.throwable.message ?: state.throwable.javaClass.simpleName}"
)
if (ConfigManagerImpl.debug) {
reason.add(state.throwable.stackTraceToString())
}
warn(*reason.toTypedArray())
}
is OnReload -> warn("This plugin is still on reload!")
}
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kr.toxicity.hud.bootstrap.bukkit.compatibility.mmocore.MMOCoreCompatibili
import kr.toxicity.hud.bootstrap.bukkit.compatibility.mmoitems.MMOItemsCompatibility
import kr.toxicity.hud.bootstrap.bukkit.compatibility.mythiclib.MythicLibCompatibility
import kr.toxicity.hud.bootstrap.bukkit.compatibility.mythicmobs.MythicMobsCompatibility
import kr.toxicity.hud.bootstrap.bukkit.compatibility.oraxen.OraxenCompatibility
import kr.toxicity.hud.bootstrap.bukkit.compatibility.parties.PartiesCompatibility
import kr.toxicity.hud.bootstrap.bukkit.compatibility.skript.SkriptCompatibility
import kr.toxicity.hud.bootstrap.bukkit.compatibility.vault.VaultCompatibility
Expand Down Expand Up @@ -41,6 +42,9 @@ object CompatibilityManager {
},
"Parties" to {
PartiesCompatibility()
},
"Oraxen" to {
OraxenCompatibility()
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ import kr.toxicity.hud.api.yaml.YamlObject
import kr.toxicity.hud.bootstrap.bukkit.module.BukkitModule
import kr.toxicity.hud.bootstrap.bukkit.util.call
import kr.toxicity.hud.bootstrap.bukkit.util.createBukkitTrigger
import kr.toxicity.hud.bootstrap.bukkit.util.registerListener
import kr.toxicity.hud.bootstrap.bukkit.util.unwrap
import kr.toxicity.hud.util.BOOTSTRAP
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityPickupItemEvent
import org.bukkit.event.player.PlayerDropItemEvent
import org.bukkit.inventory.meta.Damageable
import org.bukkit.plugin.Plugin
import java.util.function.Function

class BukkitItemModule : BukkitModule {
override fun start() {
Bukkit.getPluginManager().registerEvents(object : Listener {
registerListener(object : Listener {
@EventHandler
fun drop(e: PlayerDropItemEvent) {
UpdateItemEvent(e.player, e.itemDrop.itemStack, e).call()
Expand All @@ -37,7 +35,7 @@ class BukkitItemModule : BukkitModule {
e
).call()
}
}, BOOTSTRAP as Plugin)
})
}
override val triggers: Map<String, (YamlObject) -> HudBukkitEventTrigger<*>>
get() = mapOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kr.toxicity.hud.bootstrap.bukkit.util

import kr.toxicity.hud.util.BOOTSTRAP
import org.bukkit.Bukkit
import org.bukkit.event.Listener
import org.bukkit.plugin.Plugin

fun registerListener(listener: Listener) {
Bukkit.getPluginManager().registerEvents(listener, BOOTSTRAP as Plugin)
}
1 change: 1 addition & 0 deletions bootstrap/bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ softdepend:
- SkinsRestorer
- Parties
- GPS
- Oraxen
permissions:
hud.help:
description: Access to help command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package kr.toxicity.hud.bootstrap.fabric.compatibility
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils
import kr.toxicity.hud.api.listener.HudListener
import kr.toxicity.hud.api.placeholder.HudPlaceholder
import kr.toxicity.hud.api.plugin.ReloadState.Success
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.manager.ConfigManagerImpl
import kr.toxicity.hud.util.PLUGIN
import kr.toxicity.hud.util.info
import kr.toxicity.hud.util.warn
Expand Down Expand Up @@ -35,7 +36,17 @@ class PolymerResourcePackCompatibility : Compatibility {
}
info("Polymer generation detected - reload completed: (${state.time} ms)")
}
else -> warn("Unable to merge the resource pack with Polymer.")
is Failure -> {
val reason = mutableListOf(
"Fail to merge the resource pack with Polymer.",
"Reason: ${state.throwable.message ?: state.throwable.javaClass.simpleName}"
)
if (ConfigManagerImpl.debug) {
reason.add(state.throwable.stackTraceToString())
}
warn(*reason.toTypedArray())
}
is OnReload -> warn("This mod is still on reload!")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ fabricBootstrap.modrinthPublish(
listOf("fabric", "quilt"),
listOf(minecraft),
listOf("fabric-api"),
listOf("placeholder-api", "polymer")
listOf("luckperms", "placeholder-api", "polymer")
)

tasks.create("modrinthPublish") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ object ConfigManagerImpl : BetterHudManager, ConfigManager {
}
}
}
PLUGIN.loadAssets("pack") { n, i ->
val read = i.readAllBytes()
PackGenerator.addTask(n.split('/')) {
read
}
}
}

override fun preReload() {
Expand Down
13 changes: 0 additions & 13 deletions dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ object PackGenerator {
build.forEach {
getAllLocation(it, pathLength)
}
PLUGIN.loadAssets("pack") { a, i ->
val replace = a.replace(NAME_SPACE, NAME_SPACE_ENCODED).replace('/', File.separatorChar)
(builder.locationMap.remove(replace) ?: File(build, replace).apply {
parentFile.mkdirs()
}).outputStream().buffered().use { os ->
i.copyTo(os)
}
}
object : Generator {
override val resourcePack: Map<String, ByteArray>
get() = Collections.unmodifiableMap(builder.byteArrayMap)
Expand All @@ -160,11 +152,6 @@ object PackGenerator {
} ?: stream).apply {
setComment("BetterHud resource pack.")
setLevel(Deflater.BEST_COMPRESSION)
PLUGIN.loadAssets("pack") { s, i ->
putNextEntry(ZipEntry(s.replace(NAME_SPACE, NAME_SPACE_ENCODED).replace(File.separatorChar,'/')))
write(i.readAllBytes())
closeEntry()
}
})
fun addEntry(entry: ZipEntry, byte: ByteArray) {
synchronized(zip) {
Expand Down

0 comments on commit 5d81471

Please sign in to comment.