diff --git a/README.MD b/README.MD index 32270f4..39376b0 100644 --- a/README.MD +++ b/README.MD @@ -17,19 +17,21 @@ HoloEasy is a simple, modern and high-performant Java and Kotlin Minecraft Holog com.github.unldenis holoeasy - 3.0.1 + 3.1.0 ``` #### Gradle ```kotlin -implementation("com.github.unldenis:holoeasy:3.0.1") +implementation("com.github.unldenis:holoeasy:3.1.0") ``` Make sure you include the repository as well. -### Start programming (Java) +## Start programming + +### Java ```java import static org.holoeasy.builder.HologramBuilder.*; @@ -40,8 +42,7 @@ IHologramPool pool = HoloEasy.startInteractivePool(plugin, 60, 0.5f, 5f); public void addHologram(Location location) { hologram(new HologramKey(pool, "unique-id-holo"), location, () -> { textline("Hello"); - textline("{} Stats", Player::getName); - textline("Score {} - {}", $ -> 0, $ -> 1); + textline("Score {} - {}", 0, 1); clickable("Click me").onClick(p -> { p.sendTitle(ChatColor.AQUA + "Hi", ChatColor.BOLD + "by HoloEasy", 20, 20, 20); @@ -51,7 +52,7 @@ public void addHologram(Location location) { } ``` -### Start programming (Kotlin) +### Kotlin ```kotlin import org.holoeasy.builder.HologramBuilder.* @@ -61,8 +62,7 @@ val pool = startInteractivePool(plugin, 60.0, 0.5f, 5f) fun addHologram(location: Location) { hologram(HologramKey(pool, "unique-id-holo"), location) { textline("Hello") - textline("{} Stats", Player::getName) - textline("Score {} - {}", { 0 }, { 1 }) + textline("Score {} - {}", 0, 1) clickable("Click me").onClick { it.sendTitle(ChatColor.AQUA + "Hi", ChatColor.BOLD + "by HoloEasy", 20, 20, 20) @@ -72,6 +72,45 @@ fun addHologram(location: Location) { } ``` +## Reactive Holograms +From 3.1.0 version, the parameters of the text lines **_can also be reactive_**. This means that you can update the line by simply calling the 'set' method to these. + +

+ holoeasy state video +

+ +> [!WARNING] +> Mutable states have no player information at this time. If you need to create a hologram for a specific player, it is recommended that you do **_not_** add it to a Pool. +### Java +```java +var clickCount = mutableStateOf(0); // can be any type + +var holo = hologram(new HologramKey(plugin, "unique-id-holo"), location, () -> { + textline("{}!", "Static"); + textline("Count: {}", clickCount); + clickable("Click me", 0.5f, 5f).onClick($ -> clickCount.set(clickCount.get() + 1)); +}); + +// It hasn't been added to a pool, so it's up to us to make it visible and hide it from players. It's better to use a pool because it's automatic and performs asynchronous operations. +// HologramKey decides whether to add it to a pool or not. +holo.show(player); +``` + +### Kotlin +```kotlin +val clickCount = mutableStateOf(0) // can be any type + +val holo = hologram(HologramKey(plugin, "unique-id-holo"), location) { + textline("{}!", "Static") + textline("Dynamic: {}", clickCount) + clickable("Click me", 0.5f, 5f).onClick { clickCount.set(clickCount.get() + 1)} +} + +// It hasn't been added to a pool, so it's up to us to make it visible and hide it from players. It's better to use a pool because it's automatic and performs asynchronous operations. +// HologramKey decides whether to add it to a pool or not. +holo.show(player) +``` + ## Ex (Hologram-Lib) Are you using a version older than 3.0.0? You can find the documentation here. diff --git a/pom.xml b/pom.xml index f0ab95d..5450c8b 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ org.holoeasy holoeasy - 3.0.1 + 3.1.0 1.8 @@ -131,6 +131,15 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + C:\Users\mehil\OneDrive\Desktop\Spigot 1.16.5\plugins + + + diff --git a/src/main/java/org/holoeasy/builder/HologramBuilder.java b/src/main/java/org/holoeasy/builder/HologramBuilder.java index a4e0ca6..c51c222 100644 --- a/src/main/java/org/holoeasy/builder/HologramBuilder.java +++ b/src/main/java/org/holoeasy/builder/HologramBuilder.java @@ -60,7 +60,7 @@ public static ITextLine clickable(@NotNull String text, float minHitDistance, fl @NotNull Object... args) { return getInstance().textline( text, - false, + true, minHitDistance, maxHitDistance, args.length == 0 ? null : args @@ -79,7 +79,7 @@ public static void customline(@NotNull ILine customLine) { getInstance().customLine(customLine); } - public static MutableState mutableStateOf(T initialValue) { + public static MutableState mutableStateOf(@NotNull T initialValue) { return new MutableState<>(initialValue); } } \ No newline at end of file diff --git a/src/main/java/org/holoeasy/builder/Service.kt b/src/main/java/org/holoeasy/builder/Service.kt index 3f4e398..8e9e322 100644 --- a/src/main/java/org/holoeasy/builder/Service.kt +++ b/src/main/java/org/holoeasy/builder/Service.kt @@ -6,6 +6,7 @@ import org.holoeasy.builder.interfaces.HologramConfigGroup import org.holoeasy.hologram.TextBlockStandardLoader import org.holoeasy.line.* import org.holoeasy.reactive.MutableState +import kotlin.math.min object Service { @@ -33,16 +34,19 @@ object Service { val holo = getStaticHolo() if (minHitDistance == null || maxHitDistance == null) { + if(holo.key.pool == null && clickable) { + throw IllegalStateException("This hologram is not in a pool,so use the method #clickable(text, minHitDistance, maxHitDistance)") + } + val textLine = TextLine(holo.key.plugin, text, clickable = clickable, args = args) holo.lines.add(textLine) return textLine - } else { - val textLine = TextLine(holo.key.plugin, text, clickable = false, args = args) - val clickableTextLine = ClickableTextLine(textLine, minHitDistance, maxHitDistance) - holo.lines.add(clickableTextLine) - return clickableTextLine - } + } + val textLine = TextLine(holo.key.plugin, text, clickable = false, args = args) + val clickableTextLine = ClickableTextLine(textLine, minHitDistance, maxHitDistance) + holo.lines.add(clickableTextLine) + return clickableTextLine } fun itemline(block: ItemStack) { diff --git a/src/main/java/org/holoeasy/line/BlockLine.kt b/src/main/java/org/holoeasy/line/BlockLine.kt index d98bc9d..84043aa 100644 --- a/src/main/java/org/holoeasy/line/BlockLine.kt +++ b/src/main/java/org/holoeasy/line/BlockLine.kt @@ -37,7 +37,7 @@ class BlockLine(plugin: Plugin, obj: MutableState) : ILine get() = _mutableStateOf.get() set(value) = _mutableStateOf.set(value) - override lateinit var pvt: ILine.PrivateConfig + override var pvt = ILine.PrivateConfig(this) override fun setLocation(value: Location) { line.location = value diff --git a/src/main/java/org/holoeasy/line/ClickableTextLine.kt b/src/main/java/org/holoeasy/line/ClickableTextLine.kt index 1969eb8..db84a32 100644 --- a/src/main/java/org/holoeasy/line/ClickableTextLine.kt +++ b/src/main/java/org/holoeasy/line/ClickableTextLine.kt @@ -68,7 +68,7 @@ class ClickableTextLine(private val line: TextLine, minHitDistance: Float, maxHi line.obj = value } - override var pvt: ILine.PrivateConfig = line.pvt + override var pvt = ILine.PrivateConfig(this) override fun setLocation(value: Location) { line.setLocation(value) @@ -119,9 +119,9 @@ class ClickableTextLine(private val line: TextLine, minHitDistance: Float, maxHi val dist = size * (chars / 2.0) hitbox = AABB( - AABB.Vec3D(-dist, -0.039, -dist), - AABB.Vec3D(dist, +0.039, dist) + AABB.Vec3D(-dist, -0.040, -dist), + AABB.Vec3D(dist, +0.040, dist) ) - hitbox!!.translate(fromLocation(location!!.clone().add(0.0, 2.42, 0.0))) + hitbox!!.translate(fromLocation(location!!.clone().add(0.0, 2.35, 0.0))) } } diff --git a/src/main/java/org/holoeasy/line/TextLine.kt b/src/main/java/org/holoeasy/line/TextLine.kt index ae93d37..fda70c0 100644 --- a/src/main/java/org/holoeasy/line/TextLine.kt +++ b/src/main/java/org/holoeasy/line/TextLine.kt @@ -71,7 +71,7 @@ class TextLine( get() = line.location - override lateinit var pvt: ILine.PrivateConfig + override var pvt = ILine.PrivateConfig(this) override fun setLocation(value: Location) { line.location = value @@ -81,10 +81,10 @@ class TextLine( val dist = size * (chars / 2.0) hitbox = AABB( - AABB.Vec3D(-dist, -0.039, -dist), - AABB.Vec3D(dist, +0.039, dist) + AABB.Vec3D(-dist, -0.040, -dist), + AABB.Vec3D(dist, +0.040, dist) ).also { - it.translate(AABB.Vec3D.fromLocation(value.clone().add(0.0, 2.42, 0.0))) + it.translate(AABB.Vec3D.fromLocation(value.clone().add(0.0, 2.35, 0.0))) } } } diff --git a/src/test/java/ExampleKotlin.kt b/src/test/java/ExampleKotlin.kt deleted file mode 100644 index 0aa119b..0000000 --- a/src/test/java/ExampleKotlin.kt +++ /dev/null @@ -1,24 +0,0 @@ -import org.bukkit.Location -import org.bukkit.plugin.Plugin -import org.holoeasy.HoloEasy.startInteractivePool -import org.holoeasy.builder.HologramBuilder.* -import org.holoeasy.config.HologramKey - - -data class ExampleKotlin(val plugin: Plugin) { - - // you can use a Pool or a org.bukkit.Plugin for HologramKey - val pool = startInteractivePool(plugin, 60.0, 0.5f, 5f) - - - fun addHologram(location: Location) { - val clickCount = mutableStateOf(0) - - hologram(HologramKey(pool, "unique-id-holo"), location) { - textline("Count: {}", clickCount) - clickable("Click me").onClick { clickCount.set(clickCount.get() + 1)} - } - - } - -} \ No newline at end of file diff --git a/state.gif b/state.gif new file mode 100644 index 0000000..6d19d45 Binary files /dev/null and b/state.gif differ