Skip to content

Commit

Permalink
🐛 fix can not open interactive block
Browse files Browse the repository at this point in the history
  • Loading branch information
XiYang6666 committed Jun 9, 2024
1 parent 020a5e7 commit 9b4dcd6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.bukkit.inventory.meta.BookMeta
import xyz.xasmc.hashbook.HashBook
import xyz.xasmc.hashbook.service.ItemDataServices
import xyz.xasmc.hashbook.service.StorageServices
import xyz.xasmc.hashbook.util.BlockUtil
import xyz.xasmc.hashbook.util.BookUtil
import xyz.xasmc.hashbook.util.MessageUtil.debugMiniMessage
import xyz.xasmc.hashbook.util.MessageUtil.sendMiniMessage
Expand All @@ -18,13 +19,15 @@ import xyz.xasmc.hashbook.util.MessageUtil.shortHashMessage
class OpenBookListener : Listener {
@EventHandler
fun onPlayerInteract(event: PlayerInteractEvent) {
if (!(event.action == Action.RIGHT_CLICK_AIR || event.action == Action.RIGHT_CLICK_BLOCK)) return
if (event.action == Action.RIGHT_CLICK_BLOCK && !BlockUtil.checkInteractiveBlock(event.clickedBlock ?: return))
else if (event.action == Action.RIGHT_CLICK_AIR)
else return

val msgTitle = "<dark_aqua>[HashBook]</dark_aqua>"

val player = event.player
val hand = event.hand ?: run {
player.sendMiniMessage("$msgTitle <yellow>[warn] 无法获取装备槽")
player.debugMiniMessage("$msgTitle <aqua>[debug] 无法获取装备槽")
return@onPlayerInteract
}

Expand Down
49 changes: 49 additions & 0 deletions src/main/kotlin/xyz/xasmc/hashbook/util/BlockUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package xyz.xasmc.hashbook.util

import org.bukkit.Material
import org.bukkit.Tag
import org.bukkit.block.Block

object BlockUtil {
fun checkInteractiveBlock(block: Block): Boolean {
val type = block.type
if (Tag.WOODEN_DOORS.isTagged(type)) return true
if (Tag.WOODEN_TRAPDOORS.isTagged(type)) return true
if (Tag.FENCE_GATES.isTagged(type)) return true
if (Tag.BUTTONS.isTagged(type)) return true
if (Tag.ANVIL.isTagged(type)) return true
if (Tag.ALL_SIGNS.isTagged(type)) return true
if (Tag.BEDS.isTagged(type)) return true
if (Tag.SHULKER_BOXES.isTagged(type)) return true

when (type) {
Material.CRAFTING_TABLE -> return true
Material.STONECUTTER -> return true
Material.CARTOGRAPHY_TABLE -> return true
Material.SMITHING_TABLE -> return true
Material.BLAST_FURNACE -> return true
Material.SMOKER -> return true
Material.FURNACE -> return true
Material.GRINDSTONE -> return true
Material.LOOM -> return true
Material.NOTE_BLOCK -> return true
Material.ENCHANTING_TABLE -> return true
Material.BREWING_STAND -> return true
Material.BELL -> return true
Material.BEACON -> return true
Material.LECTERN -> return true
Material.CHISELED_BOOKSHELF -> return true
Material.CHEST -> return true
Material.TRAPPED_CHEST -> return true
Material.BARREL -> return true
Material.ENDER_CHEST -> return true
Material.LEVER -> return true
Material.REPEATER -> return true
Material.COMPARATOR -> return true
Material.DISPENSER -> return true
Material.DROPPER -> return true
else -> {}
}
return false
}
}

0 comments on commit 9b4dcd6

Please sign in to comment.