feat: コンテナ追加
This commit is contained in:
parent
47bfcfc1e4
commit
84c4252592
|
|
@ -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: <Owner Name> (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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user