Whole-project style fixes
parent
f9e0df935c
commit
d11f3e0927
|
@ -17,7 +17,7 @@ hibiscus/ $ ./gradlew runClient
|
||||||
hibiscus/ $ git submodule update --init
|
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.
|
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 {
|
fun typeHint(index: Int, parser: ArgumentParser<*>): BranchDeclaration {
|
||||||
typeHints.put(index, parser)
|
typeHints[index] = parser
|
||||||
return this
|
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.parser.ArgumentParser
|
||||||
import codes.som.hibiscus.api.command.utils.PeekableIterator
|
import codes.som.hibiscus.api.command.utils.PeekableIterator
|
||||||
import codes.som.hibiscus.api.command.utils.splitExceptingQuotes
|
import codes.som.hibiscus.api.command.utils.splitExceptingQuotes
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
||||||
private val parserRegistry = mutableMapOf<Class<*>, ArgumentParser<*>>()
|
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>) {
|
fun <T> registerParser(type: Class<T>, parser: ArgumentParser<T>) {
|
||||||
parserRegistry.put(type, parser)
|
parserRegistry[type] = parser
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun verifyCommand(command: ExecutableCommand) {
|
private fun verifyCommand(command: ExecutableCommand) {
|
||||||
// TODO: Prevent name collisions for commands / aliases
|
// TODO: Prevent name collisions for commands / aliases
|
||||||
|
|
||||||
command.branches.forEach {
|
command.branches.forEach { branch ->
|
||||||
it.parameterTypes
|
branch.parameterTypes
|
||||||
.filter { it !in parserRegistry }
|
.filter { it !in parserRegistry }
|
||||||
.forEach { throw MissingParserException(it) }
|
.forEach { throw MissingParserException(it) }
|
||||||
}
|
}
|
||||||
|
@ -104,8 +105,8 @@ class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
||||||
|
|
||||||
fun completeCommand(fullCommand: String): Array<String> {
|
fun completeCommand(fullCommand: String): Array<String> {
|
||||||
return completeCommandDuplicatesSpaces(fullCommand)
|
return completeCommandDuplicatesSpaces(fullCommand)
|
||||||
.map {
|
.map { s ->
|
||||||
if (it.toCharArray().any { it.isWhitespace() }) "\"$it\"" else it
|
if (s.toCharArray().any { it.isWhitespace() }) "\"$s\"" else s
|
||||||
} // Wrap suggestions containing spaces in quotes
|
} // Wrap suggestions containing spaces in quotes
|
||||||
.toSet() // Remove duplicates
|
.toSet() // Remove duplicates
|
||||||
.toTypedArray()
|
.toTypedArray()
|
||||||
|
@ -123,7 +124,9 @@ class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
||||||
commands.forEach { addAll(it.aliases) }
|
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]
|
val commandName = args[0]
|
||||||
|
@ -183,7 +186,7 @@ class CommandManager(private val registerDefaultParsers: Boolean = true) {
|
||||||
|
|
||||||
val argumentObjects = mutableListOf<Any>()
|
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) {
|
if (args.size - startIndex >= minArgs && args.size - startIndex >= parsers.size) {
|
||||||
for ((index, parser) in parsers.withIndex()) {
|
for ((index, parser) in parsers.withIndex()) {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
package codes.som.hibiscus.api.event
|
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.HibiscusMod
|
||||||
import codes.som.hibiscus.api.command.Command
|
import codes.som.hibiscus.api.command.Command
|
||||||
import codes.som.hibiscus.api.command.CommandContext
|
import codes.som.hibiscus.api.command.CommandContext
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class FeatureCommand(feature: Feature) : Command(feature.name.replace(" ", "").lowercase()) {
|
class FeatureCommand(feature: Feature) : Command(feature.name.replace(" ", "").lowercase()) {
|
||||||
init {
|
init {
|
||||||
|
@ -18,7 +19,7 @@ class FeatureCommand(feature: Feature) : Command(feature.name.replace(" ", "").l
|
||||||
|
|
||||||
if (feature.values.exist()) {
|
if (feature.values.exist()) {
|
||||||
for (value in feature.values) {
|
for (value in feature.values) {
|
||||||
val simplifiedValueName = value.name.toLowerCase().replace(" ", "")
|
val simplifiedValueName = value.name.lowercase(Locale.getDefault()).replace(" ", "")
|
||||||
|
|
||||||
branch(simplifiedValueName) {
|
branch(simplifiedValueName) {
|
||||||
HibiscusLog.info("Value of '${value.name}': " + value.getValueAsString())
|
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 codes.som.hibiscus.util.input.Keys
|
||||||
import org.lwjgl.glfw.GLFW
|
import org.lwjgl.glfw.GLFW
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class KeyboardValue(name: String, value: Int = GLFW.GLFW_KEY_UNKNOWN) : RegisteredValue<Int>(name, value) {
|
class KeyboardValue(name: String, value: Int = GLFW.GLFW_KEY_UNKNOWN) : RegisteredValue<Int>(name, value) {
|
||||||
override fun convertValueFromString(representation: String): Int {
|
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 {
|
override fun getValueAsString(): String {
|
||||||
|
|
|
@ -12,10 +12,10 @@ import org.lwjgl.glfw.GLFW
|
||||||
class KeybindDispatcher : TypedListener<KeyEvent>(KeyEvent::class.java) {
|
class KeybindDispatcher : TypedListener<KeyEvent>(KeyEvent::class.java) {
|
||||||
override fun on(event: KeyEvent) {
|
override fun on(event: KeyEvent) {
|
||||||
if (mc.isWindowFocused && mc.currentScreen == null && event.action == GLFW.GLFW_PRESS) {
|
if (mc.isWindowFocused && mc.currentScreen == null && event.action == GLFW.GLFW_PRESS) {
|
||||||
HibiscusMod.keybinds.getBinds(event.key).forEach {
|
HibiscusMod.keybinds.getBinds(event.key).forEach { bind ->
|
||||||
HibiscusMod.commands.context = CommandContext.KEYBIND
|
|
||||||
try {
|
try {
|
||||||
HibiscusMod.commands.executeCommand(it)
|
HibiscusMod.commands.context = CommandContext.KEYBIND
|
||||||
|
HibiscusMod.commands.executeCommand(bind)
|
||||||
} catch (e: CommandExecutionException) {
|
} catch (e: CommandExecutionException) {
|
||||||
e.cause?.message?.let { HibiscusLog.error(it) }
|
e.cause?.message?.let { HibiscusLog.error(it) }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue