forked from SteamWar/SteamWar
Apply temporary fix for rendering of the cursor
This commit is contained in:
-1
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.cannonCore
|
|||||||
|
|
||||||
import de.steamwar.bausystem.SWUtils
|
import de.steamwar.bausystem.SWUtils
|
||||||
import de.steamwar.command.SWCommand
|
import de.steamwar.command.SWCommand
|
||||||
import de.steamwar.linkage.Linked
|
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
object CannonCoreCommand : SWCommand("cannoncore") {
|
object CannonCoreCommand : SWCommand("cannoncore") {
|
||||||
|
|||||||
+18
-6
@@ -19,16 +19,19 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.cannonCore
|
package de.steamwar.bausystem.features.cannonCore
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem
|
||||||
import de.steamwar.bausystem.utils.ItemUtils
|
import de.steamwar.bausystem.utils.ItemUtils
|
||||||
import de.steamwar.core.SWPlayer
|
import de.steamwar.core.SWPlayer
|
||||||
import de.steamwar.inventory.SWItem
|
import de.steamwar.inventory.SWItem
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
import org.bukkit.event.player.PlayerItemHeldEvent
|
import org.bukkit.event.player.PlayerItemHeldEvent
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
|
||||||
object CannonCoreWand: Listener {
|
object CannonCoreWand : Listener {
|
||||||
val wandId = "CANNON_CORE_WAND"
|
val wandId = "CANNON_CORE_WAND"
|
||||||
val wandMaterial = Material.BREEZE_ROD
|
val wandMaterial = Material.BREEZE_ROD
|
||||||
|
|
||||||
@@ -41,10 +44,10 @@ object CannonCoreWand: Listener {
|
|||||||
|
|
||||||
val wand = SWItem(wandMaterial, title, lore, false, null)
|
val wand = SWItem(wandMaterial, title, lore, false, null)
|
||||||
val item = wand.itemStack
|
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)
|
return ItemUtils.isItem(itemStack, wandId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,12 +55,21 @@ object CannonCoreWand: Listener {
|
|||||||
fun onPlayerEquip(event: PlayerItemHeldEvent) {
|
fun onPlayerEquip(event: PlayerItemHeldEvent) {
|
||||||
val player = event.player
|
val player = event.player
|
||||||
val swPlayer = SWPlayer.of(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)
|
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)
|
EmptyCannonCoreWandDisplay(player)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-4
@@ -26,10 +26,11 @@ import org.bukkit.entity.Player
|
|||||||
|
|
||||||
class EmptyCannonCoreWandDisplay : SWPlayer.Component {
|
class EmptyCannonCoreWandDisplay : SWPlayer.Component {
|
||||||
val coresDisplay: CannonCoresDisplay
|
val coresDisplay: CannonCoresDisplay
|
||||||
val cursor: Cursor
|
var cursor: Cursor
|
||||||
|
|
||||||
constructor(owner: Player) {
|
constructor(owner: Player) {
|
||||||
coresDisplay = CannonCoresDisplay(owner)
|
coresDisplay = CannonCoresDisplay(owner)
|
||||||
|
SWPlayer.of(owner).setComponent(this)
|
||||||
|
|
||||||
cursor = Cursor(
|
cursor = Cursor(
|
||||||
coresDisplay.displayServer, owner, Material.GLASS, Material.COMMAND_BLOCK,
|
coresDisplay.displayServer, owner, Material.GLASS, Material.COMMAND_BLOCK,
|
||||||
@@ -39,11 +40,18 @@ class EmptyCannonCoreWandDisplay : SWPlayer.Component {
|
|||||||
) { location, hitEntity, action ->
|
) { location, hitEntity, action ->
|
||||||
print("Hello")
|
print("Hello")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SWPlayer.of(owner).setComponent(this)
|
override fun onMount(player: SWPlayer) {
|
||||||
|
coresDisplay.onMount(player)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUnmount(player: SWPlayer) {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user