diff --git a/src/main/java/org/holoeasy/line/BlockLine.kt b/src/main/java/org/holoeasy/line/BlockLine.kt index 21b38ba..f64ac52 100644 --- a/src/main/java/org/holoeasy/line/BlockLine.kt +++ b/src/main/java/org/holoeasy/line/BlockLine.kt @@ -8,12 +8,16 @@ import org.bukkit.inventory.ItemStack import org.bukkit.plugin.Plugin import org.holoeasy.ext.send import org.holoeasy.packet.IPacket +import org.holoeasy.reactive.MutableState + +class BlockLine(plugin: Plugin, obj: ItemStack) : ILine { -class BlockLine(plugin: Plugin, override var obj: ItemStack) : ILine { private val line: Line = Line(plugin, EntityType.DROPPED_ITEM) private val resetVelocity = IPacket.get(IPacket.Type.VELOCITY).velocity(line.entityID, 0, 0,0) + private val _mutableStateOf = MutableState(obj) + override val plugin: Plugin get() = line.plugin @@ -26,6 +30,12 @@ class BlockLine(plugin: Plugin, override var obj: ItemStack) : ILine override val location: Location? get() = line.location + override var obj : ItemStack + get() = _mutableStateOf.get() + set(value) = _mutableStateOf.set(value) + + override lateinit var pvt: ILine.PrivateConfig + 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 d3a7563..a10b020 100644 --- a/src/main/java/org/holoeasy/line/ClickableTextLine.kt +++ b/src/main/java/org/holoeasy/line/ClickableTextLine.kt @@ -69,6 +69,8 @@ class ClickableTextLine(private val line: TextLine, minHitDistance: Float, maxHi line.obj = value } + override var pvt: ILine.PrivateConfig = line.pvt + override fun setLocation(value: Location) { line.setLocation(value) this.updateHitBox() diff --git a/src/main/java/org/holoeasy/line/ILine.kt b/src/main/java/org/holoeasy/line/ILine.kt index 7aeacd7..2ad7d08 100644 --- a/src/main/java/org/holoeasy/line/ILine.kt +++ b/src/main/java/org/holoeasy/line/ILine.kt @@ -3,10 +3,22 @@ package org.holoeasy.line import org.bukkit.Location import org.bukkit.entity.Player import org.bukkit.plugin.Plugin +import org.holoeasy.hologram.Hologram +import org.holoeasy.reactive.Observer import org.jetbrains.annotations.ApiStatus interface ILine { + data class PrivateConfig(private val line: ILine<*>) : Observer { + + var hologram : Hologram? = null + override fun observerUpdate() { + hologram?.let { + line.update(it.seeingPlayers) + } + } + } + val plugin: Plugin val type: Type @@ -17,6 +29,8 @@ interface ILine { var obj: T + var pvt : PrivateConfig + fun setLocation(value: Location) fun hide(player: Player) diff --git a/src/main/java/org/holoeasy/line/TextLine.kt b/src/main/java/org/holoeasy/line/TextLine.kt index d9a08fa..adad372 100644 --- a/src/main/java/org/holoeasy/line/TextLine.kt +++ b/src/main/java/org/holoeasy/line/TextLine.kt @@ -15,6 +15,7 @@ class TextLine(plugin: Plugin, obj: String, override val args: Array? private val line: Line = Line(plugin, EntityType.ARMOR_STAND) + override var obj: String = "" var clickEvent : ClickEvent? = null @@ -60,6 +61,9 @@ class TextLine(plugin: Plugin, obj: String, override val args: Array? override val location: Location? get() = line.location + + override lateinit var pvt: ILine.PrivateConfig + override fun setLocation(value: Location) { line.location = value if (clickable) { diff --git a/src/main/java/org/holoeasy/reactive/MutableState.kt b/src/main/java/org/holoeasy/reactive/MutableState.kt new file mode 100644 index 0000000..8816d72 --- /dev/null +++ b/src/main/java/org/holoeasy/reactive/MutableState.kt @@ -0,0 +1,29 @@ +package org.holoeasy.reactive + +data class MutableState(private var value : T) { + + private val observers= mutableListOf() + + fun get() : T { + return value + } + + fun set(newValue : T) { + value = newValue + this.notifyObservers() + } + + fun addObserver(observer: Observer) { + observers.add(observer) + } + + fun removeObserver(observer: Observer) { + observers.remove(observer) + } + + private fun notifyObservers() { + for (observer in observers) { + observer.observerUpdate() + } + } +} diff --git a/src/main/java/org/holoeasy/reactive/Observer.kt b/src/main/java/org/holoeasy/reactive/Observer.kt new file mode 100644 index 0000000..162dfbb --- /dev/null +++ b/src/main/java/org/holoeasy/reactive/Observer.kt @@ -0,0 +1,5 @@ +package org.holoeasy.reactive + +interface Observer { + fun observerUpdate() +} \ No newline at end of file