Skip to content

Commit

Permalink
feat: add Axiom Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Oct 11, 2024
1 parent 946b5c7 commit 70e521d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ dependencies {

// Other plugins
compileOnly(libs.blocky)
compileOnly(libs.minecraft.plugin.axiompaper)
}
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -177,22 +180,41 @@ class BonfireListener : Listener {
*/
@EventHandler
fun EntityRemoveFromWorldEvent.onRemoveBonfire() {
val bonfireData = (entity as? ItemDisplay).takeIf { entity.isDead }?.toGearyOrNull()?.get<Bonfire>() ?: return
val itemDisplay = entity as? ItemDisplay ?: return
val bonfireData = itemDisplay.takeIf { entity.isDead }?.toGearyOrNull()?.get<Bonfire>() ?: 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<BonfireEffectArea>()
remove<BonfireRespawn>()
encodeComponentsTo(onlinePlayer)
} else {
p.editOfflinePDC {
encode(BonfireRemoved())
remove<BonfireRespawn>()
}
encodeComponentsTo(online)
} else offline.editOfflinePDC {
encode(BonfireRemoved())
remove<BonfireRespawn>()
}
}
}

init {
if (Plugins.isEnabled("AxiomPaper")) {
Bukkit.getPluginManager().registerEvents(object : Listener {

@EventHandler
fun AxiomManipulateEntityEvent.manipulateBonfire() {
val bonfireData = (entity as? ItemDisplay).takeUnless { entity.isDead }?.toGearyOrNull()?.get<Bonfire>() ?: return

bonfireData.bonfirePlayers.map { it.toOfflinePlayer() to it.toPlayer() }.forEach { (offline, online) ->
if (online != null) with(online.toGeary()) {
get<BonfireRespawn>()?.copy(bonfireLocation = entity.location)?.let { setPersisting(it) }
encodeComponentsTo(online)
} else offline.editOfflinePDC {
decode<BonfireRespawn>()?.copy(bonfireLocation = entity.location)?.let { encode(it) }
}
}
}
}, bonfire.plugin)
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ dependencies:
required: false
load: BEFORE
join-classpath: true
AxiomPaper:
required: false
load: BEFORE
join-classpath: true

0 comments on commit 70e521d

Please sign in to comment.