commands: action, query

Improvement to #94
This commit is contained in:
Moritz Zwerger 2023-07-30 01:33:28 +02:00
parent 578e5fcf13
commit d3ba3fcc2e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
10 changed files with 81 additions and 6 deletions

View File

@ -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))
}
}

View File

@ -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] }
}

View File

@ -38,4 +38,8 @@ object OverworldEffects : DimensionEffects {
}
override val fog: Boolean get() = true
override fun toString(): String {
return identifier.toString()
}
}

View File

@ -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)
}

View File

@ -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()
}

View File

@ -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))
}
}

View File

@ -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<Command> = listOf(
HelpCommand,
SayCommand,
ConnectionManageCommand,
AccountManageCommand,
ReloadCommand,
@ -29,5 +30,9 @@ object Commands {
CrashCommand, DumpCommand,
AboutCommand,
SayCommand,
ActionCommand, QueryCommand,
)
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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()
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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}") }))
}

View File

@ -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))
}