diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/ContainerSyncListener.kt b/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/ContainerSyncListener.kt index 8035bec..370f6a2 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/ContainerSyncListener.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/ContainerSyncListener.kt @@ -1,14 +1,18 @@ package com.mineinabyss.deeperworld.synchronization +import com.github.shynixn.mccoroutine.bukkit.launch import com.mineinabyss.deeperworld.deeperWorld import com.mineinabyss.deeperworld.world.section.* import com.mineinabyss.idofront.messaging.info import com.mineinabyss.idofront.plugin.Plugins +import com.mineinabyss.idofront.time.ticks +import kotlinx.coroutines.delay import nl.rutgerkok.blocklocker.BlockLockerAPIv2 import nl.rutgerkok.blocklocker.SearchMode import org.bukkit.Chunk import org.bukkit.block.Block import org.bukkit.block.Container +import org.bukkit.block.DecoratedPot import org.bukkit.block.Lidded import org.bukkit.entity.Player import org.bukkit.event.EventHandler @@ -85,6 +89,21 @@ object ContainerSyncListener : Listener { } } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + fun PlayerInteractEvent.onDecoratedPotFill() { + val (block, pot) = (clickedBlock ?: return) to (clickedBlock?.state as? DecoratedPot ?: return) + if (action != Action.RIGHT_CLICK_BLOCK || player.isSneaking) return + + val section = block.location.section ?: return + val linkedSection = block.location.correspondingSection ?: return + val linkedBlock = block.location.getCorrespondingLocation(section, linkedSection)?.block?.state as? DecoratedPot ?: return + + deeperWorld.plugin.launch { + delay(1.ticks) + linkedBlock.inventory.contents = pot.inventory.contents + } + } + /** Removes the player from the [keepLoadedInventories] map */ @EventHandler fun InventoryCloseEvent.onCloseInventory() { diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/SectionSyncListener.kt b/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/SectionSyncListener.kt index 8cb62e6..5572b01 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/SectionSyncListener.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/synchronization/SectionSyncListener.kt @@ -28,6 +28,7 @@ import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.block.* +import org.bukkit.event.entity.EntityChangeBlockEvent import org.bukkit.event.entity.EntityExplodeEvent import org.bukkit.event.entity.EntitySpawnEvent import org.bukkit.event.player.PlayerBucketEmptyEvent @@ -220,6 +221,12 @@ object SectionSyncListener : Listener { block.sync(signUpdater(lines())) } + @EventHandler + fun EntityChangeBlockEvent.syncBlockChange() { + if (!block.location.inSectionOverlap) return + block.sync(updateBlockData(blockData)) + } + /** Removes Iron Golem and Wither summons in corresponding section location due to duping **/ @EventHandler fun EntitySpawnEvent.onEntitySummon() {