mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
brigadier: message parser, msg command integration test
This commit is contained in:
parent
df2dccf56f
commit
661d7833ef
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2023 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
|
||||||
|
|
||||||
|
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||||
|
import de.bixilon.minosoft.commands.nodes.ArgumentNode
|
||||||
|
import de.bixilon.minosoft.commands.nodes.LiteralNode
|
||||||
|
import de.bixilon.minosoft.commands.nodes.RootNode
|
||||||
|
import de.bixilon.minosoft.commands.parser.minecraft.message.MessageParser
|
||||||
|
import de.bixilon.minosoft.commands.parser.minecraft.target.TargetParser
|
||||||
|
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.name.NameEntityTarget
|
||||||
|
import de.bixilon.minosoft.commands.stack.CommandStack
|
||||||
|
import org.testng.Assert.*
|
||||||
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
|
@Test(groups = ["command"])
|
||||||
|
class MsgCommandIT {
|
||||||
|
|
||||||
|
private fun createNode(executor: (CommandStack) -> Unit): RootNode {
|
||||||
|
return RootNode().addChild(
|
||||||
|
LiteralNode("msg").addChild(
|
||||||
|
ArgumentNode("targets", TargetParser()).addChild(
|
||||||
|
ArgumentNode("message", MessageParser, executor = executor)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).unsafeCast()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun basicExecution() {
|
||||||
|
var executed = false
|
||||||
|
val node = createNode { executed = true }
|
||||||
|
|
||||||
|
node.execute("msg Bixilon hi there!")
|
||||||
|
|
||||||
|
assertTrue(executed)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun validateStack() {
|
||||||
|
val node = createNode {
|
||||||
|
assertNotNull(it["msg"])
|
||||||
|
assertEquals(it["targets"], NameEntityTarget("Bixilon"))
|
||||||
|
assertEquals(it["message"], "hi there!")
|
||||||
|
}
|
||||||
|
|
||||||
|
node.execute("msg Bixilon hi there!")
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@ import de.bixilon.minosoft.commands.parser.minecraft.coordinate.block.BlockPosit
|
|||||||
import de.bixilon.minosoft.commands.parser.minecraft.coordinate.rotation.RotationParser
|
import de.bixilon.minosoft.commands.parser.minecraft.coordinate.rotation.RotationParser
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.coordinate.vec2.Vec2Parser
|
import de.bixilon.minosoft.commands.parser.minecraft.coordinate.vec2.Vec2Parser
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.coordinate.vec3.Vec3Parser
|
import de.bixilon.minosoft.commands.parser.minecraft.coordinate.vec3.Vec3Parser
|
||||||
|
import de.bixilon.minosoft.commands.parser.minecraft.message.MessageParser
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range.RangeParserFactory
|
import de.bixilon.minosoft.commands.parser.minecraft.range.RangeParserFactory
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRangeParser
|
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRangeParser
|
||||||
import de.bixilon.minosoft.commands.parser.minecraft.range._int.IntRangeParser
|
import de.bixilon.minosoft.commands.parser.minecraft.range._int.IntRangeParser
|
||||||
@ -69,6 +70,8 @@ object ArgumentParserFactories : DefaultFactory<ArgumentParserFactory<*>>(
|
|||||||
|
|
||||||
ChatComponentParser,
|
ChatComponentParser,
|
||||||
|
|
||||||
|
MessageParser,
|
||||||
|
|
||||||
DummyParser,
|
DummyParser,
|
||||||
|
|
||||||
ScoreHolderParser,
|
ScoreHolderParser,
|
||||||
@ -85,7 +88,6 @@ object ArgumentParserFactories : DefaultFactory<ArgumentParserFactory<*>>(
|
|||||||
minecraft:block_predicate
|
minecraft:block_predicate
|
||||||
minecraft:item_stack
|
minecraft:item_stack
|
||||||
minecraft:item_predicate
|
minecraft:item_predicate
|
||||||
minecraft:message, SIGNED
|
|
||||||
minecraft:nbt
|
minecraft:nbt
|
||||||
minecraft:nbt_path
|
minecraft:nbt_path
|
||||||
minecraft:objective
|
minecraft:objective
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2023 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.minecraft.message
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.commands.parser.ArgumentParser
|
||||||
|
import de.bixilon.minosoft.commands.parser.SignedParser
|
||||||
|
import de.bixilon.minosoft.commands.parser.brigadier.string.StringParser
|
||||||
|
import de.bixilon.minosoft.commands.parser.factory.ArgumentParserFactory
|
||||||
|
import de.bixilon.minosoft.commands.util.CommandReader
|
||||||
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
||||||
|
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||||
|
|
||||||
|
object MessageParser : ArgumentParser<String>, ArgumentParserFactory<MessageParser>, SignedParser {
|
||||||
|
override val identifier: ResourceLocation = minecraft("message")
|
||||||
|
override val examples: List<Any> = listOf("hi there!")
|
||||||
|
private val parser = StringParser(StringParser.StringModes.GREEDY)
|
||||||
|
|
||||||
|
override fun parse(reader: CommandReader): String {
|
||||||
|
if (!reader.canPeek()) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return parser.parse(reader)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSuggestions(reader: CommandReader): List<Any> {
|
||||||
|
if (reader.readString()?.isBlank() != false) {
|
||||||
|
return examples
|
||||||
|
}
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun read(buffer: PlayInByteBuffer) = this
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user