Skip to content

Commit

Permalink
format debug command messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bixilon committed Mar 1, 2024
1 parent f18c0a2 commit 2869275
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
12 changes: 5 additions & 7 deletions src/main/java/de/bixilon/minosoft/data/text/ChatComponent.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 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.
*
Expand All @@ -18,6 +18,7 @@ import de.bixilon.minosoft.data.language.IntegratedLanguage
import de.bixilon.minosoft.data.language.translate.Translatable
import de.bixilon.minosoft.data.language.translate.Translator
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.text.formatting.TextFormattable
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text
import de.bixilon.minosoft.util.json.Jackson
Expand Down Expand Up @@ -82,12 +83,9 @@ interface ChatComponent {

@JvmOverloads
fun of(raw: Any? = null, translator: Translator? = null, parent: TextComponent? = null, ignoreJson: Boolean = false, restricted: Boolean = false): ChatComponent {
if (raw == null) {
return EMPTY
}
if (raw is ChatComponent) {
return raw
}
if (raw == null) return EMPTY
if (raw is ChatComponent) return raw
if (raw is TextFormattable) return of(raw.toText())
if (raw is Translatable && raw !is ResourceLocation) {
return (translator ?: IntegratedLanguage.LANGUAGE).forceTranslate(raw.translationKey, parent, restricted = restricted)
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/de/bixilon/minosoft/protocol/PlayerPublicKey.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 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.
*
Expand All @@ -17,7 +17,7 @@ import de.bixilon.kutil.base64.Base64Util.fromBase64
import de.bixilon.kutil.base64.Base64Util.toBase64
import de.bixilon.kutil.json.JsonObject
import de.bixilon.kutil.primitive.LongUtil.toLong
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_19_1_PRE4
import de.bixilon.minosoft.protocol.protocol.encryption.CryptManager
import de.bixilon.minosoft.protocol.protocol.encryption.CryptManager.encodeNetwork
import de.bixilon.minosoft.util.account.minecraft.key.MinecraftKeyPair
Expand Down Expand Up @@ -58,17 +58,17 @@ class PlayerPublicKey(
return MinecraftKeyPair.isSignatureCorrect(uuid, expiresAt, publicKey, signature)
}

fun isSignatureCorrect(versionId: Int, uuid: UUID): Boolean {
return if (versionId < V_1_19_1_PRE4) isLegacySignatureCorrect() else isSignatureCorrect(uuid)
}

fun requireSignature(versionId: Int, uuid: UUID) {
if (versionId < ProtocolVersions.V_1_19_1_PRE4) {
if (!isLegacySignatureCorrect()) throw SignatureException()
} else {
if (!isSignatureCorrect(uuid)) throw SignatureException()
}
if (!isSignatureCorrect(versionId, uuid)) throw SignatureException()
}

fun validate(versionId: Int, uuid: UUID) {
if (isExpired()) {
throw IllegalStateException("Key is expired!")
throw SignatureException("Key is expired!")
}
requireSignature(versionId, uuid)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 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.
*
Expand All @@ -17,25 +17,32 @@ import de.bixilon.minosoft.commands.nodes.ArgumentNode
import de.bixilon.minosoft.commands.nodes.LiteralNode
import de.bixilon.minosoft.commands.parser.brigadier.bool.BooleanParser
import de.bixilon.minosoft.commands.stack.CommandStack
import de.bixilon.minosoft.commands.stack.print.PrintTarget
import de.bixilon.minosoft.data.chat.message.internal.DebugChatMessage
import de.bixilon.minosoft.util.KUtil.format

object DebugCommand : ConnectionCommand {
override var node = LiteralNode("debug")
.addChild(LiteralNode("allowFly", executor = { it.fly() }, allowArguments = true).addChild(ArgumentNode("value", BooleanParser, executable = true)))
.addChild(LiteralNode("network").addChild(
LiteralNode("detach", executor = { it.connection.network.detach(); it.connection.util.sendDebugMessage("Now you are alone on the wire...") }),
LiteralNode("detach", executor = { it.connection.network.detach(); it.print.sendDebugMessage("Now you are alone on the wire...") }),
))
.addChild(LiteralNode("cache").addChild(LiteralNode("biome", executor = { it.connection.world.biomes.resetCache(); it.connection.util.sendDebugMessage("Biome cache cleared!") })))
.addChild(LiteralNode("cache").addChild(LiteralNode("biome", executor = { it.connection.world.biomes.resetCache(); it.print.sendDebugMessage("Biome cache cleared!") })))


private fun CommandStack.fly() {
val value: Boolean = this["value"] ?: !connection.player.abilities.allowFly
val abilities = connection.player.abilities
if (abilities.allowFly == value) {
print.print("Allow fly is already set to ${value.format()}§r!")
print.sendDebugMessage("Allow fly is already set to ${value.format()}§r!")
} else {
connection.player.abilities = abilities.copy(allowFly = value)
print.print("Allow fly set to ${value.format()}§r!")
print.sendDebugMessage("Allow fly set to ${value.format()}§r!")
}
}


private fun PrintTarget.sendDebugMessage(message: Any?) {
this.print(DebugChatMessage(message.format()))
}
}

0 comments on commit 2869275

Please sign in to comment.