From dea78c861153f1abe49db222456c1aef8ae2e21c Mon Sep 17 00:00:00 2001 From: Bixilon Date: Fri, 13 Jan 2023 17:01:31 +0100 Subject: [PATCH] brigadier: print error messages red, print correct error client sided if stack is empty --- .../de/bixilon/minosoft/commands/nodes/ChatNode.kt | 7 ++++++- .../gui/elements/input/node/NodeTextInputElement.kt | 6 ++++-- .../terminal/commands/ConnectionManageCommand.kt | 12 +++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/commands/nodes/ChatNode.kt b/src/main/java/de/bixilon/minosoft/commands/nodes/ChatNode.kt index 54b043e5e..20229409c 100644 --- a/src/main/java/de/bixilon/minosoft/commands/nodes/ChatNode.kt +++ b/src/main/java/de/bixilon/minosoft/commands/nodes/ChatNode.kt @@ -39,9 +39,14 @@ class ChatNode( thrown = error } + if (node != CLI.ROOT_NODE && string.isNotBlank()) { if (peek == '/'.code) { - stack.connection.util.sendCommand("/$string", stack) + try { + stack.connection.util.sendCommand("/$string", stack) + } catch (error: Throwable) { + throw thrown ?: error + } } else { stack.connection.util.sendChatMessage(string) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/elements/input/node/NodeTextInputElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/elements/input/node/NodeTextInputElement.kt index 7c378f5dd..d68a5b216 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/elements/input/node/NodeTextInputElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/elements/input/node/NodeTextInputElement.kt @@ -1,6 +1,6 @@ /* * 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. * @@ -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.StringReader.Companion.isWord 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.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.text.mark.TextCursorStyles @@ -89,7 +91,7 @@ class NodeTextInputElement( try { node.execute(CommandReader(value), stack) } catch (exception: Throwable) { - exception.message?.let { stack.print.print(it) } + exception.message?.let { stack.print.print(TextComponent("Error: $it").color(ChatColors.RED)) } } updateError(null) } diff --git a/src/main/java/de/bixilon/minosoft/terminal/commands/ConnectionManageCommand.kt b/src/main/java/de/bixilon/minosoft/terminal/commands/ConnectionManageCommand.kt index c8164494c..ceab8379a 100644 --- a/src/main/java/de/bixilon/minosoft/terminal/commands/ConnectionManageCommand.kt +++ b/src/main/java/de/bixilon/minosoft/terminal/commands/ConnectionManageCommand.kt @@ -1,6 +1,6 @@ /* * 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. * @@ -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.ConnectionTarget 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.terminal.cli.CLI @@ -32,7 +34,7 @@ object ConnectionManageCommand : Command { connections += PlayConnection.ERRORED_CONNECTIONS.toSynchronizedList() val filteredConnections = it.get("filter")?.getConnections(connections) ?: connections 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 } val table = Table(arrayOf("Id", "State", "Address")) @@ -63,13 +65,13 @@ object ConnectionManageCommand : Command { continue } 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 } toSelect = connection } 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 } CLI.connection = toSelect @@ -85,7 +87,7 @@ object ConnectionManageCommand : Command { connections += PlayConnection.ERRORED_CONNECTIONS.toSynchronizedList() val filteredConnections = it.get("filter")?.getConnections(connections) ?: connections 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 } executor(it, connections)