Skip to content

Commit e836db6

Browse files
feat(Paper): add left/right-click as valid ConfirmationKey options (gabber235#407)
* Clean ConfirmationKey change for PR * refactor: merge both click handlers into one class
1 parent e6a5d86 commit e836db6

File tree

1 file changed

+21
-1
lines changed
  • engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/dialogue

1 file changed

+21
-1
lines changed

engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/entry/dialogue/ConfirmationKey.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ import org.bukkit.entity.Player
1313
import org.bukkit.event.EventHandler
1414
import org.bukkit.event.EventPriority
1515
import org.bukkit.event.Listener
16+
import org.bukkit.event.block.Action
17+
import org.bukkit.event.player.PlayerInteractEvent
1618
import org.bukkit.event.player.PlayerSwapHandItemsEvent
1719
import org.bukkit.event.player.PlayerToggleSneakEvent
20+
import org.bukkit.inventory.EquipmentSlot
21+
1822

1923
private val confirmationKeyString by config(
2024
"confirmationKey", ConfirmationKey.JUMP.name, comment = """
@@ -37,13 +41,17 @@ enum class ConfirmationKey(val keybind: String) {
3741
JUMP("<key:key.jump>"),
3842
SWAP_HANDS("<key:key.swapOffhand>"),
3943
SNEAK("<key:key.sneak>"),
44+
LEFT_CLICK("<key:key.attack>"),
45+
RIGHT_CLICK("<key:key.use>"),
4046
;
4147

4248
fun handler(player: Player, block: () -> Unit): ConfirmationKeyHandler {
4349
return when (this) {
4450
SWAP_HANDS -> SwapHandsHandler(player, block)
4551
JUMP -> JumpHandler(player, block)
4652
SNEAK -> SneakHandler(player, block)
53+
LEFT_CLICK -> ClickHandler(player, block, Action.LEFT_CLICK_AIR, Action.LEFT_CLICK_BLOCK)
54+
RIGHT_CLICK -> ClickHandler(player, block, Action.RIGHT_CLICK_AIR, Action.RIGHT_CLICK_BLOCK)
4755
}.apply { initialize() }
4856
}
4957

@@ -107,4 +115,16 @@ class SneakHandler(override val player: Player, override val block: () -> Unit)
107115
event.isCancelled = true
108116
block()
109117
}
110-
}
118+
}
119+
120+
class ClickHandler(override val player: Player, override val block: () -> Unit, vararg val actions: Action) : ConfirmationKeyHandler {
121+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
122+
fun onInteract(event: PlayerInteractEvent) {
123+
if (event.player.uniqueId != player.uniqueId) return
124+
if (event.hand != EquipmentSlot.HAND) return
125+
if (event.action !in actions) return
126+
event.isCancelled = true
127+
block()
128+
}
129+
}
130+

0 commit comments

Comments
 (0)