feat: コンテナ追加

This commit is contained in:
Keisuke Hirata 2025-12-20 01:56:22 +09:00
parent 47bfcfc1e4
commit 84c4252592
2 changed files with 27 additions and 16 deletions

View File

@ -9,6 +9,14 @@ import org.bukkit.block.sign.Side
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
object ShopVisuals { 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) { fun updateSign(plugin: JavaPlugin, block: org.bukkit.block.Block, shopData: ShopData, side: Side) {
val state = block.state as? Sign ?: return val state = block.state as? Sign ?: return
val signSide = state.getSide(side) val signSide = state.getSide(side)
@ -46,10 +54,11 @@ object ShopVisuals {
// L3: (Empty) // L3: (Empty)
// L4: <Owner Name> (Gray) // L4: <Owner Name> (Gray)
signSide.line(0, Component.text(itemName, NamedTextColor.AQUA)) signSide.line(0, Component.empty())
signSide.line(1, Component.text("x$amount - $priceStr", NamedTextColor.BLACK)) signSide.line(1, Component.text(itemName, NamedTextColor.AQUA))
signSide.line(2, Component.empty()) signSide.line(2, Component.text("x$amount - $priceStr", NamedTextColor.BLACK))
signSide.line(3, Component.text(ownerName, NamedTextColor.GRAY)) signSide.line(3, Component.text(ownerName, NamedTextColor.GRAY))
signSide.isGlowingText = true
// Update the sign immediately // Update the sign immediately
state.isWaxed = true // Force lock visually 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 { fun calculateStock(block: org.bukkit.block.Block, item: org.bukkit.inventory.ItemStack?): Int {
if (item == null) return 0 if (item == null) return 0
val chestBlock = block.getRelative(org.bukkit.block.BlockFace.DOWN) val downBlock = block.getRelative(org.bukkit.block.BlockFace.DOWN)
if (chestBlock.type != org.bukkit.Material.CHEST) return 0
val chest = chestBlock.state as? org.bukkit.block.Chest ?: return 0 if (downBlock.type !in VALID_CONTAINERS) return 0
val inventory = chest.inventory
// 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 var count = 0
for (i in 0 until inventory.size) { for (i in 0 until inventory.size) {

View File

@ -48,9 +48,9 @@ class ShopListener(private val plugin: ShopPlugin) : Listener {
return return
} }
// Check block against (Chest) // Check block against (Chest/Container)
if (event.blockAgainst.type != Material.CHEST) { if (event.blockAgainst.type !in ShopVisuals.VALID_CONTAINERS) {
// Only valid on top of chests // Only valid on top of supported containers
event.isCancelled = true event.isCancelled = true
return return
} }
@ -65,12 +65,12 @@ class ShopListener(private val plugin: ShopPlugin) : Listener {
// Just ensure color is black initially if needed, but Visuals will overwrite. // Just ensure color is black initially if needed, but Visuals will overwrite.
val frontSide = signState.getSide(Side.FRONT) val frontSide = signState.getSide(Side.FRONT)
frontSide.color = DyeColor.BLACK frontSide.color = DyeColor.BLACK
frontSide.isGlowingText = false frontSide.isGlowingText = true
// Back Text // Back Text
val backSide = signState.getSide(Side.BACK) val backSide = signState.getSide(Side.BACK)
backSide.color = DyeColor.BLACK backSide.color = DyeColor.BLACK
backSide.isGlowingText = false backSide.isGlowingText = true
// Save Tier to Block and Wax (Lock) // Save Tier to Block and Wax (Lock)
signState.persistentDataContainer.set(tierKey, PersistentDataType.INTEGER, tier) signState.persistentDataContainer.set(tierKey, PersistentDataType.INTEGER, tier)
@ -356,10 +356,10 @@ class ShopListener(private val plugin: ShopPlugin) : Listener {
} }
@EventHandler @EventHandler
fun onChestInteract(event: PlayerInteractEvent) { fun onContainerInteract(event: PlayerInteractEvent) {
if (event.action != Action.RIGHT_CLICK_BLOCK) return if (event.action != Action.RIGHT_CLICK_BLOCK) return
val block = event.clickedBlock ?: 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 // Check for Shop Sign above
val signBlock = block.getRelative(BlockFace.UP) 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) { fun onBlockBreak(event: org.bukkit.event.block.BlockBreakEvent) {
val block = event.block val block = event.block
// Handle Chest Break Protection // Handle Container Break Protection
if (block.type == Material.CHEST) { if (block.type in ShopVisuals.VALID_CONTAINERS) {
val signBlock = block.getRelative(BlockFace.UP) val signBlock = block.getRelative(BlockFace.UP)
if (signBlock.type == Material.OAK_SIGN) { if (signBlock.type == Material.OAK_SIGN) {
val state = signBlock.state as? Sign val state = signBlock.state as? Sign