cli: use dummy parser as failover

This commit is contained in:
Bixilon 2022-05-20 13:34:09 +02:00
parent de3800ba62
commit 11ac933cd5
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 45 additions and 3 deletions

View File

@ -26,6 +26,7 @@ import de.bixilon.minosoft.commands.parser.minecraft.resource.ResourceParser
import de.bixilon.minosoft.commands.parser.minecraft.resource.tag.ResourceOrTagParser
import de.bixilon.minosoft.commands.parser.minecraft.score.holder.ScoreHolderParser
import de.bixilon.minosoft.commands.parser.minecraft.target.TargetParser
import de.bixilon.minosoft.commands.parser.minosoft.dummy.DummyParser
import de.bixilon.minosoft.data.registries.factory.DefaultFactory
object ArgumentParserFactories : DefaultFactory<ArgumentParserFactory<*>>(
@ -42,6 +43,8 @@ object ArgumentParserFactories : DefaultFactory<ArgumentParserFactory<*>>(
FloatRangeParser,
IntRangeParser,
DummyParser,
ScoreHolderParser,
ResourceParser,
ResourceOrTagParser,

View File

@ -0,0 +1,38 @@
/*
* 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.commands.parser.minosoft.dummy
import de.bixilon.minosoft.commands.parser.ArgumentParser
import de.bixilon.minosoft.commands.parser.factory.ArgumentParserFactory
import de.bixilon.minosoft.commands.util.CommandReader
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.KUtil.toResourceLocation
object DummyParser : ArgumentParser<Any>, ArgumentParserFactory<DummyParser> {
override val RESOURCE_LOCATION: ResourceLocation = "minosoft:dummy".toResourceLocation()
override val examples: List<Any> = listOf("?")
override val placeholder = ChatComponent.of("<?>")
override fun parse(reader: CommandReader): String {
return "?"
}
override fun getSuggestions(reader: CommandReader): List<Any> {
return examples
}
override fun read(buffer: PlayInByteBuffer) = this
}

View File

@ -15,5 +15,4 @@ package de.bixilon.minosoft.commands.suggestion.factory
import de.bixilon.minosoft.data.registries.factory.DefaultFactory
object SuggestionFactories : DefaultFactory<SuggestionFactory<*>>(
)
object SuggestionFactories : DefaultFactory<SuggestionFactory<*>>()

View File

@ -51,8 +51,8 @@ class CommandsS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
for ((childIndex, child) in it.withIndex()) {
children[childIndex] = nodes[child] ?: throw IllegalArgumentException("Invalid child: $child for $childIndex")
}
node.redirect = children.unsafeCast()
}
builder.redirectNode?.let { node.redirect = nodes[it] }
}
return nodes.unsafeCast()

View File

@ -19,6 +19,7 @@ import de.bixilon.minosoft.commands.nodes.NamedNode
import de.bixilon.minosoft.commands.nodes.builder.ArgumentNodes
import de.bixilon.minosoft.commands.nodes.builder.CommandNodeBuilder
import de.bixilon.minosoft.commands.parser.factory.ArgumentParserFactories
import de.bixilon.minosoft.commands.parser.minosoft.dummy.DummyParser
import de.bixilon.minosoft.commands.suggestion.factory.SuggestionFactories
import de.bixilon.minosoft.data.container.ItemStackUtil
import de.bixilon.minosoft.data.container.stack.ItemStack
@ -301,6 +302,7 @@ class PlayInByteBuffer : InByteBuffer {
val parser = ArgumentParserFactories[parserName]
if (parser == null) {
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Can not find parser: $parserName" }
builder.parser = DummyParser
} else {
builder.parser = parser.read(this)
}