From 70e521db789db219dcddbf875260241fadb9067c Mon Sep 17 00:00:00 2001 From: Boy Date: Fri, 11 Oct 2024 14:20:22 +0200 Subject: [PATCH] feat: add Axiom Compatibility --- build.gradle.kts | 1 + gradle/libs.versions.toml | 5 ++- .../bonfire/extensions/BonfireHelpers.kt | 3 +- .../bonfire/listeners/BonfireListener.kt | 44 ++++++++++++++----- src/main/resources/paper-plugin.yml | 4 ++ 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ff6477a..980df91 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,4 +30,5 @@ dependencies { // Other plugins compileOnly(libs.blocky) + compileOnly(libs.minecraft.plugin.axiompaper) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 62e92c8..0c309b3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,8 @@ [versions] -gearyPaper = "0.30.17" -blocky = "0.10.6" +gearyPaper = "0.30.21" +blocky = "0.10.9" [libraries] geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" } blocky = { module = "com.mineinabyss:blocky", version.ref = "blocky" } +minecraft-plugin-axiompaper = "com.moulberry:axiom:4.0.1" diff --git a/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfireHelpers.kt b/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfireHelpers.kt index f242f4a..389341e 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfireHelpers.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/extensions/BonfireHelpers.kt @@ -4,7 +4,6 @@ import com.github.shynixn.mccoroutine.bukkit.launch import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher import com.github.shynixn.mccoroutine.bukkit.ticks import com.mineinabyss.blocky.components.core.BlockyFurniture -import com.mineinabyss.blocky.helpers.FurniturePacketHelpers.ITEM_DISPLAY_ITEMSTACK_ID import com.mineinabyss.bonfire.components.Bonfire import com.mineinabyss.bonfire.components.BonfireRemoved import com.mineinabyss.bonfire.components.BonfireRespawn @@ -78,7 +77,7 @@ fun ItemDisplay.updateBonfireState() { // 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(ITEM_DISPLAY_ITEMSTACK_ID, EntityDataSerializers.ITEM_STACK, CraftItemStack.asNMSCopy(stateItem))) + listOf(SynchedEntityData.DataValue(23, EntityDataSerializers.ITEM_STACK, CraftItemStack.asNMSCopy(stateItem))) ) com.mineinabyss.bonfire.bonfire.plugin.launch(com.mineinabyss.bonfire.bonfire.plugin.minecraftDispatcher) { diff --git a/src/main/kotlin/com/mineinabyss/bonfire/listeners/BonfireListener.kt b/src/main/kotlin/com/mineinabyss/bonfire/listeners/BonfireListener.kt index 85c5849..d5c9425 100644 --- a/src/main/kotlin/com/mineinabyss/bonfire/listeners/BonfireListener.kt +++ b/src/main/kotlin/com/mineinabyss/bonfire/listeners/BonfireListener.kt @@ -24,10 +24,13 @@ import com.mineinabyss.geary.papermc.tracking.entities.toGeary import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull import com.mineinabyss.geary.serialization.setPersisting import com.mineinabyss.idofront.entities.toOfflinePlayer +import com.mineinabyss.idofront.entities.toPlayer import com.mineinabyss.idofront.messaging.error import com.mineinabyss.idofront.messaging.success import com.mineinabyss.idofront.nms.nbt.editOfflinePDC 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.attribute.Attribute import org.bukkit.entity.ItemDisplay @@ -177,22 +180,41 @@ class BonfireListener : Listener { */ @EventHandler fun EntityRemoveFromWorldEvent.onRemoveBonfire() { - val bonfireData = (entity as? ItemDisplay).takeIf { entity.isDead }?.toGearyOrNull()?.get() ?: return + val itemDisplay = entity as? ItemDisplay ?: return + val bonfireData = itemDisplay.takeIf { entity.isDead }?.toGearyOrNull()?.get() ?: return - BlockyFurnitures.removeFurniture(entity as ItemDisplay) + BlockyFurnitures.removeFurniture(itemDisplay) - bonfireData.bonfirePlayers.map { it.toOfflinePlayer() }.forEach { p -> - val onlinePlayer = p.player - if (onlinePlayer != null) with(onlinePlayer.toGeary()) { + bonfireData.bonfirePlayers.map { it.toOfflinePlayer() to it.toPlayer() }.forEach { (offline, online) -> + if (online != null) with(online.toGeary()) { remove() remove() - encodeComponentsTo(onlinePlayer) - } else { - p.editOfflinePDC { - encode(BonfireRemoved()) - remove() - } + encodeComponentsTo(online) + } else offline.editOfflinePDC { + encode(BonfireRemoved()) + remove() } } } + + init { + if (Plugins.isEnabled("AxiomPaper")) { + Bukkit.getPluginManager().registerEvents(object : Listener { + + @EventHandler + fun AxiomManipulateEntityEvent.manipulateBonfire() { + val bonfireData = (entity as? ItemDisplay).takeUnless { entity.isDead }?.toGearyOrNull()?.get() ?: return + + 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) + } else offline.editOfflinePDC { + decode()?.copy(bonfireLocation = entity.location)?.let { encode(it) } + } + } + } + }, bonfire.plugin) + } + } } diff --git a/src/main/resources/paper-plugin.yml b/src/main/resources/paper-plugin.yml index 9247e03..15d6935 100644 --- a/src/main/resources/paper-plugin.yml +++ b/src/main/resources/paper-plugin.yml @@ -27,3 +27,7 @@ dependencies: required: false load: BEFORE join-classpath: true + AxiomPaper: + required: false + load: BEFORE + join-classpath: true