Skip to content

Commit

Permalink
fix: allow for backwards compatibility with GUIs
Browse files Browse the repository at this point in the history
  • Loading branch information
DebitCardz committed Aug 1, 2023
1 parent 8db0796 commit f2b086d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,16 +31,11 @@ dependencies {
<dependency>
<groupId>com.github.DebitCardz</groupId>
<artifactId>mc-chestui-plus</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>

```

## 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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 18 additions & 2 deletions src/main/kotlin/me/tech/mcchestui/GUIItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f2b086d

Please sign in to comment.