brigadier: print error messages red, print correct error client sided if stack is empty

This commit is contained in:
Bixilon 2023-01-13 17:01:31 +01:00
parent acc668916e
commit dea78c8611
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 17 additions and 8 deletions

View File

@ -39,9 +39,14 @@ class ChatNode(
thrown = error thrown = error
} }
if (node != CLI.ROOT_NODE && string.isNotBlank()) { if (node != CLI.ROOT_NODE && string.isNotBlank()) {
if (peek == '/'.code) { if (peek == '/'.code) {
stack.connection.util.sendCommand("/$string", stack) try {
stack.connection.util.sendCommand("/$string", stack)
} catch (error: Throwable) {
throw thrown ?: error
}
} else { } else {
stack.connection.util.sendChatMessage(string) stack.connection.util.sendChatMessage(string)
} }

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -24,6 +24,8 @@ import de.bixilon.minosoft.commands.stack.print.PlayerPrintTarget
import de.bixilon.minosoft.commands.util.CommandReader import de.bixilon.minosoft.commands.util.CommandReader
import de.bixilon.minosoft.commands.util.StringReader.Companion.isWord import de.bixilon.minosoft.commands.util.StringReader.Companion.isWord
import de.bixilon.minosoft.config.key.KeyCodes import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.Element
import de.bixilon.minosoft.gui.rendering.gui.elements.text.mark.TextCursorStyles import de.bixilon.minosoft.gui.rendering.gui.elements.text.mark.TextCursorStyles
@ -89,7 +91,7 @@ class NodeTextInputElement(
try { try {
node.execute(CommandReader(value), stack) node.execute(CommandReader(value), stack)
} catch (exception: Throwable) { } catch (exception: Throwable) {
exception.message?.let { stack.print.print(it) } exception.message?.let { stack.print.print(TextComponent("Error: $it").color(ChatColors.RED)) }
} }
updateError(null) updateError(null)
} }

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -21,6 +21,8 @@ import de.bixilon.minosoft.commands.nodes.LiteralNode
import de.bixilon.minosoft.commands.parser.minosoft.connection.ConnectionParser import de.bixilon.minosoft.commands.parser.minosoft.connection.ConnectionParser
import de.bixilon.minosoft.commands.parser.minosoft.connection.ConnectionTarget import de.bixilon.minosoft.commands.parser.minosoft.connection.ConnectionTarget
import de.bixilon.minosoft.commands.stack.CommandStack import de.bixilon.minosoft.commands.stack.CommandStack
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.terminal.cli.CLI import de.bixilon.minosoft.terminal.cli.CLI
@ -32,7 +34,7 @@ object ConnectionManageCommand : Command {
connections += PlayConnection.ERRORED_CONNECTIONS.toSynchronizedList() connections += PlayConnection.ERRORED_CONNECTIONS.toSynchronizedList()
val filteredConnections = it.get<ConnectionTarget?>("filter")?.getConnections(connections) ?: connections val filteredConnections = it.get<ConnectionTarget?>("filter")?.getConnections(connections) ?: connections
if (filteredConnections.isEmpty()) { if (filteredConnections.isEmpty()) {
it.print.print("No connection matched your filter!") it.print.print(TextComponent("No connection matched your filter!").color(ChatColors.RED))
return@LiteralNode return@LiteralNode
} }
val table = Table(arrayOf("Id", "State", "Address")) val table = Table(arrayOf("Id", "State", "Address"))
@ -63,13 +65,13 @@ object ConnectionManageCommand : Command {
continue continue
} }
if (toSelect != null) { if (toSelect != null) {
stack.print.print("Can not select multiple connections!") stack.print.print(TextComponent("Can not select multiple connections!").color(ChatColors.RED))
return@addFilter return@addFilter
} }
toSelect = connection toSelect = connection
} }
if (toSelect == null) { if (toSelect == null) {
stack.print.print("No connection matched your filter!") stack.print.print(TextComponent("No connection matched your filter!").color(ChatColors.RED))
return@addFilter return@addFilter
} }
CLI.connection = toSelect CLI.connection = toSelect
@ -85,7 +87,7 @@ object ConnectionManageCommand : Command {
connections += PlayConnection.ERRORED_CONNECTIONS.toSynchronizedList() connections += PlayConnection.ERRORED_CONNECTIONS.toSynchronizedList()
val filteredConnections = it.get<ConnectionTarget?>("filter")?.getConnections(connections) ?: connections val filteredConnections = it.get<ConnectionTarget?>("filter")?.getConnections(connections) ?: connections
if (filteredConnections.isEmpty()) { if (filteredConnections.isEmpty()) {
it.print.print("No connection matched your filter!") it.print.print(TextComponent("No connection matched your filter!").color(ChatColors.RED))
return@ArgumentNode return@ArgumentNode
} }
executor(it, connections) executor(it, connections)