Skip to content

Commit

Permalink
fix: sync Decorated Pot inventories
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jul 23, 2024
1 parent 4ded7e5 commit ab72406
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ab72406

Please sign in to comment.