26 lines
994 B
Kotlin
26 lines
994 B
Kotlin
package codes.som.hibiscus.util.input
|
|
|
|
import codes.som.hibiscus.HibiscusLog
|
|
import codes.som.hibiscus.Hibiscus
|
|
import codes.som.hibiscus.api.command.CommandContext
|
|
import codes.som.hibiscus.api.command.exceptions.CommandExecutionException
|
|
import codes.som.hibiscus.api.event.TypedListener
|
|
import codes.som.hibiscus.events.KeyEvent
|
|
import codes.som.hibiscus.mc
|
|
import org.lwjgl.glfw.GLFW
|
|
|
|
class KeybindDispatcher : TypedListener<KeyEvent>(KeyEvent::class.java) {
|
|
override fun on(event: KeyEvent) {
|
|
if (mc.isWindowFocused && mc.currentScreen == null && event.action == GLFW.GLFW_PRESS) {
|
|
Hibiscus.keybinds.getBinds(event.key).forEach { bind ->
|
|
try {
|
|
Hibiscus.commands.context = CommandContext.KEYBIND
|
|
Hibiscus.commands.executeCommand(bind)
|
|
} catch (e: CommandExecutionException) {
|
|
e.cause?.message?.let { HibiscusLog.error(it) }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|