Apply temporary fix for rendering of the cursor

This commit is contained in:
D4rkr34lm
2026-06-17 22:29:44 +02:00
parent 99f7610d3d
commit 24a7dae6d8
3 changed files with 30 additions and 11 deletions
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.cannonCore
import de.steamwar.bausystem.SWUtils
import de.steamwar.command.SWCommand
import de.steamwar.linkage.Linked
import org.bukkit.entity.Player
object CannonCoreCommand : SWCommand("cannoncore") {
@@ -19,16 +19,19 @@
package de.steamwar.bausystem.features.cannonCore
import de.steamwar.bausystem.BauSystem
import de.steamwar.bausystem.utils.ItemUtils
import de.steamwar.core.SWPlayer
import de.steamwar.inventory.SWItem
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerItemHeldEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.plugin.java.JavaPlugin
object CannonCoreWand: Listener {
object CannonCoreWand : Listener {
val wandId = "CANNON_CORE_WAND"
val wandMaterial = Material.BREEZE_ROD
@@ -41,10 +44,10 @@ object CannonCoreWand: Listener {
val wand = SWItem(wandMaterial, title, lore, false, null)
val item = wand.itemStack
return ItemUtils.setItem(item, wandId)
return ItemUtils.setItem(item, wandId)
}
fun isWandItem(itemStack: ItemStack): Boolean {
fun isWandItem(itemStack: ItemStack?): Boolean {
return ItemUtils.isItem(itemStack, wandId)
}
@@ -52,12 +55,21 @@ object CannonCoreWand: Listener {
fun onPlayerEquip(event: PlayerItemHeldEvent) {
val player = event.player
val swPlayer = SWPlayer.of(event.player)
val item = player.inventory.getItem(event.newSlot) ?: return
val item = player.inventory.getItem(event.newSlot)
if(!isWandItem(item)) {
if (isWandItem(item)) {
scheduleDisplayUpdate(player)
} else {
swPlayer.removeComponent(EmptyCannonCoreWandDisplay::class.java)
}
else {
}
private fun scheduleDisplayUpdate(player: Player) {
BauSystem.runTaskLater(JavaPlugin.getPlugin(BauSystem::class.java), Runnable { updateDisplay(player) }, 2)
}
private fun updateDisplay(player: Player) {
if (isWandItem(player.inventory.itemInMainHand)) {
EmptyCannonCoreWandDisplay(player)
}
}
@@ -26,10 +26,11 @@ import org.bukkit.entity.Player
class EmptyCannonCoreWandDisplay : SWPlayer.Component {
val coresDisplay: CannonCoresDisplay
val cursor: Cursor
var cursor: Cursor
constructor(owner: Player) {
coresDisplay = CannonCoresDisplay(owner)
SWPlayer.of(owner).setComponent(this)
cursor = Cursor(
coresDisplay.displayServer, owner, Material.GLASS, Material.COMMAND_BLOCK,
@@ -39,11 +40,18 @@ class EmptyCannonCoreWandDisplay : SWPlayer.Component {
) { location, hitEntity, action ->
print("Hello")
}
}
SWPlayer.of(owner).setComponent(this)
override fun onMount(player: SWPlayer) {
coresDisplay.onMount(player)
}
override fun onUnmount(player: SWPlayer) {
player.removeComponent(cursor::class.java)
player.getComponent(Cursor::class.java)
.filter { it === cursor }
.ifPresent { player.removeComponent(Cursor::class.java) }
coresDisplay.onUnmount(player)
}
}
}