diff --git a/build.gradle.kts b/build.gradle.kts index 980df91..fa26752 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,3 +32,13 @@ dependencies { compileOnly(libs.blocky) compileOnly(libs.minecraft.plugin.axiompaper) } + +kotlin { + compilerOptions { + freeCompilerArgs.addAll( + "-opt-in=kotlinx.serialization.ExperimentalSerializationApi", + "-opt-in=kotlin.ExperimentalUnsignedTypes", + "-Xcontext-receivers" + ) + } +} diff --git a/gradle.properties b/gradle.properties index 150d390..a595d8d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss version=1.11 -idofrontVersion=0.25.5 +idofrontVersion=0.25.17-dev.2 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0c309b3..cd13ab2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -gearyPaper = "0.30.21" +gearyPaper = "0.31.0-dev.3" blocky = "0.10.9" [libraries] diff --git a/src/main/kotlin/com/mineinabyss/bonfire/BonfireAddon.kt b/src/main/kotlin/com/mineinabyss/bonfire/BonfireAddon.kt new file mode 100644 index 0000000..dac8550 --- /dev/null +++ b/src/main/kotlin/com/mineinabyss/bonfire/BonfireAddon.kt @@ -0,0 +1,15 @@ +package com.mineinabyss.bonfire + +import com.mineinabyss.bonfire.systems.bonfireEffectSystem +import com.mineinabyss.geary.addons.dsl.createAddon +import com.mineinabyss.geary.autoscan.autoscan + +val BonfireAddon = createAddon("Bonfire", configuration = { + autoscan(BonfirePlugin::class.java.classLoader, "com.mineinabyss.bonfire") { + all() + } +}) { + systems { + bonfireEffectSystem() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/mineinabyss/bonfire/BonfireCommands.kt b/src/main/kotlin/com/mineinabyss/bonfire/BonfireCommands.kt index 0509d09..92e88ec 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/BonfireCommands.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/BonfireCommands.kt @@ -10,11 +10,15 @@ import com.mineinabyss.geary.papermc.datastore.decode import com.mineinabyss.geary.papermc.datastore.encode import com.mineinabyss.geary.papermc.datastore.encodeComponentsTo import com.mineinabyss.geary.papermc.datastore.remove +import com.mineinabyss.geary.papermc.gearyPaper import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull +import com.mineinabyss.geary.papermc.withGeary import com.mineinabyss.geary.serialization.setPersisting -import com.mineinabyss.idofront.commands.brigadier.IdoCommandContext import com.mineinabyss.idofront.commands.brigadier.commands +import com.mineinabyss.idofront.commands.brigadier.context.IdoCommandContext +import com.mineinabyss.idofront.commands.brigadier.executes +import com.mineinabyss.idofront.commands.brigadier.playerExecutes import com.mineinabyss.idofront.messaging.error import com.mineinabyss.idofront.messaging.info import com.mineinabyss.idofront.messaging.success @@ -36,20 +40,21 @@ object BonfireCommands { "bonfire" { "debug" { playerExecutes { - with(player.toGeary()) { - when { - has() -> { - remove() - sender.error("Bonfire debug mode disabled") - } - else -> { - setPersisting(BonfireDebug()) - sender.success("Bonfire debug mode enabled") + player.withGeary { + with(player.toGeary()) { + when { + has() -> { + remove() + sender.error("Bonfire debug mode disabled") + } + else -> { + setPersisting(BonfireDebug()) + sender.success("Bonfire debug mode enabled") + } } + encodeComponentsTo(player) } - encodeComponentsTo(player) } - } } "reload" { @@ -59,61 +64,54 @@ object BonfireCommands { } } "players" { - fun IdoCommandContext.runPlayersCommand(location: Location) { - val bonfireLoc = location.toBlockCenterLocation() - val (x,y,z) = bonfireLoc.blockX to bonfireLoc.blockY to bonfireLoc.blockZ + playerExecutes( + ArgumentTypes.finePosition(true).suggests { + suggestFiltering("${location.blockX} ${location.blockY} ${location.blockZ}") + }.named("location"), + ) { location -> + val location = location.resolve(context.source).toLocation(player.world) + val (x,y,z) = location.blockX() to location.blockY() to location.blockZ() - location.world.getChunkAtAsync(location).thenAccept { - val bonfireEntity = bonfireLoc.getNearbyEntitiesByType(ItemDisplay::class.java, 5.0).firstOrNull() - bonfireEntity?.toGeary()?.get()?.let { bonfire -> - sender.info( - "Players with their respawn set at this bonfire: ${ - bonfire.bonfirePlayers.joinToString(", ") { Bukkit.getOfflinePlayer(it).name ?: "Unknown" } - }" - ) - } ?: sender.error("Could not find bonfire at $x $y $z") - } - } - - executes { context.source.executor?.location?.let { runPlayersCommand(it) } } - val location by ArgumentTypes.blockPosition().suggests { - (context.source.executor as? Player)?.location?.let { - suggestFiltering("${it.blockX} ${it.blockY} ${it.blockZ}") + location.world.getChunkAtAsync(location).thenAccept { chunk -> + chunk.addPluginChunkTicket(bonfire.plugin) + location.getNearbyEntitiesByType(ItemDisplay::class.java, 2.0) + .firstOrNull()?.toGeary()?.get()?.let { bonfire -> + val bonfireNames = bonfire.bonfirePlayers.joinToString(", ") { Bukkit.getOfflinePlayer(it).name ?: "Unknown" } + sender.info("Players with their respawn set at this bonfire: $bonfireNames") + } ?: sender.error("Could not find bonfire at $x $y $z") } } - executes { runPlayersCommand(location().toLocation(context.source.location.world)!!) } - val world by ArgumentTypes.world().suggests { - suggest(Bukkit.getWorlds().map { it.key.asString() }) - } - executes { runPlayersCommand(location().toLocation(world()!!)) } } + "respawn" { - val offlinePlayer by StringArgumentType.word() "get" { - executes { - val offlinePlayer = Bukkit.getOfflinePlayer(offlinePlayer()) + executes(StringArgumentType.word().named("offlinePlayer")) { offlinePlayer -> + val offlinePlayer = Bukkit.getOfflinePlayer(offlinePlayer) val respawn = when { offlinePlayer.isOnline -> offlinePlayer.player?.toGearyOrNull()?.get() - else -> offlinePlayer.getOfflinePDC()?.decode() - }?.bonfireLocation ?: return@executes sender.error("Could not find BonfireRespawn for the given Player") + else -> with(gearyPaper.worldManager.global) { + offlinePlayer.getOfflinePDC()?.decode() + } + }?.bonfireLocation + ?: return@executes sender.error("Could not find BonfireRespawn for the given Player") sender.info("Bonfire-Respawn for ${offlinePlayer.name} is at ${respawn.x}, ${respawn.y}, ${respawn.z} in ${respawn.world.name}") } } "set" { - val location by ArgumentTypes.blockPosition().suggests { - (context.source.executor as? Player)?.location?.let { - suggestFiltering("${it.blockX} ${it.blockY} ${it.blockZ}") - } - } - - fun IdoCommandContext.handleRespawnSet(offlinePlayer: OfflinePlayer, location: Location) { + playerExecutes( + StringArgumentType.word().named("offlinePlayer"), + ArgumentTypes.finePosition(true).suggests { + suggestFiltering("${location.blockX} ${location.blockY} ${location.blockZ}") + }.named("location"), + ) { offlinePlayer, location -> + val offlinePlayer = Bukkit.getOfflinePlayer(offlinePlayer) // Ensures the player has a datafile, aka joined the server before, so we can save the bonfire location - offlinePlayer.getOfflinePDC() ?: return sender.error("Could not find PDC for the given OfflinePlayer") - val world = location.world + offlinePlayer.getOfflinePDC() ?: return@playerExecutes sender.error("Could not find PDC for the given OfflinePlayer") + val location = location.resolve(context.source).toLocation(player.world) val bonfireLoc = location.toBlockCenterLocation() val (x,y,z) = bonfireLoc.blockX to bonfireLoc.blockY to bonfireLoc.blockZ - world.getChunkAtAsync(location).thenAccept { + player.world.getChunkAtAsync(location).thenAccept { val bonfireEntity = bonfireLoc.getNearbyEntitiesByType(ItemDisplay::class.java, 0.5).firstOrNull() bonfireEntity?.toGearyOrNull()?.get()?.let { bonfire -> @@ -122,32 +120,23 @@ object BonfireCommands { sender.error("Player is already registered to this bonfire") bonfire.bonfirePlayers.size >= bonfire.maxPlayerCount -> sender.error("Bonfire is full") - else -> { + else -> with(gearyPaper.worldManager.global) { offlinePlayer.editOfflinePDC { encode(BonfireRespawn(bonfireEntity.uniqueId, bonfireEntity.location)) } bonfire.bonfirePlayers += offlinePlayer.uniqueId bonfireEntity.updateBonfireState() BonfirePacketHelpers.sendAddonPacket(bonfireEntity) - sender.success("Set respawn point for ${offlinePlayer.name} to $x $y $z in ${world.name}") + sender.success("Set respawn point for ${offlinePlayer.name} to $x $y $z in ${player.world.name}") } } } ?: sender.error("Could not find bonfire at $x $y $z") } } - executes { - handleRespawnSet(Bukkit.getOfflinePlayer(offlinePlayer()), location().toLocation(context.source.location.world)) - } - val world by ArgumentTypes.world().suggests { - suggest(Bukkit.getWorlds().map { it.key.asString() }) - } - executes { - handleRespawnSet(Bukkit.getOfflinePlayer(offlinePlayer()), location().toLocation(world()!!)) - } } "remove" { - executes { - val offlinePlayer = Bukkit.getOfflinePlayer(offlinePlayer()) + executes(StringArgumentType.word().named("offlinePlayer")) { offlinePlayer -> + val offlinePlayer = Bukkit.getOfflinePlayer(offlinePlayer) val respawn = when { offlinePlayer.isOnline -> { val respawn = offlinePlayer.player?.toGearyOrNull()?.get() @@ -155,11 +144,13 @@ object BonfireCommands { respawn } else -> { - val pdc = offlinePlayer.getOfflinePDC() ?: return@executes sender.error("Could not find PDC for the given OfflinePlayer") - val respawn = pdc.decode() ?: return@executes sender.error("OfflinePlayer has no bonfire set") - pdc.remove() - offlinePlayer.saveOfflinePDC(pdc) - respawn + with(gearyPaper.worldManager.global) { + val pdc = offlinePlayer.getOfflinePDC() ?: return@executes sender.error("Could not find PDC for the given OfflinePlayer") + val respawn = pdc.decode() ?: return@executes sender.error("OfflinePlayer has no bonfire set") + pdc.remove() + offlinePlayer.saveOfflinePDC(pdc) + respawn + } } } ?: return@executes sender.error("Player has no respawn point set") diff --git a/src/main/kotlin/com/mineinabyss/bonfire/BonfirePlugin.kt b/src/main/kotlin/com/mineinabyss/bonfire/BonfirePlugin.kt index a8c9fe5..8c03360 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/BonfirePlugin.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/BonfirePlugin.kt @@ -8,8 +8,11 @@ import com.mineinabyss.bonfire.listeners.FixUntrackedBonfiresListener import com.mineinabyss.bonfire.listeners.PlayerListener import com.mineinabyss.bonfire.systems.bonfireEffectSystem import com.mineinabyss.geary.addons.GearyPhase +import com.mineinabyss.geary.addons.dsl.createAddon import com.mineinabyss.geary.autoscan.autoscan import com.mineinabyss.geary.modules.geary +import com.mineinabyss.geary.papermc.configure +import com.mineinabyss.geary.papermc.gearyPaper import com.mineinabyss.idofront.config.config import com.mineinabyss.idofront.di.DI import com.mineinabyss.idofront.messaging.ComponentLogger @@ -20,10 +23,8 @@ import org.bukkit.plugin.java.JavaPlugin class BonfirePlugin : JavaPlugin() { override fun onLoad() { registerBonfireContext() - geary { - autoscan(classLoader, "com.mineinabyss.bonfire") { - all() - } + gearyPaper.configure { + install(BonfireAddon) } } @@ -36,11 +37,6 @@ class BonfirePlugin : JavaPlugin() { DebugListener(), FixUntrackedBonfiresListener() ) - - geary.pipeline.runOnOrAfter(GearyPhase.INIT_SYSTEMS) { - geary.bonfireEffectSystem() - } - } fun registerBonfireContext() { diff --git a/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfireHelpers.kt b/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfireHelpers.kt index 3a63be5..be01931 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfireHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfireHelpers.kt @@ -9,7 +9,8 @@ import com.mineinabyss.bonfire.components.BonfireRemoved import com.mineinabyss.bonfire.components.BonfireRespawn import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import com.mineinabyss.geary.papermc.tracking.items.gearyItems +import com.mineinabyss.geary.papermc.tracking.items.ItemTracking +import com.mineinabyss.geary.papermc.withGeary import com.mineinabyss.idofront.entities.toPlayer import kotlinx.coroutines.delay import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket @@ -60,28 +61,31 @@ fun Player.removeOldBonfire() { * Updates the bonfire state for all players. */ fun ItemDisplay.updateBonfireState() { - val plugin = bonfire.plugin - val bonfire = toGearyOrNull()?.get() ?: return + withGeary { + val plugin = bonfire.plugin + val bonfire = toGearyOrNull()?.get() ?: return + val itemTracking = getAddon(ItemTracking) - when {// Set the base-furniture item to the correct state - bonfire.bonfirePlayers.isEmpty() -> { - this.brightness = toGearyOrNull()?.get()?.properties?.brightness - gearyItems.createItem(bonfire.states.unlit)?.let { setItemStack(it) } - } - else -> { - this.brightness = Display.Brightness(15, 15) - gearyItems.createItem(bonfire.states.lit)?.let { setItemStack(it) } + when {// Set the base-furniture item to the correct state + bonfire.bonfirePlayers.isEmpty() -> { + brightness = toGearyOrNull()?.get()?.properties?.brightness + itemTracking.createItem(bonfire.states.unlit)?.let { setItemStack(it) } + } + else -> { + brightness = Display.Brightness(15, 15) + itemTracking.createItem(bonfire.states.lit)?.let { setItemStack(it) } - // Set state via packets to 'set' for all online players currently at the bonfire - val stateItem = gearyItems.createItem(bonfire.states.set) ?: return - val metadataPacket = ClientboundSetEntityDataPacket(entityId, - listOf(SynchedEntityData.DataValue(23, EntityDataSerializers.ITEM_STACK, CraftItemStack.asNMSCopy(stateItem))) - ) + // Set state via packets to 'set' for all online players currently at the bonfire + val stateItem = itemTracking.createItem(bonfire.states.set) ?: return + val metadataPacket = ClientboundSetEntityDataPacket(entityId, + listOf(SynchedEntityData.DataValue(23, EntityDataSerializers.ITEM_STACK, CraftItemStack.asNMSCopy(stateItem))) + ) - plugin.launch { - delay(2.ticks) - bonfire.bonfirePlayers.mapNotNull { it.toPlayer()?.takeIf( { p -> p.canSee(this@updateBonfireState) }) }.forEach { - (it as CraftPlayer).handle.connection.send(metadataPacket) + plugin.launch { + delay(2.ticks) + bonfire.bonfirePlayers.mapNotNull { it.toPlayer()?.takeIf( { p -> p.canSee(this@updateBonfireState) }) }.forEach { + (it as CraftPlayer).handle.connection.send(metadataPacket) + } } } } diff --git a/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfirePacketHelpers.kt b/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfirePacketHelpers.kt index 02053ac..8f74950 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfirePacketHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfirePacketHelpers.kt @@ -1,19 +1,14 @@ package com.mineinabyss.bonfire.extensions -import com.github.shynixn.mccoroutine.bukkit.launch import com.mineinabyss.blocky.api.BlockyFurnitures.isBlockyFurniture import com.mineinabyss.blocky.helpers.FurnitureUUID -import com.mineinabyss.bonfire.bonfire import com.mineinabyss.bonfire.components.Bonfire import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull -import com.mineinabyss.geary.papermc.tracking.items.gearyItems -import com.mineinabyss.idofront.messaging.broadcast +import com.mineinabyss.geary.papermc.tracking.items.ItemTracking +import com.mineinabyss.geary.papermc.withGeary import com.mineinabyss.idofront.nms.aliases.NMSEntity import com.mineinabyss.idofront.nms.aliases.toNMS -import com.mineinabyss.idofront.time.ticks import it.unimi.dsi.fastutil.ints.IntList -import kotlinx.coroutines.delay -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket import net.minecraft.network.protocol.game.ClientboundBundlePacket import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket @@ -21,7 +16,6 @@ import net.minecraft.network.syncher.EntityDataSerializers import net.minecraft.network.syncher.SynchedEntityData import net.minecraft.world.entity.Display import net.minecraft.world.entity.EntityType -import org.bukkit.Location import org.bukkit.craftbukkit.entity.CraftPlayer import org.bukkit.craftbukkit.inventory.CraftItemStack import org.bukkit.entity.ItemDisplay @@ -58,7 +52,7 @@ object BonfirePacketHelpers { .apply(bonfireAddons::add).addonEntity val metadataPackets = bonfire.addons.mapNotNull { addon -> - val item = gearyItems.createItem(addon) ?: return@mapNotNull null + val item = player.withGeary { getAddon(ItemTracking) }.createItem(addon) ?: return@mapNotNull null ClientboundSetEntityDataPacket(addonEntity.id, listOf(SynchedEntityData.DataValue(23, EntityDataSerializers.ITEM_STACK, CraftItemStack.asNMSCopy(item))) ) diff --git a/src/main/kotlin/com/mineinabyss/bonfire/listeners/BonfireListener.kt b/src/main/kotlin/com/mineinabyss/bonfire/listeners/BonfireListener.kt index 0597839..b865475 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/listeners/BonfireListener.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/listeners/BonfireListener.kt @@ -17,8 +17,10 @@ import com.mineinabyss.geary.papermc.datastore.encodeComponentsTo import com.mineinabyss.geary.papermc.datastore.remove import com.mineinabyss.geary.papermc.features.common.cooldowns.Cooldowns import com.mineinabyss.geary.papermc.features.common.cooldowns.StartCooldown +import com.mineinabyss.geary.papermc.gearyPaper import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull +import com.mineinabyss.geary.papermc.withGeary import com.mineinabyss.geary.serialization.setPersisting import com.mineinabyss.idofront.entities.toOfflinePlayer import com.mineinabyss.idofront.entities.toPlayer @@ -29,6 +31,7 @@ import com.mineinabyss.idofront.nms.nbt.getOfflinePDC import com.mineinabyss.idofront.plugin.Plugins import com.moulberry.axiom.event.AxiomManipulateEntityEvent import org.bukkit.Bukkit +import org.bukkit.OfflinePlayer import org.bukkit.attribute.Attribute import org.bukkit.entity.ItemDisplay import org.bukkit.event.EventHandler @@ -60,7 +63,9 @@ class BonfireListener : Listener { gearyEntity.setPersisting(bonfire.copy(bonfireOwner = player.uniqueId, bonfirePlayers = mutableListOf())) gearyEntity.setPersisting(BonfireExpirationTime(0.seconds, currentTime())) - gearyEntity.encodeComponentsTo(baseEntity) + baseEntity.withGeary { + gearyEntity.encodeComponentsTo(baseEntity) + } baseEntity.updateBonfireState() } @@ -89,7 +94,9 @@ class BonfireListener : Listener { } else Unit } } - gearyEntity.encodeComponentsTo(baseEntity) // Ensure data is saved to PDC + baseEntity.withGeary { + gearyEntity.encodeComponentsTo(baseEntity) // Ensure data is saved to PDC + } } } @@ -139,8 +146,10 @@ class BonfireListener : Listener { } } - gearyBonfire.encodeComponentsTo(baseEntity) // Ensure data is saved to PDC - gearyPlayer.encodeComponentsTo(player) + player.withGeary { + gearyBonfire.encodeComponentsTo(baseEntity) // Ensure data is saved to PDC + gearyPlayer.encodeComponentsTo(player) + } baseEntity.updateBonfireState() BonfirePacketHelpers.sendAddonPacket(baseEntity) } @@ -162,7 +171,7 @@ class BonfireListener : Listener { val offlinePlayer = Bukkit.getOfflinePlayer(it) val respawn = when { offlinePlayer.isOnline -> offlinePlayer.player?.toGearyOrNull()?.get() - else -> offlinePlayer.getOfflinePDC()?.decode() + else -> withGeary { offlinePlayer.getOfflinePDC()?.decode() } } respawn?.bonfireUuid == this.uniqueId } @@ -187,10 +196,12 @@ class BonfireListener : Listener { if (online != null) with(online.toGeary()) { remove() remove() - encodeComponentsTo(online) + online.withGeary { encodeComponentsTo(online) } } else offline.editOfflinePDC { - encode(BonfireRemoved()) - remove() + with(gearyPaper.worldManager.global) { + encode(BonfireRemoved()) + remove() + } } } } @@ -207,9 +218,11 @@ class BonfireListener : Listener { bonfireData.bonfirePlayers.map { it.toOfflinePlayer() to it.toPlayer() }.forEach { (offline, online) -> if (online != null) with(online.toGeary()) { get()?.copy(bonfireLocation = entity.location)?.let { setPersisting(it) } - encodeComponentsTo(online) + online.withGeary { encodeComponentsTo(online) } } else offline.editOfflinePDC { - decode()?.copy(bonfireLocation = entity.location)?.let { encode(it) } + with(gearyPaper.worldManager.global) { + decode()?.copy(bonfireLocation = entity.location)?.let { encode(it) } + } } } BonfirePacketHelpers.sendAddonPacket(furniture) diff --git a/src/main/kotlin/com/mineinabyss/bonfire/listeners/FixUntrackedBonfiresListener.kt b/src/main/kotlin/com/mineinabyss/bonfire/listeners/FixUntrackedBonfiresListener.kt index 7a5e6a6..73b67eb 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/listeners/FixUntrackedBonfiresListener.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/listeners/FixUntrackedBonfiresListener.kt @@ -8,6 +8,7 @@ import com.mineinabyss.geary.modules.geary import com.mineinabyss.geary.papermc.datastore.decodePrefabs import com.mineinabyss.geary.papermc.datastore.hasComponentsEncoded import com.mineinabyss.geary.papermc.tracking.entities.events.GearyEntityAddToWorldEvent +import com.mineinabyss.geary.papermc.withGeary import com.mineinabyss.geary.prefabs.PrefabKey import org.bukkit.Bukkit import org.bukkit.entity.ItemDisplay @@ -23,8 +24,7 @@ class FixUntrackedBonfiresListener : Listener { fun ChunkLoadEvent.onAddToWorld() { chunk.entities.filterIsInstance().forEach { entity -> if (entity.persistentDataContainer.hasComponentsEncoded) return@forEach - val displayItemPDC = entity.itemStack.itemMeta?.persistentDataContainer ?: return - val itemPrefabs = displayItemPDC.decodePrefabs() + val itemPrefabs = entity.withGeary { entity.itemStack.itemMeta?.persistentDataContainer?.decodePrefabs() ?: return } if (bonfireItemKey in itemPrefabs || bonfireLitItemKey in itemPrefabs) { Bukkit.getScheduler().scheduleSyncDelayedTask(bonfire.plugin, { diff --git a/src/main/kotlin/com/mineinabyss/bonfire/listeners/PlayerListener.kt b/src/main/kotlin/com/mineinabyss/bonfire/listeners/PlayerListener.kt index 5f1e355..0cf54cb 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/listeners/PlayerListener.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/listeners/PlayerListener.kt @@ -12,6 +12,7 @@ import com.mineinabyss.bonfire.extensions.updateBonfireState import com.mineinabyss.geary.papermc.datastore.remove import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull +import com.mineinabyss.geary.papermc.withGeary import com.mineinabyss.idofront.entities.rightClicked import com.mineinabyss.idofront.messaging.error import com.mineinabyss.idofront.messaging.info @@ -99,6 +100,6 @@ class PlayerListener : Listener { @EventHandler fun PlayerQuitEvent.onPlayerQuit() { - player.persistentDataContainer.remove() + player.withGeary { player.persistentDataContainer.remove() } } } diff --git a/src/main/kotlin/com/mineinabyss/bonfire/systems/BonfireEffectSystem.kt b/src/main/kotlin/com/mineinabyss/bonfire/systems/BonfireEffectSystem.kt index 4eedab8..e5ca734 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/systems/BonfireEffectSystem.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/systems/BonfireEffectSystem.kt @@ -3,16 +3,14 @@ package com.mineinabyss.bonfire.systems import com.mineinabyss.bonfire.bonfire import com.mineinabyss.bonfire.components.BonfireEffectArea import com.mineinabyss.bonfire.extensions.isBonfire -import com.mineinabyss.geary.autoscan.AutoScan -import com.mineinabyss.geary.modules.GearyModule -import com.mineinabyss.geary.systems.builders.system +import com.mineinabyss.geary.modules.Geary import com.mineinabyss.geary.systems.query.Query import com.mineinabyss.idofront.time.ticks import org.bukkit.Particle import org.bukkit.entity.ItemDisplay import org.bukkit.entity.Player -fun GearyModule.bonfireEffectSystem() = system(object : Query() { +fun Geary.bonfireEffectSystem() = system(object : Query(this) { val player by get() val effect by get() }).every(10.ticks).exec {