From be6c8b3f64c003962cc3336c5ff7b20a45f98a59 Mon Sep 17 00:00:00 2001 From: Boy Date: Fri, 18 Oct 2024 14:27:59 +0200 Subject: [PATCH] feat: sync items removed by void to corresponding section --- .../com/mineinabyss/deeperworld/DeeperConfig.kt | 2 -- .../deeperworld/listeners/MovementListener.kt | 1 - .../synchronization/SectionSyncListener.kt | 16 ++++++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt b/src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt index 8599050..d239740 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/DeeperConfig.kt @@ -27,8 +27,6 @@ data class DeeperWorldConfig( val damageOutsideSections: Double = 1.0, @YamlComment("Worlds which shouldn't damage players when outside of a section.") val damageExcludedWorlds: Set<@Serializable(with = WorldSerializer::class) World> = emptySet(), - @YamlComment("Sends an additional remount packet after this delay to prevent client-side mount bugs when moving between sections.\n") - val remountPacketDelay: Duration = 40.ticks, val fall: FallDamageConfig = FallDamageConfig(), val time: TimeConfig = TimeConfig(), ) { diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/listeners/MovementListener.kt b/src/main/kotlin/com/mineinabyss/deeperworld/listeners/MovementListener.kt index 79260d6..c61f492 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/listeners/MovementListener.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/listeners/MovementListener.kt @@ -40,4 +40,3 @@ object MovementListener : Listener { .forEach { MovementHandler.handleMovement(it, from, to) } } } - diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/SectionSyncListener.kt b/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/SectionSyncListener.kt index 116c88b..e2b8b0f 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/SectionSyncListener.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/SectionSyncListener.kt @@ -1,5 +1,6 @@ package com.mineinabyss.deeperworld.synchronization +import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent import com.github.shynixn.mccoroutine.bukkit.launch import com.mineinabyss.deeperworld.deeperWorld import com.mineinabyss.deeperworld.event.BlockSyncEvent @@ -8,6 +9,7 @@ import com.mineinabyss.deeperworld.world.section.correspondingLocation import com.mineinabyss.deeperworld.world.section.inSectionOverlap import com.mineinabyss.idofront.events.call import com.mineinabyss.idofront.plugin.Plugins +import com.mineinabyss.idofront.spawning.spawn import com.mineinabyss.idofront.time.ticks import kotlinx.coroutines.delay import net.kyori.adventure.text.Component @@ -24,6 +26,7 @@ import org.bukkit.block.data.type.Stairs import org.bukkit.block.data.type.TrapDoor import org.bukkit.block.sign.Side import org.bukkit.entity.EntityType +import org.bukkit.entity.Item import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener @@ -244,4 +247,17 @@ object SectionSyncListener : Listener { entity.world.getNearbyEntitiesByType(entityType.entityClass, corrLocation, 1.0).firstOrNull()?.remove() } + + /** Sync items removed by void to corresponding section */ + @EventHandler + fun EntityRemoveFromWorldEvent.onVoidRemoval() { + val item = (entity as? Item)?.takeIf { it.y < it.world.minHeight } ?: return + val corrLoc = item.location.apply { y = -240.0 }.correspondingLocation ?: return + corrLoc.spawn { + itemStack = item.itemStack + thrower = item.thrower + owner = item.owner + velocity = velocity + } + } }