From cc4d14f707865bd51dcc2669191b1fc8ff16214e Mon Sep 17 00:00:00 2001 From: toxicity Date: Thu, 18 Apr 2024 12:08:30 +0900 Subject: [PATCH] Hotfix. --- .../java/kr/toxicity/hud/api/BetterHud.java | 8 ++ .../hud/api/event/PluginReloadStartEvent.java | 24 ++++++ .../hud/api/event/PluginReloadedEvent.java | 5 +- build.gradle.kts | 4 +- .../kotlin/kr/toxicity/hud/BetterHudImpl.kt | 65 +++++++++------ .../kotlin/kr/toxicity/hud/hud/HudElement.kt | 6 +- .../kotlin/kr/toxicity/hud/hud/HudImpl.kt | 16 ++-- .../kr/toxicity/hud/hud/HudTextElement.kt | 9 +- .../toxicity/hud/manager/BackgroundManager.kt | 17 +++- .../kr/toxicity/hud/manager/ConfigManager.kt | 11 ++- .../kr/toxicity/hud/manager/HudManagerImpl.kt | 6 +- .../kr/toxicity/hud/manager/ImageManager.kt | 21 +++-- .../kr/toxicity/hud/manager/LayoutManager.kt | 6 +- .../toxicity/hud/manager/PlayerHeadManager.kt | 28 ++++--- .../toxicity/hud/manager/PopupManagerImpl.kt | 7 +- .../kr/toxicity/hud/manager/ShaderManager.kt | 49 ++++++----- .../kr/toxicity/hud/manager/TextManager.kt | 34 +++++--- .../kotlin/kr/toxicity/hud/pack/PackFile.kt | 6 ++ .../kr/toxicity/hud/pack/PackGenerator.kt | 77 ++++++++++++++++-- .../kotlin/kr/toxicity/hud/pack/PackType.kt | 6 ++ .../kotlin/kr/toxicity/hud/popup/PopupImpl.kt | 14 ++-- .../kr/toxicity/hud/popup/PopupLayout.kt | 23 ++++-- .../toxicity/hud/resource/GlobalResource.kt | 40 ++++----- .../main/kotlin/kr/toxicity/hud/util/Files.kt | 24 ++---- .../main/kotlin/kr/toxicity/hud/util/Gsons.kt | 5 ++ .../kotlin/kr/toxicity/hud/util/Images.kt | 8 ++ .../main/kotlin/kr/toxicity/hud/util/Lists.kt | 36 +++----- dist/src/main/resources/config.yml | 3 +- .../assets}/betterhud/font/legacy_space.json | 0 .../assets}/betterhud/font/space.json | 0 .../assets}/betterhud/font/spaces.ttf | Bin .../betterhud/textures/font/splitter.png | Bin .../core/rendertype_entity_cutout.json | 0 .../rendertype_entity_translucent_cull.json | 0 .../shaders/core/rendertype_text.fsh | 0 .../shaders/core/rendertype_text.json | 0 36 files changed, 374 insertions(+), 184 deletions(-) create mode 100644 api/src/main/java/kr/toxicity/hud/api/event/PluginReloadStartEvent.java create mode 100644 dist/src/main/kotlin/kr/toxicity/hud/pack/PackFile.kt create mode 100644 dist/src/main/kotlin/kr/toxicity/hud/pack/PackType.kt rename dist/src/main/resources/{ => pack/assets}/betterhud/font/legacy_space.json (100%) rename dist/src/main/resources/{ => pack/assets}/betterhud/font/space.json (100%) rename dist/src/main/resources/{ => pack/assets}/betterhud/font/spaces.ttf (100%) rename dist/src/main/resources/{ => pack/assets}/betterhud/textures/font/splitter.png (100%) rename dist/src/main/resources/{ => pack/assets}/minecraft/shaders/core/rendertype_entity_cutout.json (100%) rename dist/src/main/resources/{ => pack/assets}/minecraft/shaders/core/rendertype_entity_translucent_cull.json (100%) rename dist/src/main/resources/{ => pack/assets}/minecraft/shaders/core/rendertype_text.fsh (100%) rename dist/src/main/resources/{ => pack/assets}/minecraft/shaders/core/rendertype_text.json (100%) diff --git a/api/src/main/java/kr/toxicity/hud/api/BetterHud.java b/api/src/main/java/kr/toxicity/hud/api/BetterHud.java index 86b56351..1df7d4fa 100644 --- a/api/src/main/java/kr/toxicity/hud/api/BetterHud.java +++ b/api/src/main/java/kr/toxicity/hud/api/BetterHud.java @@ -12,7 +12,9 @@ import org.jetbrains.annotations.NotNull; import java.io.File; +import java.io.InputStream; import java.util.Objects; +import java.util.function.BiConsumer; import java.util.function.Consumer; /** @@ -94,6 +96,12 @@ public void onLoad() { // Do not use this * @param dir target directory */ public abstract void loadAssets(@NotNull String prefix, @NotNull File dir); + /** + * Loads player's resource to some directory + * @param prefix resource folder + * @param consumer for each callback + */ + public abstract void loadAssets(@NotNull String prefix, @NotNull BiConsumer consumer); /** * Gets a width of default font's char diff --git a/api/src/main/java/kr/toxicity/hud/api/event/PluginReloadStartEvent.java b/api/src/main/java/kr/toxicity/hud/api/event/PluginReloadStartEvent.java new file mode 100644 index 00000000..028ac357 --- /dev/null +++ b/api/src/main/java/kr/toxicity/hud/api/event/PluginReloadStartEvent.java @@ -0,0 +1,24 @@ +package kr.toxicity.hud.api.event; + +import lombok.Getter; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * Plugin reloaded event. + */ +@Getter +public class PluginReloadStartEvent extends Event implements BetterHudEvent { + public PluginReloadStartEvent() { + super(true); + } + @NotNull + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} diff --git a/api/src/main/java/kr/toxicity/hud/api/event/PluginReloadedEvent.java b/api/src/main/java/kr/toxicity/hud/api/event/PluginReloadedEvent.java index 47f9054d..82e34c5a 100644 --- a/api/src/main/java/kr/toxicity/hud/api/event/PluginReloadedEvent.java +++ b/api/src/main/java/kr/toxicity/hud/api/event/PluginReloadedEvent.java @@ -10,10 +10,13 @@ /** * Plugin reloaded event. */ -@RequiredArgsConstructor @Getter public class PluginReloadedEvent extends Event implements BetterHudEvent { private final ReloadResult result; + public PluginReloadedEvent(@NotNull ReloadResult result) { + super(true); + this.result = result; + } @NotNull @Override public HandlerList getHandlers() { diff --git a/build.gradle.kts b/build.gradle.kts index 203275aa..bedffaa4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ plugins { `java-library` kotlin("jvm") version "1.9.23" id("com.github.johnrengelman.shadow") version("8.1.1") - id("io.papermc.paperweight.userdev") version("1.5.6") apply(false) + id("io.papermc.paperweight.userdev") version("1.5.12") apply(false) id("org.jetbrains.dokka") version "1.9.20" } @@ -32,7 +32,7 @@ allprojects { apply(plugin = "kotlin") group = "kr.toxicity.hud" - version = "beta-14" + version = "beta-15" repositories { mavenCentral() diff --git a/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt index 9b7c07c8..0ce99dff 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt @@ -2,6 +2,7 @@ package kr.toxicity.hud import kr.toxicity.hud.api.BetterHud import kr.toxicity.hud.api.bedrock.BedrockAdapter +import kr.toxicity.hud.api.event.PluginReloadStartEvent import kr.toxicity.hud.api.event.PluginReloadedEvent import kr.toxicity.hud.api.manager.* import kr.toxicity.hud.api.nms.NMS @@ -31,10 +32,12 @@ import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.player.PlayerJoinEvent import java.io.File +import java.io.InputStream import java.net.URI import java.net.http.HttpClient import java.net.http.HttpRequest import java.net.http.HttpResponse +import java.util.function.BiConsumer import java.util.function.Consumer import java.util.jar.JarFile @@ -213,6 +216,7 @@ class BetterHudImpl: BetterHud() { onReload = true val time = System.currentTimeMillis() asyncTask { + PluginReloadStartEvent().call() runCatching { managers.forEach { it.preReload() @@ -221,25 +225,23 @@ class BetterHudImpl: BetterHud() { val index = TaskIndex(managers.size) fun managerReload() { - synchronized(index) { - if (index.current < managers.size) { - val manager = managers[index.current++] - info("Loading ${manager.javaClass.simpleName}...") + if (index.current < managers.size) { + val manager = managers[index.current++] + info("Loading ${manager.javaClass.simpleName}...") + synchronized(manager) { manager.reload(resource) { managerReload() } - } else { - PackGenerator.generate { - managers.forEach { - it.postReload() - } - onReload = false - val result = ReloadResult(ReloadState.SUCCESS, System.currentTimeMillis() - time) - task { - PluginReloadedEvent(result).call() - } - consumer.accept(result) + } + } else { + PackGenerator.generate { + managers.forEach { + it.postReload() } + onReload = false + val result = ReloadResult(ReloadState.SUCCESS, System.currentTimeMillis() - time) + PluginReloadedEvent(result).call() + consumer.accept(result) } } } @@ -269,7 +271,26 @@ class BetterHudImpl: BetterHud() { override fun getAudiences(): BukkitAudiences = audience override fun getHudPlayer(player: Player): HudPlayer = PlayerManager.getHudPlayer(player) + override fun loadAssets(prefix: String, dir: File) { + loadAssets(prefix, { + File(dir, it).run { + if (!exists()) mkdir() + } + }) { s, i -> + File(dir, s).outputStream().buffered().use { + i.copyTo(it) + } + } + } + + override fun loadAssets(prefix: String, consumer: BiConsumer) { + loadAssets(prefix, {}) { s, i -> + consumer.accept(s, i) + } + } + + private fun loadAssets(prefix: String, dir: (String) -> Unit, consumer: (String, InputStream) -> Unit) { JarFile(file).use { it.entries().asSequence().sortedBy { dir -> dir.name.length @@ -277,18 +298,10 @@ class BetterHudImpl: BetterHud() { if (!entry.name.startsWith(prefix)) return@forEach if (entry.name.length <= prefix.length + 1) return@forEach val name = entry.name.substring(prefix.length + 1) - val file = File(dir, name) if (entry.isDirectory) { - if (!file.exists()) file.mkdir() - } else { - getResource(entry.name)?.buffered()?.use { stream -> - if (!file.exists()) { - file.createNewFile() - file.outputStream().buffered().use { fos -> - stream.copyTo(fos) - } - } - } + dir(name) + } else getResource(entry.name)?.buffered()?.use { stream -> + consumer(name, stream) } } } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudElement.kt b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudElement.kt index cb5902d4..c937ed53 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudElement.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudElement.kt @@ -10,12 +10,14 @@ import kr.toxicity.hud.util.EMPTY_WIDTH_COMPONENT import kr.toxicity.hud.util.subFolder import java.io.File -class HudElement(hud: HudImpl, name: String, file: File, private val layout: LayoutGroup, gui: GuiLocation, pixel: ImageLocation) { +class HudElement(hud: HudImpl, name: String, file: List, private val layout: LayoutGroup, gui: GuiLocation, pixel: ImageLocation) { private val imageElement = layout.image.map {image -> HudImageElement(hud, image, gui, pixel) } private val textElement = run { - val subFile = file.subFolder("text") + val subFile = ArrayList(file).apply { + add("text") + } layout.text.mapIndexed { index, textLayout -> HudTextElement(hud, name, subFile, textLayout, index, gui, pixel) } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImpl.kt index f83d2bf4..5157eca5 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudImpl.kt @@ -17,9 +17,8 @@ import kr.toxicity.hud.shader.HudShader import kr.toxicity.hud.util.* import net.kyori.adventure.key.Key import org.bukkit.configuration.ConfigurationSection -import java.io.File -class HudImpl(private val internalName: String, file: File, section: ConfigurationSection) : Hud { +class HudImpl(private val internalName: String, file: List, section: ConfigurationSection) : Hud { companion object { const val DEFAULT_BIT = 13 const val MAX_BIT = 23 - DEFAULT_BIT @@ -37,7 +36,9 @@ class HudImpl(private val internalName: String, file: File, section: Configurati var textIndex = 0 private val elements = run { - val subFile = file.subFolder(internalName) + val subFile = ArrayList(file).apply { + add(internalName) + } ArrayList().apply { section.getConfigurationSection("layouts").ifNull("layout configuration not set.").forEachSubConfiguration { s, configurationSection -> val layout = configurationSection.getString("name").ifNull("name value not set: $s").let { @@ -69,10 +70,15 @@ class HudImpl(private val internalName: String, file: File, section: Configurati } } init { - PackGenerator.addTask { + PackGenerator.addTask( + ArrayList(file).apply { + add(internalName) + add("image.json") + } + ) { JsonObject().apply { add("providers", jsonArray) - }.save(file.subFolder(internalName).subFile("image.json")) + }.toByteArray() } } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextElement.kt b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextElement.kt index 5a684f6a..34bf5731 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextElement.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/hud/HudTextElement.kt @@ -20,10 +20,9 @@ import kr.toxicity.hud.text.HudTextData import kr.toxicity.hud.util.* import net.kyori.adventure.key.Key import net.kyori.adventure.text.Component -import java.io.File import kotlin.math.roundToInt -class HudTextElement(parent: HudImpl, name: String, file: File, private val text: TextLayout, index: Int, gui: GuiLocation, pixel: ImageLocation) { +class HudTextElement(parent: HudImpl, name: String, file: List, private val text: TextLayout, index: Int, gui: GuiLocation, pixel: ImageLocation) { private val renderer = run { val shader = HudShader( @@ -108,10 +107,12 @@ class HudTextElement(parent: HudImpl, name: String, file: File, private val text ) } ) - PackGenerator.addTask { + PackGenerator.addTask(ArrayList(file).apply { + add("text_${index + 1}_${index2 + 1}.json") + }) { JsonObject().apply { add("providers", array) - }.save(File(file, "text_${index + 1}_${index2 + 1}.json")) + }.toByteArray() } TextManager.setKey(group, result) result diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/BackgroundManager.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/BackgroundManager.kt index 75d07f30..77eb9ed7 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/BackgroundManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/BackgroundManager.kt @@ -2,6 +2,7 @@ package kr.toxicity.hud.manager import kr.toxicity.hud.background.HudBackground import kr.toxicity.hud.image.ImageLocation +import kr.toxicity.hud.pack.PackGenerator import kr.toxicity.hud.resource.GlobalResource import kr.toxicity.hud.util.* import java.io.File @@ -18,21 +19,29 @@ object BackgroundManager: BetterHudManager { override fun reload(resource: GlobalResource, callback: () -> Unit) { val folder = DATA_FOLDER.subFolder("backgrounds") - val outputParent = resource.textures.subFolder("background") + val outputParent = ArrayList(resource.textures).apply { + add("background") + } backgroundMap.clear() - folder.forEachAsync({ _, it -> + folder.forEachAsync({ if (it.extension == "yml") { runCatching { val yaml = it.toYaml() val name = it.nameWithoutExtension val backgroundFolder = folder.subFolder(name) - val output = outputParent.subFolder(name) + val output = ArrayList(outputParent).apply { + add(name) + } fun getImage(imageName: String) = File(backgroundFolder, "$imageName.png") .ifNotExist("this image doesn't exist: $imageName.png in $name") .toImage() .removeEmptyWidth() .ifNull("this image is empty: $imageName.png in $name").apply { - image.save(output.subFile("$imageName.png")) + PackGenerator.addTask(ArrayList(output).apply { + add("$imageName.png") + }) { + image.toByteArray() + } } backgroundMap[name] = HudBackground( name, diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManager.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManager.kt index 1e536254..9dac3f4d 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManager.kt @@ -1,5 +1,6 @@ package kr.toxicity.hud.manager +import kr.toxicity.hud.pack.PackType import kr.toxicity.hud.resource.GlobalResource import kr.toxicity.hud.util.* import net.kyori.adventure.text.Component @@ -26,11 +27,11 @@ object ConfigManager: BetterHudManager { private set var buildFolderLocation = "BetterHud\\build" private set - var separateResourcePackNameSpace = false - private set var mergeBossBar = true private set + var packType = PackType.FOLDER + private set override fun start() { @@ -50,6 +51,11 @@ object ConfigManager: BetterHudManager { yaml.getString("default-font-name")?.let { defaultFontName = it } + yaml.getString("pack-type")?.let { + runCatching { + packType = PackType.valueOf(it.uppercase()) + } + } tickSpeed = yaml.getLong("tick-speed", 1) numberFormat = (yaml.getString("number-format")?.let { runCatching { @@ -57,7 +63,6 @@ object ConfigManager: BetterHudManager { }.getOrNull() } ?: DecimalFormat("#,###.#")) disableToBedrockPlayer = yaml.getBoolean("disable-to-bedrock-player", true) - separateResourcePackNameSpace = yaml.getBoolean("separate-resource-pack-namespace", false) yaml.getString("build-folder-location")?.let { buildFolderLocation = it } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/HudManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/HudManagerImpl.kt index d7e53dbc..fa97177a 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/HudManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/HudManagerImpl.kt @@ -19,8 +19,10 @@ object HudManagerImpl: BetterHudManager, HudManager { override fun reload(resource: GlobalResource, callback: () -> Unit) { hudMap.clear() - val hudFolder = resource.font.subFolder("hud") - DATA_FOLDER.subFolder("huds").forEachAllYamlAsync({ _, file, s, configurationSection -> + val hudFolder = ArrayList(resource.font).apply { + add("hud") + } + DATA_FOLDER.subFolder("huds").forEachAllYamlAsync({ file, s, configurationSection -> runCatching { hudMap[s] = HudImpl(s, hudFolder, configurationSection) }.onFailure { e -> diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/ImageManager.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/ImageManager.kt index fec5ffb3..04e03e4d 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/ImageManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/ImageManager.kt @@ -6,6 +6,7 @@ import kr.toxicity.hud.resource.GlobalResource import kr.toxicity.hud.util.* import org.bukkit.configuration.MemoryConfiguration import java.io.File +import java.util.concurrent.ConcurrentHashMap object ImageManager: BetterHudManager { @@ -23,7 +24,7 @@ object ImageManager: BetterHudManager { imageMap.clear() val assets = DATA_FOLDER.subFolder("assets") - DATA_FOLDER.subFolder("images").forEachAllYamlAsync({ _, file, s, configurationSection -> + DATA_FOLDER.subFolder("images").forEachAllYamlAsync({ file, s, configurationSection -> runCatching { imageMap[s] = when (val type = ImageType.valueOf(configurationSection.getString("type").ifNull("type value not set.").uppercase())) { ImageType.SINGLE -> { @@ -79,17 +80,21 @@ object ImageManager: BetterHudManager { warn("Reason: ${e.message}") } }) { - val saveLocation = resource.textures.subFolder("image") + val saveLocation = ArrayList(resource.textures).apply { + add("image") + } imageMap.values.forEach { value -> val list = value.image if (list.isNotEmpty()) { - val imageSaveLocation = if (list.size == 1) saveLocation else saveLocation.subFolder(value.name) + val imageSaveLocation = if (list.size == 1) saveLocation else ArrayList(saveLocation).apply { + add(value.name) + } list.forEach { - val file = File(imageSaveLocation, it.name) - if (!file.exists()) { - PackGenerator.addTask { - it.image.image.save(file) - } + val file = ArrayList(imageSaveLocation).apply { + add(it.name) + } + PackGenerator.addTask(file) { + it.image.image.toByteArray() } } } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/LayoutManager.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/LayoutManager.kt index 702af360..b1c07cf9 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/LayoutManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/LayoutManager.kt @@ -3,6 +3,7 @@ package kr.toxicity.hud.manager import kr.toxicity.hud.layout.LayoutGroup import kr.toxicity.hud.resource.GlobalResource import kr.toxicity.hud.util.* +import java.util.concurrent.ConcurrentHashMap object LayoutManager: BetterHudManager { @@ -16,15 +17,14 @@ object LayoutManager: BetterHudManager { override fun reload(resource: GlobalResource, callback: () -> Unit) { layoutMap.clear() - DATA_FOLDER.subFolder("layouts").forEachAllYaml { file, s, configurationSection -> + DATA_FOLDER.subFolder("layouts").forEachAllYamlAsync({ file, s, configurationSection -> runCatching { layoutMap[s] = LayoutGroup(configurationSection) }.onFailure { e -> warn("Unable to load this layout: $s in ${file.name}") warn("Reason: ${e.message}") } - } - callback() + }, callback) } override fun end() { diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/PlayerHeadManager.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/PlayerHeadManager.kt index d9e711d4..6bd9f7b6 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/PlayerHeadManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/PlayerHeadManager.kt @@ -1,11 +1,11 @@ package kr.toxicity.hud.manager +import kr.toxicity.hud.pack.PackGenerator import kr.toxicity.hud.player.HudHead import kr.toxicity.hud.resource.GlobalResource import kr.toxicity.hud.util.* import java.awt.Color import java.awt.image.BufferedImage -import java.io.File object PlayerHeadManager: BetterHudManager { @@ -18,20 +18,26 @@ object PlayerHeadManager: BetterHudManager { fun getHead(name: String) = headMap[name] override fun reload(resource: GlobalResource, callback: () -> Unit) { - val saveLocation = resource.textures.subFolder("head") + val saveLocation = ArrayList(resource.textures).apply { + add("head") + } headMap.clear() - DATA_FOLDER.subFolder("heads").forEachAllYamlAsync({ _, file, s, configurationSection -> + DATA_FOLDER.subFolder("heads").forEachAllYamlAsync({ file, s, configurationSection -> runCatching { val head = HudHead(s , configurationSection) val pixel = head.pixel - val targetFile = File(saveLocation, "pixel_$pixel.png") - if (!targetFile.exists()) BufferedImage(pixel, pixel ,BufferedImage.TYPE_INT_ARGB).apply { - createGraphics().run { - color = Color.WHITE - fillRect(0, 0, pixel, pixel) - dispose() - } - }.save(targetFile) + val targetFile = ArrayList(saveLocation).apply { + add("pixel_$pixel.png") + } + PackGenerator.addTask(targetFile) { + BufferedImage(pixel, pixel ,BufferedImage.TYPE_INT_ARGB).apply { + createGraphics().run { + color = Color.WHITE + fillRect(0, 0, pixel, pixel) + dispose() + } + }.toByteArray() + } headMap[head.name] = head }.onFailure { e -> warn("Unable to load this head: $s in ${file.name}") diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/PopupManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/PopupManagerImpl.kt index 1007127f..6ddb1cb1 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/PopupManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/PopupManagerImpl.kt @@ -6,6 +6,7 @@ import kr.toxicity.hud.popup.PopupImpl import kr.toxicity.hud.resource.GlobalResource import kr.toxicity.hud.util.* import java.util.* +import kotlin.collections.ArrayList import kotlin.collections.HashMap object PopupManagerImpl: BetterHudManager, PopupManager { @@ -16,8 +17,10 @@ object PopupManagerImpl: BetterHudManager, PopupManager { override fun reload(resource: GlobalResource, callback: () -> Unit) { popupMap.clear() - val save = resource.font.subFolder("popup") - DATA_FOLDER.subFolder("popups").forEachAllYamlAsync({ _, file, s, configurationSection -> + val save = ArrayList(resource.font).apply { + add("popup") + } + DATA_FOLDER.subFolder("popups").forEachAllYamlAsync({ file, s, configurationSection -> runCatching { popupMap[s] = PopupImpl(save, s, configurationSection) }.onFailure { e -> diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManager.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManager.kt index 693f4625..0aa827fc 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManager.kt @@ -1,6 +1,7 @@ package kr.toxicity.hud.manager import kr.toxicity.hud.hud.HudImpl +import kr.toxicity.hud.pack.PackGenerator import kr.toxicity.hud.resource.GlobalResource import kr.toxicity.hud.shader.HotBarShader import kr.toxicity.hud.shader.HudShader @@ -8,6 +9,7 @@ import kr.toxicity.hud.util.* import org.bukkit.boss.BarColor import java.awt.image.BufferedImage import java.io.BufferedReader +import java.io.ByteArrayOutputStream import java.io.File import java.util.concurrent.CompletableFuture import java.util.regex.Pattern @@ -95,15 +97,14 @@ object ShaderManager: BetterHudManager { } ?: BarColor.RED fun copy(suffix: String) { PLUGIN.getResource("background.png")?.buffered()?.use { input -> - resource.bossBar - .subFolder("sprites") - .subFolder("boss_bar") - .subFile("${barColor.name.lowercase()}_$suffix.png") - .outputStream() - .buffered() - .use { output -> - input.copyTo(output) - } + val byte = input.readAllBytes() + PackGenerator.addTask(ArrayList(resource.bossBar).apply { + add("sprites") + add("boss_bar") + add("${barColor.name.lowercase()}_$suffix.png") + }) { + byte + } } } copy("background") @@ -111,13 +112,17 @@ object ShaderManager: BetterHudManager { PLUGIN.getResource("bars.png")?.buffered()?.use { target -> val oldImage = target.toImage() val yAxis = 10 * barColor.ordinal - BufferedImage(oldImage.width, oldImage.height, BufferedImage.TYPE_INT_ARGB).apply { - createGraphics().run { - if (barColor.ordinal > 0) drawImage(oldImage.getSubimage(0, 0, oldImage.width, yAxis), 0, 0, null) - drawImage(oldImage.getSubimage(0, yAxis + 10, oldImage.width, oldImage.height - yAxis - 10), 0, yAxis + 10, null) - dispose() - } - }.save(File(resource.bossBar, "bars.png")) + PackGenerator.addTask(ArrayList(resource.bossBar).apply { + add("bars.png") + }) { + BufferedImage(oldImage.width, oldImage.height, BufferedImage.TYPE_INT_ARGB).apply { + createGraphics().run { + if (barColor.ordinal > 0) drawImage(oldImage.getSubimage(0, 0, oldImage.width, yAxis), 0, 0, null) + drawImage(oldImage.getSubimage(0, yAxis + 10, oldImage.width, oldImage.height - yAxis - 10), 0, yAxis + 10, null) + dispose() + } + }.toByteArray() + } } if (yaml.getBoolean("disable-level-text")) replaceList.add("HideExp") @@ -150,7 +155,7 @@ object ShaderManager: BetterHudManager { shaders.forEach { shader -> shader.second.use { reader -> - File(resource.core, shader.first).bufferedWriter(Charsets.UTF_8).use { writer -> + val byte = ByteArrayOutputStream().use { writer -> reader.readLines().forEach write@ { string -> var s = string val deactivateMatcher = deactivatePattern.matcher(s) @@ -162,13 +167,19 @@ object ShaderManager: BetterHudManager { tagBuilders[tagMatcher.group("name")]?.let { val space = "".padStart(s.count { it == ' ' }, ' ') it().forEach { methodString -> - writer.write(space + methodString + "\n") + writer.write((space + methodString + "\n").toByteArray()) } return@write } } - writer.write(s + "\n") + writer.write((s + "\n").toByteArray()) } + writer + }.toByteArray() + PackGenerator.addTask(ArrayList(resource.core).apply { + add(shader.first) + }) { + byte } } } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/manager/TextManager.kt b/dist/src/main/kotlin/kr/toxicity/hud/manager/TextManager.kt index db5a9b19..8b24a800 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/manager/TextManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/manager/TextManager.kt @@ -50,8 +50,10 @@ object TextManager: BetterHudManager { textKeyMap.clear() val assetsFolder = DATA_FOLDER.subFolder("assets") val fontFolder = DATA_FOLDER.subFolder("fonts") - val globalSaveFolder = resource.textures.subFolder("text") - DATA_FOLDER.subFolder("texts").forEachAllYamlAsync({ _, file, s, section -> + val globalSaveFolder = ArrayList(resource.textures).apply { + add("text") + } + DATA_FOLDER.subFolder("texts").forEachAllYamlAsync({ file, s, section -> runCatching { val fontDir = section.getString("file") val scale = section.getInt("scale") @@ -103,7 +105,9 @@ object TextManager: BetterHudManager { } }.getOrNull() else null) ?: BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics().font }.deriveFont(configScale.toFloat()) - val parseDefault = parseFont("default", "default", defaultFont, configScale, resource.textures.subFolder("font"), emptyMap(), ConditionBuilder.alwaysTrue, fontConfig.getBoolean("merge-default-bitmap", true)) + val parseDefault = parseFont("default", "default", defaultFont, configScale, ArrayList(resource.textures).apply { + add("font") + }, emptyMap(), ConditionBuilder.alwaysTrue, fontConfig.getBoolean("merge-default-bitmap", true)) val heightMultiply = configHeight.toDouble() / parseDefault.height.toDouble() parseDefault.charWidth.forEach { textWidthMap[it.key] = Math.round(it.value.toDouble() * heightMultiply).toInt() @@ -117,10 +121,12 @@ object TextManager: BetterHudManager { add("chars", it.chars) }) } - PackGenerator.addTask { + PackGenerator.addTask(ArrayList(resource.font).apply { + add("default.json") + }) { JsonObject().apply { add("providers", defaultArray) - }.save(resource.font.subFile("default.json")) + }.toByteArray() } callback() } @@ -173,7 +179,7 @@ object TextManager: BetterHudManager { saveName: String, fontFile: Font, scale: Int, - imageSaveFolder: File, + imageSaveFolder: List, images: Map, condition: ConditionBuilder, mergeDefaultBitmap: Boolean @@ -205,10 +211,16 @@ object TextManager: BetterHudManager { } } val textList = ArrayList() - val saveFolder = imageSaveFolder.subFolder(saveName) + val saveFolder = ArrayList(imageSaveFolder).apply { + add(saveName) + } var i = 0 images.forEach { - it.value.image.image.save(File(saveFolder, "image_${it.key}.png")) + PackGenerator.addTask(ArrayList(saveFolder).apply { + add("image_${it.key}.png") + }) { + it.value.image.image.toByteArray() + } } pairMap.forEach { val width = it.key @@ -220,7 +232,9 @@ object TextManager: BetterHudManager { pair.first }.joinToString("")) } - PackGenerator.addTask { + PackGenerator.addTask(ArrayList(saveFolder).apply { + add(name) + }) { BufferedImage(width * list.size.coerceAtMost(CHAR_LENGTH), height * (((list.size - 1) / CHAR_LENGTH) + 1), BufferedImage.TYPE_INT_ARGB).apply { createGraphics().run { composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER) @@ -229,7 +243,7 @@ object TextManager: BetterHudManager { } dispose() } - }.save(File(saveFolder, name)) + }.toByteArray() } textList.add(HudTextArray(name, json)) } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/pack/PackFile.kt b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackFile.kt new file mode 100644 index 00000000..13c8f213 --- /dev/null +++ b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackFile.kt @@ -0,0 +1,6 @@ +package kr.toxicity.hud.pack + +class PackFile( + val path: String, + val array: () -> ByteArray +) \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt index ba6cf1b1..04b22a28 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt @@ -1,20 +1,85 @@ package kr.toxicity.hud.pack -import kr.toxicity.hud.util.forEachAsync +import kr.toxicity.hud.manager.ConfigManager +import kr.toxicity.hud.util.* +import java.io.File +import java.util.TreeMap +import java.util.zip.Deflater +import java.util.zip.ZipEntry +import java.util.zip.ZipOutputStream object PackGenerator { - private val tasks = ArrayList<() -> Unit>() + private val tasks = TreeMap() fun generate(callback: () -> Unit) { - tasks.forEachAsync({ _, t -> - t() + val saveTask: Generator = when (ConfigManager.packType) { + PackType.FOLDER -> { + val build = DATA_FOLDER.parentFile.subFolder(ConfigManager.buildFolderLocation).clearFolder().apply { + PLUGIN.loadAssets("pack", this) + } + object : Generator { + override fun close() { + } + override fun invoke(p1: PackFile) { + File(build, p1.path).apply { + parentFile.mkdirs() + }.outputStream().buffered().use { stream -> + stream.write(p1.array()) + } + } + } + } + PackType.ZIP -> { + val zip = ZipOutputStream(File(DATA_FOLDER.parentFile, "${ConfigManager.buildFolderLocation}.zip").apply { + if (!exists()) delete() + }.outputStream().buffered()).apply { + setComment("BetterHud resource pack.") + setLevel(Deflater.BEST_COMPRESSION) + PLUGIN.loadAssets("pack") { s, i -> + putNextEntry(ZipEntry(s.replace('\\','/'))) + write(i.readAllBytes()) + closeEntry() + } + } + object : Generator { + override fun close() { + synchronized(zip) { + zip.close() + } + } + + override fun invoke(p1: PackFile) { + val entry = ZipEntry(p1.path) + val byte = p1.array() + synchronized(zip) { + zip.putNextEntry(entry) + zip.write(byte) + zip.closeEntry() + } + } + } + } + } + tasks.values.forEachAsync({ t -> + runCatching { + saveTask(t) + }.onFailure { e -> + warn("Unable to save this file: ${t.path}") + warn("Reason: ${e.message}") + } }) { + saveTask.close() callback() tasks.clear() } } - fun addTask(block: () -> Unit) { - tasks.add(block) + fun addTask(dir: Iterable, byteArray: () -> ByteArray) { + val str = dir.joinToString("/") + tasks.computeIfAbsent(str) { + PackFile(str, byteArray) + } } + + private interface Generator: (PackFile) -> Unit, AutoCloseable } \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/hud/pack/PackType.kt b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackType.kt new file mode 100644 index 00000000..153a5d7c --- /dev/null +++ b/dist/src/main/kotlin/kr/toxicity/hud/pack/PackType.kt @@ -0,0 +1,6 @@ +package kr.toxicity.hud.pack + +enum class PackType { + FOLDER, + ZIP +} \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupImpl.kt b/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupImpl.kt index e8c403cf..6d45396d 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupImpl.kt @@ -12,11 +12,11 @@ import kr.toxicity.hud.manager.* import kr.toxicity.hud.shader.GuiLocation import kr.toxicity.hud.util.* import org.bukkit.configuration.ConfigurationSection -import java.io.File -import java.util.UUID +import java.util.* +import kotlin.collections.ArrayList class PopupImpl( - file: File, + file: List, val internalName: String, section: ConfigurationSection ): Popup { @@ -51,7 +51,9 @@ class PopupImpl( } ?: PopupSortType.LAST private val layouts = section.getConfigurationSection("layouts")?.let { - val target = file.subFolder(internalName) + val target = ArrayList(file).apply { + add(internalName) + } ArrayList().apply { it.forEachSubConfiguration { s, configurationSection -> val layout = configurationSection.getString("name").ifNull("name value not set.") @@ -67,7 +69,9 @@ class PopupImpl( configurationSection.getConfigurationSection("pixel")?.let { ImageLocation(it) } ?: ImageLocation.zero, - target.subFolder(s), + ArrayList(target).apply { + add(s) + }, )) } } diff --git a/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt b/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt index 7b13cda5..eac956fc 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt @@ -26,7 +26,6 @@ import kr.toxicity.hud.text.HudTextData import kr.toxicity.hud.util.* import net.kyori.adventure.key.Key import net.kyori.adventure.text.Component -import java.io.File import kotlin.math.roundToInt class PopupLayout( @@ -35,7 +34,7 @@ class PopupLayout( private val name: String, private val globalLocation: GuiLocation, private val globalPixel: ImageLocation, - file: File + file: List ) { private var imageChar = 0xCE000 private var textIndex = 0 @@ -43,14 +42,18 @@ class PopupLayout( private val imageKey = Key.key("$NAME_SPACE:popup/${parent.internalName}/$name/image") private val groups = parent.move.locations.run { val json = JsonArray() - val textFolder = file.subFolder("text") + val textFolder = ArrayList(file).apply { + add("text") + } val map = map { location -> PopupLayoutGroup(location, json, textFolder) } - PackGenerator.addTask { + PackGenerator.addTask(ArrayList(file).apply { + add("image.json") + }) { JsonObject().apply { add("providers", json) - }.save(File(file, "image.json")) + }.toByteArray() } map } @@ -74,7 +77,7 @@ class PopupLayout( } } - private inner class PopupLayoutGroup(pair: LocationGroup, val array: JsonArray, textFolder: File) { + private inner class PopupLayoutGroup(pair: LocationGroup, val array: JsonArray, textFolder: List) { val elements = layout.animation.location.map { location -> PopupElement(pair, array, location, textFolder) } @@ -89,7 +92,7 @@ class PopupLayout( } } } - private inner class PopupElement(pair: LocationGroup, val array: JsonArray, location: ImageLocation, textFolder: File) { + private inner class PopupElement(pair: LocationGroup, val array: JsonArray, location: ImageLocation, textFolder: List) { private val elementGui = pair.gui + parent.gui + globalLocation private val elementPixel = globalPixel + location @@ -257,10 +260,12 @@ class PopupLayout( ) } ) - PackGenerator.addTask { + PackGenerator.addTask(ArrayList(textFolder).apply { + add("text_${index}.json") + }) { JsonObject().apply { add("providers", array) - }.save(File(textFolder, "text_${index}.json")) + }.toByteArray() } TextManager.setKey(group, result) result diff --git a/dist/src/main/kotlin/kr/toxicity/hud/resource/GlobalResource.kt b/dist/src/main/kotlin/kr/toxicity/hud/resource/GlobalResource.kt index b69597b7..6a5d13a4 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/resource/GlobalResource.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/resource/GlobalResource.kt @@ -1,32 +1,32 @@ package kr.toxicity.hud.resource -import kr.toxicity.hud.manager.ConfigManager -import kr.toxicity.hud.manager.ShaderManager import kr.toxicity.hud.util.* -import org.bukkit.Bukkit -import org.bukkit.boss.BarColor -import org.bukkit.boss.BarStyle class GlobalResource { - private val accept = DATA_FOLDER.parentFile.subFolder(ConfigManager.buildFolderLocation).let { - if (ConfigManager.separateResourcePackNameSpace) it else it.subFolder("assets").clearFolder() - } + private val assets = listOf("assets") - private val hud = accept.subFolder(NAME_SPACE).clearFolder().apply { - PLUGIN.loadAssets(NAME_SPACE, this) + private val hud = ArrayList(assets).apply { + add(NAME_SPACE) } - private val minecraft = accept.subFolder("minecraft").clearFolder().apply { - PLUGIN.loadAssets("minecraft", this) + + private val minecraft = ArrayList(assets).apply { + add("minecraft") } - val bossBar = minecraft - .subFolder("textures") - .subFolder("gui") + val bossBar = ArrayList(minecraft).apply { + add("textures") + add("gui") + } - val core = minecraft - .subFolder("shaders") - .subFolder("core") + val core = ArrayList(minecraft).apply { + add("shaders") + add("core") + } - val font = hud.subFolder("font") - val textures = hud.subFolder("textures") + val font = ArrayList(hud).apply { + add("font") + } + val textures = ArrayList(hud).apply { + add("textures") + } } \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt b/dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt index 47e7ac04..74e2f8eb 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt @@ -33,7 +33,7 @@ fun File.forEachAllFolder(block: (File) -> Unit) { } } -fun File.forEachAllFolderAsync(block: (Int, File) -> Unit, callback: () -> Unit) { +fun File.forEachAllFolderAsync(block: (File) -> Unit, callback: () -> Unit) { fun getAll(file: File): List { return if (file.isDirectory) { file.listFiles()?.map { subFile -> @@ -46,20 +46,8 @@ fun File.forEachAllFolderAsync(block: (Int, File) -> Unit, callback: () -> Unit) getAll(this).forEachAsync(block, callback) } -fun File.forEachAsync(block: (Int, File) -> Unit, callback: () -> Unit) { - val list = listFiles() ?: return - val task = TaskIndex(list.size) - list.forEach { - CompletableFuture.runAsync { - block(task.current, it) - }.thenAccept { - synchronized(task) { - if (++task.current == task.max) { - callback() - } - } - } - } +fun File.forEachAsync(block: (File) -> Unit, callback: () -> Unit) { + listFiles()?.toList()?.forEachAsync(block, callback) ?: return callback() } fun File.forEachAllYaml(block: (File, String, ConfigurationSection) -> Unit) { @@ -76,12 +64,12 @@ fun File.forEachAllYaml(block: (File, String, ConfigurationSection) -> Unit) { } } } -fun File.forEachAllYamlAsync(block: (Int, File, String, ConfigurationSection) -> Unit, callback: () -> Unit) { - forEachAllFolderAsync({ i, it -> +fun File.forEachAllYamlAsync(block: (File, String, ConfigurationSection) -> Unit, callback: () -> Unit) { + forEachAllFolderAsync({ if (it.extension == "yml") { runCatching { it.toYaml().forEachSubConfiguration { s, configurationSection -> - block(i, it, s, configurationSection) + block(it, s, configurationSection) } }.onFailure { e -> warn("Unable to load this yml file: ${it.name}") diff --git a/dist/src/main/kotlin/kr/toxicity/hud/util/Gsons.kt b/dist/src/main/kotlin/kr/toxicity/hud/util/Gsons.kt index 452e6a08..4200e7e0 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/util/Gsons.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/util/Gsons.kt @@ -16,4 +16,9 @@ fun JsonElement.save(file: File) { JsonWriter(FileWriter(file, StandardCharsets.UTF_8).buffered()).use { GSON.toJson(this, it) } +} +fun JsonElement.toByteArray(): ByteArray { + val sb = StringBuilder() + GSON.toJson(this, sb) + return sb.toString().toByteArray(Charsets.UTF_8) } \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/hud/util/Images.kt b/dist/src/main/kotlin/kr/toxicity/hud/util/Images.kt index 83799e51..dbb6bc1a 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/util/Images.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/util/Images.kt @@ -6,6 +6,7 @@ import java.awt.Font import java.awt.font.FontRenderContext import java.awt.image.BufferedImage import java.awt.image.RenderedImage +import java.io.ByteArrayOutputStream import java.io.File import java.io.InputStream import java.io.OutputStream @@ -18,6 +19,13 @@ fun RenderedImage.save(outputStream: OutputStream) { ImageIO.write(this, "png", outputStream) } +fun RenderedImage.toByteArray(): ByteArray { + return ByteArrayOutputStream().use { + ImageIO.write(this, "png", it) + it + }.toByteArray() +} + fun File.toImage(): BufferedImage = ImageIO.read(this) fun InputStream.toImage(): BufferedImage = ImageIO.read(this) diff --git a/dist/src/main/kotlin/kr/toxicity/hud/util/Lists.kt b/dist/src/main/kotlin/kr/toxicity/hud/util/Lists.kt index 2e8997a1..c8d635ad 100644 --- a/dist/src/main/kotlin/kr/toxicity/hud/util/Lists.kt +++ b/dist/src/main/kotlin/kr/toxicity/hud/util/Lists.kt @@ -21,30 +21,20 @@ fun List>.sum(): List { return result } -fun List.forEachAsync(block: (Int, T) -> Unit, callback: () -> Unit) { - val current = TaskIndex(size) - if (isNotEmpty()) forEach { - CompletableFuture.runAsync { - block(current.current, it) - }.thenAccept { - synchronized(current) { - if (++current.current == current.max) { - callback() +fun Collection.forEachAsync(block: (T) -> Unit, callback: () -> Unit) { + if (isNotEmpty()) { + val current = TaskIndex(size) + forEach { + CompletableFuture.runAsync { + runCatching { + block(it) + }.onFailure { e -> + e.printStackTrace() } - } - } - } else callback() -} - -fun Set.forEachAsync(block: (Int, T) -> Unit, callback: () -> Unit) { - val current = TaskIndex(size) - if (isNotEmpty()) forEach { - CompletableFuture.runAsync { - block(current.current, it) - }.thenAccept { - synchronized(current) { - if (++current.current == current.max) { - callback() + synchronized(current) { + if (++current.current == current.max) { + callback() + } } } } diff --git a/dist/src/main/resources/config.yml b/dist/src/main/resources/config.yml index d2571ec5..ae7e569b 100644 --- a/dist/src/main/resources/config.yml +++ b/dist/src/main/resources/config.yml @@ -6,7 +6,8 @@ default-font-name: "font.ttf" merge-boss-bar: true disable-to-bedrock-player: true build-folder-location: "BetterHud/build" -separate-resource-pack-namespace: false + +pack-type: folder #folder, zip default-hud: - test_hud diff --git a/dist/src/main/resources/betterhud/font/legacy_space.json b/dist/src/main/resources/pack/assets/betterhud/font/legacy_space.json similarity index 100% rename from dist/src/main/resources/betterhud/font/legacy_space.json rename to dist/src/main/resources/pack/assets/betterhud/font/legacy_space.json diff --git a/dist/src/main/resources/betterhud/font/space.json b/dist/src/main/resources/pack/assets/betterhud/font/space.json similarity index 100% rename from dist/src/main/resources/betterhud/font/space.json rename to dist/src/main/resources/pack/assets/betterhud/font/space.json diff --git a/dist/src/main/resources/betterhud/font/spaces.ttf b/dist/src/main/resources/pack/assets/betterhud/font/spaces.ttf similarity index 100% rename from dist/src/main/resources/betterhud/font/spaces.ttf rename to dist/src/main/resources/pack/assets/betterhud/font/spaces.ttf diff --git a/dist/src/main/resources/betterhud/textures/font/splitter.png b/dist/src/main/resources/pack/assets/betterhud/textures/font/splitter.png similarity index 100% rename from dist/src/main/resources/betterhud/textures/font/splitter.png rename to dist/src/main/resources/pack/assets/betterhud/textures/font/splitter.png diff --git a/dist/src/main/resources/minecraft/shaders/core/rendertype_entity_cutout.json b/dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_entity_cutout.json similarity index 100% rename from dist/src/main/resources/minecraft/shaders/core/rendertype_entity_cutout.json rename to dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_entity_cutout.json diff --git a/dist/src/main/resources/minecraft/shaders/core/rendertype_entity_translucent_cull.json b/dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_entity_translucent_cull.json similarity index 100% rename from dist/src/main/resources/minecraft/shaders/core/rendertype_entity_translucent_cull.json rename to dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_entity_translucent_cull.json diff --git a/dist/src/main/resources/minecraft/shaders/core/rendertype_text.fsh b/dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_text.fsh similarity index 100% rename from dist/src/main/resources/minecraft/shaders/core/rendertype_text.fsh rename to dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_text.fsh diff --git a/dist/src/main/resources/minecraft/shaders/core/rendertype_text.json b/dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_text.json similarity index 100% rename from dist/src/main/resources/minecraft/shaders/core/rendertype_text.json rename to dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_text.json