Whole-project style fixes
parent
f9e0df935c
commit
d11f3e0927
|
@ -17,7 +17,7 @@ hibiscus/ $ ./gradlew runClient
|
|||
hibiscus/ $ git submodule update --init
|
||||
```
|
||||
|
||||
You may want to also mark the `run` and `vendor` folders as excluded in IntelliJ.
|
||||
You may want to also mark the `build_src`, `run`, and `vendor` folders as excluded in IntelliJ.
|
||||
|
||||
To authenticate from the IDE, you can create a lastlogin.txt file in `run/` (already gitignored) with the following structure.
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ open class Command(val name: String) {
|
|||
}
|
||||
|
||||
fun typeHint(index: Int, parser: ArgumentParser<*>): BranchDeclaration {
|
||||
typeHints.put(index, parser)
|
||||
typeHints[index] = parser
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import codes.som.hibiscus.api.command.exceptions.*
|
|||
import codes.som.hibiscus.api.command.parser.ArgumentParser
|
||||
import codes.som.hibiscus.api.command.utils.PeekableIterator
|
||||
import codes.som.hibiscus.api.command.utils.splitExceptingQuotes
|
||||
import java.util.*
|
||||
|
||||
class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
||||
private val parserRegistry = mutableMapOf<Class<*>, ArgumentParser<*>>()
|
||||
|
@ -24,14 +25,14 @@ class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
|||
}
|
||||
|
||||
fun <T> registerParser(type: Class<T>, parser: ArgumentParser<T>) {
|
||||
parserRegistry.put(type, parser)
|
||||
parserRegistry[type] = parser
|
||||
}
|
||||
|
||||
private fun verifyCommand(command: ExecutableCommand) {
|
||||
// TODO: Prevent name collisions for commands / aliases
|
||||
|
||||
command.branches.forEach {
|
||||
it.parameterTypes
|
||||
command.branches.forEach { branch ->
|
||||
branch.parameterTypes
|
||||
.filter { it !in parserRegistry }
|
||||
.forEach { throw MissingParserException(it) }
|
||||
}
|
||||
|
@ -104,8 +105,8 @@ class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
|||
|
||||
fun completeCommand(fullCommand: String): Array<String> {
|
||||
return completeCommandDuplicatesSpaces(fullCommand)
|
||||
.map {
|
||||
if (it.toCharArray().any { it.isWhitespace() }) "\"$it\"" else it
|
||||
.map { s ->
|
||||
if (s.toCharArray().any { it.isWhitespace() }) "\"$s\"" else s
|
||||
} // Wrap suggestions containing spaces in quotes
|
||||
.toSet() // Remove duplicates
|
||||
.toTypedArray()
|
||||
|
@ -123,7 +124,9 @@ class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
|||
commands.forEach { addAll(it.aliases) }
|
||||
}
|
||||
|
||||
return namesAndAliasesOfCommands.filter { it.toLowerCase().startsWith(fullCommand.toLowerCase()) }
|
||||
return namesAndAliasesOfCommands.filter {
|
||||
it.lowercase(Locale.getDefault()).startsWith(fullCommand.lowercase(Locale.getDefault()))
|
||||
}
|
||||
}
|
||||
|
||||
val commandName = args[0]
|
||||
|
@ -183,7 +186,7 @@ class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
|||
|
||||
val argumentObjects = mutableListOf<Any>()
|
||||
|
||||
val minArgs = parsers.map { it.minimumAcceptedArguments() }.sum()
|
||||
val minArgs = parsers.sumOf { it.minimumAcceptedArguments() }
|
||||
|
||||
if (args.size - startIndex >= minArgs && args.size - startIndex >= parsers.size) {
|
||||
for ((index, parser) in parsers.withIndex()) {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
package codes.som.hibiscus.api.event
|
||||
|
||||
interface Event {
|
||||
}
|
||||
interface Event
|
||||
|
|
|
@ -4,6 +4,7 @@ import codes.som.hibiscus.HibiscusLog
|
|||
import codes.som.hibiscus.HibiscusMod
|
||||
import codes.som.hibiscus.api.command.Command
|
||||
import codes.som.hibiscus.api.command.CommandContext
|
||||
import java.util.*
|
||||
|
||||
class FeatureCommand(feature: Feature) : Command(feature.name.replace(" ", "").lowercase()) {
|
||||
init {
|
||||
|
@ -18,7 +19,7 @@ class FeatureCommand(feature: Feature) : Command(feature.name.replace(" ", "").l
|
|||
|
||||
if (feature.values.exist()) {
|
||||
for (value in feature.values) {
|
||||
val simplifiedValueName = value.name.toLowerCase().replace(" ", "")
|
||||
val simplifiedValueName = value.name.lowercase(Locale.getDefault()).replace(" ", "")
|
||||
|
||||
branch(simplifiedValueName) {
|
||||
HibiscusLog.info("Value of '${value.name}': " + value.getValueAsString())
|
||||
|
|
|
@ -2,10 +2,11 @@ package codes.som.hibiscus.api.feature.values
|
|||
|
||||
import codes.som.hibiscus.util.input.Keys
|
||||
import org.lwjgl.glfw.GLFW
|
||||
import java.util.*
|
||||
|
||||
class KeyboardValue(name: String, value: Int = GLFW.GLFW_KEY_UNKNOWN) : RegisteredValue<Int>(name, value) {
|
||||
override fun convertValueFromString(representation: String): Int {
|
||||
return Keys.KEY_MAP[representation.toUpperCase()] ?: -1
|
||||
return Keys.KEY_MAP[representation.uppercase(Locale.getDefault())] ?: -1
|
||||
}
|
||||
|
||||
override fun getValueAsString(): String {
|
||||
|
|
|
@ -12,10 +12,10 @@ 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) {
|
||||
HibiscusMod.keybinds.getBinds(event.key).forEach {
|
||||
HibiscusMod.commands.context = CommandContext.KEYBIND
|
||||
HibiscusMod.keybinds.getBinds(event.key).forEach { bind ->
|
||||
try {
|
||||
HibiscusMod.commands.executeCommand(it)
|
||||
HibiscusMod.commands.context = CommandContext.KEYBIND
|
||||
HibiscusMod.commands.executeCommand(bind)
|
||||
} catch (e: CommandExecutionException) {
|
||||
e.cause?.message?.let { HibiscusLog.error(it) }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue