mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 20:05:02 -04:00
chat: correct max length per version
This commit is contained in:
parent
45db95af26
commit
faa70657ee
@ -59,4 +59,5 @@ class Version(
|
||||
val flattened: Boolean = versionId >= ProtocolDefinition.FLATTING_VERSION_ID
|
||||
val hasOffhand: Boolean = versionId >= V_15W31A
|
||||
val maxPacketLength = (versionId < ProtocolVersions.V_1_17_1_RC2).decide(1 shl 21, 1 shl 23)
|
||||
val maxChatMessageSize = (versionId < ProtocolVersions.V_16W38A).decide(100, 256)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class ChatElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElem
|
||||
private val profile = connection.profiles.hud
|
||||
private val chatProfile = profile.chat
|
||||
private val messages = TextFlowElement(guiRenderer, 20000).apply { parent = this@ChatElement }
|
||||
private val input = TextInputElement(guiRenderer, maxLength = 256)
|
||||
private val input = TextInputElement(guiRenderer, maxLength = connection.version.maxChatMessageSize)
|
||||
private var active = false
|
||||
set(value) {
|
||||
field = value
|
||||
@ -133,13 +133,17 @@ class ChatElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElem
|
||||
input.onCharPress(char)
|
||||
}
|
||||
|
||||
private fun submit() {
|
||||
if (input.value.isNotBlank()) {
|
||||
connection.sendPacket(ChatMessageC2SP(input.value))
|
||||
}
|
||||
input.value = ""
|
||||
guiRenderer.gui.pop()
|
||||
}
|
||||
|
||||
override fun onSpecialKey(key: InputSpecialKey, type: KeyChangeTypes) {
|
||||
if (key == InputSpecialKey.KEY_ENTER && type == KeyChangeTypes.PRESS) {
|
||||
if (input.value.isNotBlank()) {
|
||||
connection.sendPacket(ChatMessageC2SP(input.value))
|
||||
input.value = ""
|
||||
}
|
||||
guiRenderer.gui.pop()
|
||||
return submit()
|
||||
}
|
||||
input.onSpecialKey(key, type)
|
||||
}
|
||||
@ -153,7 +157,6 @@ class ChatElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElem
|
||||
input.tick()
|
||||
}
|
||||
|
||||
|
||||
companion object : HUDBuilder<LayoutedGUIElement<ChatElement>>, GUIBuilder<LayoutedGUIElement<ChatElement>> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minosoft:chat_hud".toResourceLocation()
|
||||
private const val CHAT_INPUT_HEIGHT = Font.TOTAL_CHAR_HEIGHT * 3 + Font.CHAR_MARGIN * 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user