Fixed hologram bug

This commit is contained in:
Auxilor
2022-12-08 14:32:06 +00:00
parent ce43506e77
commit 4148b36e0f
3 changed files with 25 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ import com.willfp.ecocrates.converters.impl.SpecializedCratesConverter
import com.willfp.ecocrates.crate.CrateKeyListener
import com.willfp.ecocrates.crate.Crates
import com.willfp.ecocrates.crate.placed.CrateDisplay
import com.willfp.ecocrates.crate.placed.HologramBugFixer
import com.willfp.ecocrates.crate.placed.PlacedCrates
import com.willfp.ecocrates.display.KeyDisplay
import com.willfp.ecocrates.reward.Rewards
@@ -110,7 +111,8 @@ class EcoCratesPlugin : EcoPlugin() {
override fun loadListeners(): List<Listener> {
return listOf(
PlacedCrateListener(this),
CrateKeyListener()
CrateKeyListener(),
HologramBugFixer
)
}

View File

@@ -0,0 +1,17 @@
package com.willfp.ecocrates.crate.placed
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.world.ChunkUnloadEvent
object HologramBugFixer: Listener {
@EventHandler
fun handle(event: ChunkUnloadEvent) {
val chunk = event.chunk
for (crate in PlacedCrates.values()) {
if (crate.location.chunk == chunk) {
crate.handleChunkUnload()
}
}
}
}

View File

@@ -11,7 +11,7 @@ class PlacedCrate(
blockLocation: Location
) {
// Center the location, they're mutable because bukkit is bad at designing APIs.
private val location = blockLocation.clone().apply {
val location = blockLocation.clone().apply {
x += 0.5
y += 0.5
z += 0.5
@@ -42,6 +42,10 @@ class PlacedCrate(
item?.remove()
}
internal fun handleChunkUnload() {
hologram.remove()
}
private fun tickHolograms(tick: Int) {
var frameToShow: HologramFrame? = null