diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_double/DoubleParser.kt b/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_double/DoubleParser.kt index 1f9dc717a..acd1e881d 100644 --- a/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_double/DoubleParser.kt +++ b/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_double/DoubleParser.kt @@ -48,6 +48,7 @@ class DoubleParser( companion object : ArgumentParserFactory { override val RESOURCE_LOCATION: ResourceLocation = "brigadier:double".toResourceLocation() + val DEFAULT = DoubleParser() override fun read(buffer: PlayInByteBuffer): DoubleParser { val flags = buffer.readUnsignedByte() diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_float/FloatParser.kt b/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_float/FloatParser.kt index be74483f8..45b78bc83 100644 --- a/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_float/FloatParser.kt +++ b/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_float/FloatParser.kt @@ -48,6 +48,7 @@ class FloatParser( companion object : ArgumentParserFactory { override val RESOURCE_LOCATION: ResourceLocation = "brigadier:float".toResourceLocation() + val DEFAULT = FloatParser() override fun read(buffer: PlayInByteBuffer): FloatParser { val flags = buffer.readUnsignedByte() diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_int/IntParser.kt b/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_int/IntParser.kt index 4d6f6dfd7..d0ceca924 100644 --- a/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_int/IntParser.kt +++ b/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_int/IntParser.kt @@ -48,6 +48,7 @@ class IntParser( companion object : ArgumentParserFactory { override val RESOURCE_LOCATION: ResourceLocation = "brigadier:integer".toResourceLocation() + val DEFAULT = IntParser() override fun read(buffer: PlayInByteBuffer): IntParser { val flags = buffer.readUnsignedByte() diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_long/LongParser.kt b/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_long/LongParser.kt index b925de3d6..327ad0961 100644 --- a/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_long/LongParser.kt +++ b/src/main/java/de/bixilon/minosoft/commands/parser/brigadier/_long/LongParser.kt @@ -48,6 +48,7 @@ class LongParser( companion object : ArgumentParserFactory { override val RESOURCE_LOCATION: ResourceLocation = "brigadier:long".toResourceLocation() + val DEFAULT = LongParser() override fun read(buffer: PlayInByteBuffer): LongParser { val flags = buffer.readUnsignedByte() diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/factory/ArgumentParserFactories.kt b/src/main/java/de/bixilon/minosoft/commands/parser/factory/ArgumentParserFactories.kt index 555253838..0085bce4e 100644 --- a/src/main/java/de/bixilon/minosoft/commands/parser/factory/ArgumentParserFactories.kt +++ b/src/main/java/de/bixilon/minosoft/commands/parser/factory/ArgumentParserFactories.kt @@ -23,9 +23,12 @@ 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._int.IntRangeParser import de.bixilon.minosoft.commands.parser.minecraft.resource.ResourceParser +import de.bixilon.minosoft.commands.parser.minecraft.resource.location.ResourceLocationParser 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.minecraft.time.TimeParser +import de.bixilon.minosoft.commands.parser.minecraft.uuid.UUIDParser import de.bixilon.minosoft.commands.parser.minosoft.dummy.DummyParser import de.bixilon.minosoft.data.registries.factory.DefaultFactory @@ -43,6 +46,10 @@ object ArgumentParserFactories : DefaultFactory>( FloatRangeParser, IntRangeParser, + UUIDParser, + ResourceLocationParser, + TimeParser, + DummyParser, ScoreHolderParser, @@ -75,17 +82,14 @@ minecraft:score_holder minecraft:swizzle minecraft:team minecraft:item_slot -minecraft:resource_location minecraft:mob_effect minecraft:function minecraft:entity_anchor minecraft:item_enchantment minecraft:entity_summon minecraft:dimension -minecraft:uuid minecraft:nbt_tag minecraft:nbt_compound_tag -minecraft:time minecraft:resource_or_tag minecraft:resource */ diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/resource/location/InvalidResourceLocationError.kt b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/resource/location/InvalidResourceLocationError.kt new file mode 100644 index 000000000..e18bb5e66 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/resource/location/InvalidResourceLocationError.kt @@ -0,0 +1,24 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.commands.parser.minecraft.resource.location + +import de.bixilon.minosoft.commands.errors.parser.ParserError +import de.bixilon.minosoft.commands.util.CommandReader +import de.bixilon.minosoft.commands.util.ReadResult +import de.bixilon.minosoft.data.registries.ResourceLocation + +class InvalidResourceLocationError( + reader: CommandReader, + result: ReadResult, +) : ParserError(reader, result) diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/resource/location/ResourceLocationParser.kt b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/resource/location/ResourceLocationParser.kt new file mode 100644 index 000000000..30ea18c49 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/resource/location/ResourceLocationParser.kt @@ -0,0 +1,41 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.commands.parser.minecraft.resource.location + +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 ResourceLocationParser : ArgumentParser, ArgumentParserFactory { + override val RESOURCE_LOCATION: ResourceLocation = "minecraft:resource_location".toResourceLocation() + override val examples: List = listOf("dirt", "minecraft:dirt") + override val placeholder = ChatComponent.of("") + + override fun parse(reader: CommandReader): ResourceLocation { + reader.readResult { readResourceLocation() }.let { return it.result ?: throw InvalidResourceLocationError(reader, it) } + } + + override fun getSuggestions(reader: CommandReader): List { + if (reader.readString()?.isBlank() != false) { + return examples + } + return emptyList() + } + + override fun read(buffer: PlayInByteBuffer) = this +} diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/target/TargetParser.kt b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/target/TargetParser.kt index dbc192985..66db0d8b7 100644 --- a/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/target/TargetParser.kt +++ b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/target/TargetParser.kt @@ -20,13 +20,13 @@ import de.bixilon.minosoft.commands.parser.factory.ArgumentParserFactory import de.bixilon.minosoft.commands.parser.minecraft.target.targets.EntityTarget import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.name.InvalidNameError import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.name.NameEntityTarget -import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.uuid.InvalidUUIDError import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.uuid.UUIDEntityTarget import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorEntityTarget import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.error.InvalidSelectorKeyError import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.error.InvalidTargetSelector import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperties import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperty +import de.bixilon.minosoft.commands.parser.minecraft.uuid.InvalidUUIDError import de.bixilon.minosoft.commands.util.CommandReader import de.bixilon.minosoft.commands.util.ReadResult import de.bixilon.minosoft.data.registries.ResourceLocation diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/time/InvalidTimeUnitError.kt b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/time/InvalidTimeUnitError.kt new file mode 100644 index 000000000..6bbb95a25 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/time/InvalidTimeUnitError.kt @@ -0,0 +1,23 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.commands.parser.minecraft.time + +import de.bixilon.minosoft.commands.errors.ReaderError +import de.bixilon.minosoft.commands.util.CommandReader + +class InvalidTimeUnitError( + reader: CommandReader, + position: Int, + read: Int?, +) : ReaderError(reader, position, position + 1) diff --git a/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/time/TimeParser.kt b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/time/TimeParser.kt new file mode 100644 index 000000000..1e34946de --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/commands/parser/minecraft/time/TimeParser.kt @@ -0,0 +1,61 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.commands.parser.minecraft.time + +import de.bixilon.minosoft.commands.parser.ArgumentParser +import de.bixilon.minosoft.commands.parser.brigadier._float.FloatParser +import de.bixilon.minosoft.commands.parser.brigadier._float.FloatParser.Companion.readFloat +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 TimeParser : ArgumentParser, ArgumentParserFactory { + override val RESOURCE_LOCATION: ResourceLocation = "minecraft:time".toResourceLocation() + override val examples: List = listOf(2400, "3d", "10s") + override val placeholder = ChatComponent.of("