From 84c4252592fddfe850ee85cf7e3300f2ea0b60f4 Mon Sep 17 00:00:00 2001 From: Hare Date: Sat, 20 Dec 2025 01:56:22 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=82=B3=E3=83=B3=E3=83=86=E3=83=8A?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/hareworks/hcu/shop/ShopVisuals.kt | 25 +++++++++++++------ .../hcu/shop/listeners/ShopListener.kt | 18 ++++++------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/net/hareworks/hcu/shop/ShopVisuals.kt b/src/main/kotlin/net/hareworks/hcu/shop/ShopVisuals.kt index a2eca69..f39ef97 100644 --- a/src/main/kotlin/net/hareworks/hcu/shop/ShopVisuals.kt +++ b/src/main/kotlin/net/hareworks/hcu/shop/ShopVisuals.kt @@ -9,6 +9,14 @@ import org.bukkit.block.sign.Side import org.bukkit.plugin.java.JavaPlugin object ShopVisuals { + val VALID_CONTAINERS = setOfNotNull( + org.bukkit.Material.CHEST, + org.bukkit.Material.TRAPPED_CHEST, + org.bukkit.Material.BARREL, + org.bukkit.Material.DECORATED_POT, + org.bukkit.Material.COPPER_CHEST + ) + fun updateSign(plugin: JavaPlugin, block: org.bukkit.block.Block, shopData: ShopData, side: Side) { val state = block.state as? Sign ?: return val signSide = state.getSide(side) @@ -46,10 +54,11 @@ object ShopVisuals { // L3: (Empty) // L4: (Gray) - signSide.line(0, Component.text(itemName, NamedTextColor.AQUA)) - signSide.line(1, Component.text("x$amount - $priceStr", NamedTextColor.BLACK)) - signSide.line(2, Component.empty()) + signSide.line(0, Component.empty()) + signSide.line(1, Component.text(itemName, NamedTextColor.AQUA)) + signSide.line(2, Component.text("x$amount - $priceStr", NamedTextColor.BLACK)) signSide.line(3, Component.text(ownerName, NamedTextColor.GRAY)) + signSide.isGlowingText = true // Update the sign immediately state.isWaxed = true // Force lock visually @@ -58,11 +67,13 @@ object ShopVisuals { fun calculateStock(block: org.bukkit.block.Block, item: org.bukkit.inventory.ItemStack?): Int { if (item == null) return 0 - val chestBlock = block.getRelative(org.bukkit.block.BlockFace.DOWN) - if (chestBlock.type != org.bukkit.Material.CHEST) return 0 + val downBlock = block.getRelative(org.bukkit.block.BlockFace.DOWN) - val chest = chestBlock.state as? org.bukkit.block.Chest ?: return 0 - val inventory = chest.inventory + if (downBlock.type !in VALID_CONTAINERS) return 0 + + // Use InventoryHolder to support Chests, Barrels, etc. + val container = downBlock.state as? org.bukkit.inventory.InventoryHolder ?: return 0 + val inventory = container.inventory var count = 0 for (i in 0 until inventory.size) { diff --git a/src/main/kotlin/net/hareworks/hcu/shop/listeners/ShopListener.kt b/src/main/kotlin/net/hareworks/hcu/shop/listeners/ShopListener.kt index a318aad..c8bb61c 100644 --- a/src/main/kotlin/net/hareworks/hcu/shop/listeners/ShopListener.kt +++ b/src/main/kotlin/net/hareworks/hcu/shop/listeners/ShopListener.kt @@ -48,9 +48,9 @@ class ShopListener(private val plugin: ShopPlugin) : Listener { return } - // Check block against (Chest) - if (event.blockAgainst.type != Material.CHEST) { - // Only valid on top of chests + // Check block against (Chest/Container) + if (event.blockAgainst.type !in ShopVisuals.VALID_CONTAINERS) { + // Only valid on top of supported containers event.isCancelled = true return } @@ -65,12 +65,12 @@ class ShopListener(private val plugin: ShopPlugin) : Listener { // Just ensure color is black initially if needed, but Visuals will overwrite. val frontSide = signState.getSide(Side.FRONT) frontSide.color = DyeColor.BLACK - frontSide.isGlowingText = false + frontSide.isGlowingText = true // Back Text val backSide = signState.getSide(Side.BACK) backSide.color = DyeColor.BLACK - backSide.isGlowingText = false + backSide.isGlowingText = true // Save Tier to Block and Wax (Lock) signState.persistentDataContainer.set(tierKey, PersistentDataType.INTEGER, tier) @@ -356,10 +356,10 @@ class ShopListener(private val plugin: ShopPlugin) : Listener { } @EventHandler - fun onChestInteract(event: PlayerInteractEvent) { + fun onContainerInteract(event: PlayerInteractEvent) { if (event.action != Action.RIGHT_CLICK_BLOCK) return val block = event.clickedBlock ?: return - if (block.type != Material.CHEST) return + if (block.type !in ShopVisuals.VALID_CONTAINERS) return // Check for Shop Sign above val signBlock = block.getRelative(BlockFace.UP) @@ -592,8 +592,8 @@ class ShopListener(private val plugin: ShopPlugin) : Listener { fun onBlockBreak(event: org.bukkit.event.block.BlockBreakEvent) { val block = event.block - // Handle Chest Break Protection - if (block.type == Material.CHEST) { + // Handle Container Break Protection + if (block.type in ShopVisuals.VALID_CONTAINERS) { val signBlock = block.getRelative(BlockFace.UP) if (signBlock.type == Material.OAK_SIGN) { val state = signBlock.state as? Sign