From f2b086dc867ee13a0dcd93b175a3cd9089c58650 Mon Sep 17 00:00:00 2001 From: Tech Date: Tue, 1 Aug 2023 09:03:57 -0400 Subject: [PATCH] fix: allow for backwards compatibility with GUIs --- README.md | 9 ++------- build.gradle.kts | 2 +- src/main/kotlin/me/tech/mcchestui/GUIItem.kt | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 090ccec..fb8340e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ repositories { } dependencies { - implementation("com.github.DebitCardz:mc-chestui-plus:1.0.0") + implementation("com.github.DebitCardz:mc-chestui-plus:1.0.1") } ``` ### Maven @@ -31,16 +31,11 @@ dependencies { com.github.DebitCardz mc-chestui-plus - 1.0.0 + 1.0.1 ``` -## Supported Versions -* 1.19.4 -* 1.20 -* 1.20.1 - *ChestUI+ will only work properly on versions 1.19.4 and above due to issues with Kyori Components.* # Changes From Original diff --git a/build.gradle.kts b/build.gradle.kts index 571e2a8..cc326cb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ val githubActor = project.findProperty("gpr.user") as String? ?: System.getenv(" val githubToken = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") group = "me.tech" -version = "1.0.0" +version = "1.0.1" repositories { mavenCentral() diff --git a/src/main/kotlin/me/tech/mcchestui/GUIItem.kt b/src/main/kotlin/me/tech/mcchestui/GUIItem.kt index 40df641..788b9b9 100644 --- a/src/main/kotlin/me/tech/mcchestui/GUIItem.kt +++ b/src/main/kotlin/me/tech/mcchestui/GUIItem.kt @@ -68,7 +68,7 @@ class GUIItem( get() = itemMeta.displayName() set(value) { val name = if(removeParentItalics) { - value?.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE) + value?.let { removeComponentParentItalics(it) } } else { value } @@ -85,7 +85,7 @@ class GUIItem( get() = itemMeta.lore() set(value) { val lore = if(removeParentItalics) { - value?.map { it.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE) } + value?.map { removeComponentParentItalics(it) } } else { value } @@ -163,6 +163,22 @@ class GUIItem( } } + /** + * Remove the italics of a [Component] if it is not already + * set on the [Component]. + * @param component to remove from. + * @return converted component. + */ + // we have to basically remake decorationIfAbsent because of issues with + // backwards compatibility. + private fun removeComponentParentItalics(component: Component): Component { + if(component.decoration(TextDecoration.ITALIC) == TextDecoration.State.NOT_SET) { + return component.decoration(TextDecoration.ITALIC, false) + } + + return component + } + /** * Sanitize the input lore to remove trailing new line breaks. * @param lore to be sanitized.