mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
use String::trimWhitespaces from kutil
This commit is contained in:
parent
c2248a8424
commit
81f3644565
@ -16,7 +16,7 @@ package de.bixilon.minosoft.gui.rendering.gui.gui.elements.input.node
|
||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.kutil.string.StringUtil.codePointAtOrNull
|
||||
import de.bixilon.kutil.string.TextUtil
|
||||
import de.bixilon.kutil.string.WhitespaceUtil.removeTrailingWhitespaces
|
||||
import de.bixilon.kutil.string.WhitespaceUtil.trimWhitespaces
|
||||
import de.bixilon.minosoft.commands.errors.ReaderError
|
||||
import de.bixilon.minosoft.commands.nodes.CommandNode
|
||||
import de.bixilon.minosoft.commands.stack.CommandStack
|
||||
@ -32,7 +32,6 @@ import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
|
||||
import de.bixilon.minosoft.gui.rendering.system.window.KeyChangeTypes
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
||||
import de.bixilon.minosoft.terminal.cli.CLI.removeDuplicatedWhitespaces
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
@ -121,7 +120,7 @@ class NodeTextInputElement(
|
||||
|
||||
fun updateSuggestion(suggestion: Any) {
|
||||
val string = suggestion.toString()
|
||||
val value = value.removeDuplicatedWhitespaces().removeTrailingWhitespaces()
|
||||
val value = value.trimWhitespaces()
|
||||
val overlappingLength = TextUtil.getOverlappingText(value, string)
|
||||
var nextValue = value
|
||||
val lastChar = value.codePointAtOrNull(value.length - 1)
|
||||
|
@ -41,7 +41,7 @@ class BlockDustParticle(connection: PlayConnection, position: Vec3d, velocity: V
|
||||
color = 0.6f.asGray()
|
||||
|
||||
if (data.blockState.block.resourceLocation != MinecraftBlocks.GRASS_BLOCK) { // Just the overlay is tinted
|
||||
connection.rendering!!.renderWindow.tintManager.getTint(data.blockState, null, blockPosition)?.getOrNull(0)?.asRGBColor()?.let {
|
||||
connection.rendering!!.renderWindow.tintManager.getTint(data.blockState, null, blockPosition)?.getOrNull(PARTICLE_TINT_INDEX)?.asRGBColor()?.let {
|
||||
color = RGBColor(color.floatRed * it.floatRed, color.floatGreen * it.floatGreen, color.floatBlue * it.floatBlue)
|
||||
}
|
||||
}
|
||||
@ -57,6 +57,7 @@ class BlockDustParticle(connection: PlayConnection, position: Vec3d, velocity: V
|
||||
|
||||
companion object : ParticleFactory<BlockDustParticle> {
|
||||
private const val GRAY = 153 shl 16 or (153 shl 8) or 153
|
||||
private const val PARTICLE_TINT_INDEX = 0
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:block".toResourceLocation()
|
||||
|
||||
override fun build(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData): BlockDustParticle? {
|
||||
|
@ -16,7 +16,7 @@ package de.bixilon.minosoft.protocol.network.connection.play
|
||||
import com.fasterxml.jackson.core.io.JsonStringEncoder
|
||||
import com.google.common.primitives.Longs
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kutil.string.WhitespaceUtil.removeTrailingWhitespaces
|
||||
import de.bixilon.kutil.string.WhitespaceUtil.trimWhitespaces
|
||||
import de.bixilon.minosoft.commands.stack.CommandStack
|
||||
import de.bixilon.minosoft.data.text.BaseComponent
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
@ -32,7 +32,6 @@ import de.bixilon.minosoft.protocol.packets.c2s.play.chat.SignedChatMessageC2SP
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.protocol.protocol.encryption.CryptManager
|
||||
import de.bixilon.minosoft.protocol.protocol.encryption.SignatureData
|
||||
import de.bixilon.minosoft.terminal.cli.CLI.removeDuplicatedWhitespaces
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
@ -58,13 +57,16 @@ class ConnectionUtil(
|
||||
}
|
||||
|
||||
fun sendChatMessage(message: String) {
|
||||
val message = message.removeDuplicatedWhitespaces().removeTrailingWhitespaces()
|
||||
val message = message.trimWhitespaces()
|
||||
if (message.isBlank()) {
|
||||
throw IllegalArgumentException("Chat message can not be blank!")
|
||||
}
|
||||
if (message.contains(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR)) {
|
||||
throw IllegalArgumentException("Chat message must not contain chat formatting (${ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR}): $message")
|
||||
}
|
||||
if (message.length > connection.version.maxChatMessageSize) {
|
||||
throw IllegalArgumentException("Message length (${message.length} can not exceed ${connection.version.maxChatMessageSize})")
|
||||
}
|
||||
if (connection.fireEvent(ChatMessageSendEvent(connection, message))) {
|
||||
return
|
||||
}
|
||||
|
@ -135,15 +135,16 @@ class PlayConnection(
|
||||
}
|
||||
}
|
||||
}
|
||||
network::state.observe(this) {
|
||||
when (it) {
|
||||
network::state.observe(this) { state ->
|
||||
when (state) {
|
||||
ProtocolStates.HANDSHAKING, ProtocolStates.STATUS -> throw IllegalStateException("Invalid state!")
|
||||
ProtocolStates.LOGIN -> {
|
||||
state = PlayConnectionStates.LOGGING_IN
|
||||
this.state = PlayConnectionStates.LOGGING_IN
|
||||
this.network.send(StartC2SP(this.player))
|
||||
}
|
||||
|
||||
ProtocolStates.PLAY -> {
|
||||
state = PlayConnectionStates.JOINING
|
||||
this.state = PlayConnectionStates.JOINING
|
||||
|
||||
if (CLI.connection == null) {
|
||||
CLI.connection = this
|
||||
|
@ -33,13 +33,13 @@ object DefaultPluginHandler {
|
||||
connection.pluginManager[brandChannel] = {
|
||||
connection.serverInfo.brand = it.readString()
|
||||
|
||||
sendBrand(brandChannel, connection, if (connection.profiles.connection.fakeBrand) ProtocolDefinition.VANILLA_BRAND else ProtocolDefinition.MINOSOFT_BRAND)
|
||||
connection.sendBrand(brandChannel, if (connection.profiles.connection.fakeBrand) ProtocolDefinition.VANILLA_BRAND else ProtocolDefinition.MINOSOFT_BRAND)
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendBrand(channel: ResourceLocation, connection: PlayConnection, brand: String) {
|
||||
val buffer = PlayOutByteBuffer(connection)
|
||||
private fun PlayConnection.sendBrand(channel: ResourceLocation, brand: String) {
|
||||
val buffer = PlayOutByteBuffer(this)
|
||||
buffer.writeByteArray(brand.encodeNetwork())
|
||||
connection.sendPacket(PluginC2SP(channel, buffer))
|
||||
sendPacket(PluginC2SP(channel, buffer))
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ package de.bixilon.minosoft.terminal.cli
|
||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||
import de.bixilon.kutil.shutdown.AbstractShutdownReason
|
||||
import de.bixilon.kutil.shutdown.ShutdownManager
|
||||
import de.bixilon.kutil.string.WhitespaceUtil.trimWhitespaces
|
||||
import de.bixilon.kutil.watcher.DataWatcher.Companion.observe
|
||||
import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
|
||||
import de.bixilon.minosoft.commands.nodes.RootNode
|
||||
@ -68,7 +69,7 @@ object CLI {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
val line: String = reader.readLine().removeDuplicatedWhitespaces()
|
||||
val line: String = reader.readLine().trimWhitespaces()
|
||||
if (line.isBlank()) {
|
||||
continue
|
||||
}
|
||||
@ -82,10 +83,6 @@ object CLI {
|
||||
}
|
||||
}
|
||||
|
||||
fun String.removeDuplicatedWhitespaces(): String {
|
||||
return this.replace("\\s{2,}".toRegex(), "")
|
||||
}
|
||||
|
||||
object NodeCompleter : Completer {
|
||||
|
||||
override fun complete(reader: LineReader, line: ParsedLine, candidates: MutableList<Candidate>) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user