diff --git a/src/main/java/de/bixilon/minosoft/commands/stack/print/PrintTarget.kt b/src/main/java/de/bixilon/minosoft/commands/stack/print/PrintTarget.kt index 8b2206a1c..51dff65b7 100644 --- a/src/main/java/de/bixilon/minosoft/commands/stack/print/PrintTarget.kt +++ b/src/main/java/de/bixilon/minosoft/commands/stack/print/PrintTarget.kt @@ -13,7 +13,14 @@ package de.bixilon.minosoft.commands.stack.print +import de.bixilon.minosoft.data.text.BaseComponent +import de.bixilon.minosoft.data.text.TextComponent +import de.bixilon.minosoft.data.text.formatting.color.ChatColors + interface PrintTarget { fun print(message: Any) + fun error(message: Any) { + print(BaseComponent(TextComponent("[ERROR] ").bold().color(ChatColors.RED), message)) + } } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt index 22fd8aa02..dd43769bf 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt @@ -86,7 +86,7 @@ class AccountProfile( var selected: Account? by BackingDelegate(get = { entries[_selected] }, set = { _selected = it?.id }) init { - this::_selected.observe(this) { this.selected = entries[_selected] } + this::_selected.observe(this) { this.selected = entries[it] } } diff --git a/src/main/java/de/bixilon/minosoft/data/registries/dimension/effects/OverworldEffects.kt b/src/main/java/de/bixilon/minosoft/data/registries/dimension/effects/OverworldEffects.kt index 1ea96b7df..a2a5029c3 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/dimension/effects/OverworldEffects.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/dimension/effects/OverworldEffects.kt @@ -38,4 +38,8 @@ object OverworldEffects : DimensionEffects { } override val fog: Boolean get() = true + + override fun toString(): String { + return identifier.toString() + } } 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 0944b554c..339d82ae5 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 @@ -91,7 +91,7 @@ class NodeTextInputElement( try { node.execute(CommandReader(value), stack) } catch (exception: Throwable) { - exception.message?.let { stack.print.print(TextComponent("Error: $it").color(ChatColors.RED)) } + exception.message?.let { stack.print.error(TextComponent(it).color(ChatColors.RED)) } } updateError(null) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/pause/RespawnMenu.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/pause/RespawnMenu.kt index 3197a6c5e..f19a65d7c 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/pause/RespawnMenu.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/menu/pause/RespawnMenu.kt @@ -27,7 +27,6 @@ import de.bixilon.minosoft.gui.rendering.gui.gui.GUIBuilder import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement import de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu.Menu import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates -import de.bixilon.minosoft.protocol.packets.c2s.play.ClientActionC2SP class RespawnMenu(guiRenderer: GUIRenderer) : Menu(guiRenderer) { @@ -43,7 +42,7 @@ class RespawnMenu(guiRenderer: GUIRenderer) : Menu(guiRenderer) { } fun respawn() { - guiRenderer.connection.network.send(ClientActionC2SP(ClientActionC2SP.ClientActions.PERFORM_RESPAWN)) + guiRenderer.connection.util.respawn() canPop = true guiRenderer.gui.pop() } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/util/ConnectionUtil.kt b/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/util/ConnectionUtil.kt index df6590ad8..71a7bb47b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/util/ConnectionUtil.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/connection/play/util/ConnectionUtil.kt @@ -30,6 +30,7 @@ import de.bixilon.minosoft.modding.event.events.chat.ChatMessageSendEvent import de.bixilon.minosoft.modding.event.events.container.ContainerCloseEvent import de.bixilon.minosoft.protocol.ProtocolUtil.encodeNetwork import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection +import de.bixilon.minosoft.protocol.packets.c2s.play.ClientActionC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.chat.ChatMessageC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.chat.CommandC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.chat.SignedChatMessageC2SP @@ -149,4 +150,8 @@ class ConnectionUtil( connection.world.entities.clear(connection) connection.world.clear() } + + fun respawn() { + connection.network.send(ClientActionC2SP(ClientActionC2SP.ClientActions.PERFORM_RESPAWN)) + } } diff --git a/src/main/java/de/bixilon/minosoft/terminal/commands/Commands.kt b/src/main/java/de/bixilon/minosoft/terminal/commands/Commands.kt index 3081f55d0..2cd2139b6 100644 --- a/src/main/java/de/bixilon/minosoft/terminal/commands/Commands.kt +++ b/src/main/java/de/bixilon/minosoft/terminal/commands/Commands.kt @@ -13,13 +13,14 @@ package de.bixilon.minosoft.terminal.commands +import de.bixilon.minosoft.terminal.commands.connection.ActionCommand +import de.bixilon.minosoft.terminal.commands.connection.QueryCommand import de.bixilon.minosoft.terminal.commands.connection.SayCommand import de.bixilon.minosoft.terminal.commands.rendering.ReloadCommand object Commands { val COMMANDS: List = listOf( HelpCommand, - SayCommand, ConnectionManageCommand, AccountManageCommand, ReloadCommand, @@ -29,5 +30,9 @@ object Commands { CrashCommand, DumpCommand, AboutCommand, + + + SayCommand, + ActionCommand, QueryCommand, ) } diff --git a/src/main/java/de/bixilon/minosoft/terminal/commands/connection/ActionCommand.kt b/src/main/java/de/bixilon/minosoft/terminal/commands/connection/ActionCommand.kt new file mode 100644 index 000000000..ec6cd34f2 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/terminal/commands/connection/ActionCommand.kt @@ -0,0 +1,31 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.terminal.commands.connection + +import de.bixilon.minosoft.commands.nodes.LiteralNode +import de.bixilon.minosoft.commands.stack.CommandStack + +object ActionCommand : ConnectionCommand { + override var node = LiteralNode("action", setOf("do")) + .addChild(LiteralNode("respawn", executor = { it.respawn() })) + + + private fun CommandStack.respawn() { + if (connection.player.healthCondition.hp > 0.0f) { + return print.error("You are still alive!") + } + print.print("Performing respawn...") + connection.util.respawn() + } +} diff --git a/src/main/java/de/bixilon/minosoft/terminal/commands/connection/QueryCommand.kt b/src/main/java/de/bixilon/minosoft/terminal/commands/connection/QueryCommand.kt new file mode 100644 index 000000000..43df3c108 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/terminal/commands/connection/QueryCommand.kt @@ -0,0 +1,24 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.terminal.commands.connection + +import de.bixilon.minosoft.commands.nodes.LiteralNode +import de.bixilon.minosoft.data.registries.effects.attributes.MinecraftAttributes + +object QueryCommand : ConnectionCommand { + override var node = LiteralNode("query") + .addChild(LiteralNode("health", executor = { it.print.print("Health §c${it.connection.player.healthCondition.hp}§r/§c${it.connection.player.attributes[MinecraftAttributes.MAX_HEALTH]}, hunger=${it.connection.player.healthCondition.hunger}") })) + .addChild(LiteralNode("xp", setOf("experience", "exp"), executor = { it.print.print("Experience: level §e${it.connection.player.experienceCondition.level}") })) + .addChild(LiteralNode("dimension", executor = { it.print.print("Dimension: §e${it.connection.world.dimension.effects}") })) +} diff --git a/src/main/java/de/bixilon/minosoft/terminal/commands/connection/SayCommand.kt b/src/main/java/de/bixilon/minosoft/terminal/commands/connection/SayCommand.kt index 84ef626af..ba5939a9b 100644 --- a/src/main/java/de/bixilon/minosoft/terminal/commands/connection/SayCommand.kt +++ b/src/main/java/de/bixilon/minosoft/terminal/commands/connection/SayCommand.kt @@ -17,6 +17,6 @@ import de.bixilon.minosoft.commands.nodes.ChatNode import de.bixilon.minosoft.commands.nodes.LiteralNode object SayCommand : ConnectionCommand { - override var node = LiteralNode("say", setOf("chat", "send", "write")) + override var node = LiteralNode("say", setOf("chat", "send")) .addChild(ChatNode("message", allowCLI = false)) }