diff --git a/README.md b/README.md index ab3faca..24ad360 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/main/kotlin/codes/som/hibiscus/api/command/Command.kt b/src/main/kotlin/codes/som/hibiscus/api/command/Command.kt index 8e769c1..37cff2f 100644 --- a/src/main/kotlin/codes/som/hibiscus/api/command/Command.kt +++ b/src/main/kotlin/codes/som/hibiscus/api/command/Command.kt @@ -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 } } diff --git a/src/main/kotlin/codes/som/hibiscus/api/command/CommandManager.kt b/src/main/kotlin/codes/som/hibiscus/api/command/CommandManager.kt index d168558..c63e72b 100644 --- a/src/main/kotlin/codes/som/hibiscus/api/command/CommandManager.kt +++ b/src/main/kotlin/codes/som/hibiscus/api/command/CommandManager.kt @@ -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, ArgumentParser<*>>() @@ -24,14 +25,14 @@ class CommandManager(private val registerDefaultParsers: Boolean = true) { } fun registerParser(type: Class, parser: ArgumentParser) { - 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 { 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() - 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()) { diff --git a/src/main/kotlin/codes/som/hibiscus/api/event/Event.kt b/src/main/kotlin/codes/som/hibiscus/api/event/Event.kt index cfcef87..c58c115 100644 --- a/src/main/kotlin/codes/som/hibiscus/api/event/Event.kt +++ b/src/main/kotlin/codes/som/hibiscus/api/event/Event.kt @@ -1,4 +1,3 @@ package codes.som.hibiscus.api.event -interface Event { -} +interface Event diff --git a/src/main/kotlin/codes/som/hibiscus/api/feature/FeatureCommand.kt b/src/main/kotlin/codes/som/hibiscus/api/feature/FeatureCommand.kt index 2712824..bc8b4fc 100644 --- a/src/main/kotlin/codes/som/hibiscus/api/feature/FeatureCommand.kt +++ b/src/main/kotlin/codes/som/hibiscus/api/feature/FeatureCommand.kt @@ -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()) diff --git a/src/main/kotlin/codes/som/hibiscus/api/feature/values/KeyboardValue.kt b/src/main/kotlin/codes/som/hibiscus/api/feature/values/KeyboardValue.kt index 988b946..a83c846 100644 --- a/src/main/kotlin/codes/som/hibiscus/api/feature/values/KeyboardValue.kt +++ b/src/main/kotlin/codes/som/hibiscus/api/feature/values/KeyboardValue.kt @@ -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(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 { diff --git a/src/main/kotlin/codes/som/hibiscus/util/input/KeybindDispatcher.kt b/src/main/kotlin/codes/som/hibiscus/util/input/KeybindDispatcher.kt index 7966c07..fe6cbf1 100644 --- a/src/main/kotlin/codes/som/hibiscus/util/input/KeybindDispatcher.kt +++ b/src/main/kotlin/codes/som/hibiscus/util/input/KeybindDispatcher.kt @@ -12,10 +12,10 @@ import org.lwjgl.glfw.GLFW class KeybindDispatcher : TypedListener(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) } }