From 73f95a4cc0c35a38ba9629d5a8b2dee8e1089c57 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Fri, 25 Dec 2020 11:36:59 +0100 Subject: [PATCH] cssc: more parsers --- .../minosoft/config/Configuration.java | 2 +- .../data/commands/CommandArgumentNode.java | 2 +- .../data/commands/CommandStringReader.java | 28 ++++++++- .../data/commands/parser/AngleParser.kt | 30 +++++++++ .../data/commands/parser/ColorParser.kt | 37 +++++++++++ .../data/commands/parser/CommandParsers.kt | 23 +++---- .../data/commands/parser/GameProfileParser.kt | 36 +++++++++++ .../commands/parser/IdentifierListParser.kt | 23 ++++++- .../data/commands/parser/ItemSlotParser.kt | 61 +++++++++++++++++++ .../data/commands/parser/ItemStackParser.kt | 4 +- .../data/commands/parser/ObjectiveParser.kt | 2 +- .../data/commands/parser/OperationParser.kt | 37 +++++++++++ .../data/commands/parser/RotationParser.kt | 30 +++++++++ .../commands/parser/ScoreboardSlotParser.kt | 49 +++++++++++++++ .../data/commands/parser/SwizzleParser.kt | 46 ++++++++++++++ .../data/commands/parser/TeamParser.kt | 30 +++++++++ ...SwizzleCombinationCommandParseException.kt | 25 ++++++++ .../ColorNotFoundCommandParseException.kt | 25 ++++++++ ...knownInventorySlotCommandParseException.kt | 25 ++++++++ .../UnknownOperationCommandParseException.kt | 25 ++++++++ .../DimensionNotFoundCommandParseException.kt | 26 ++++++++ ...nchantmentNotFoundCommandParseException.kt | 3 +- .../EntityNotFoundCommandParseException.kt | 26 ++++++++ .../InvalidIdentifierCommandParseException.kt | 3 +- .../ItemNotFoundCommandParseException.kt | 3 +- .../MobEffectNotFoundCommandParseException.kt | 3 +- .../properties/EntityParserProperties.java | 5 ++ .../entities/block/BedEntityMetaData.java | 2 +- .../mappings/versions/VersionMapping.java | 10 +++ .../minosoft/data/text/ChatColors.java | 11 +++- .../play/PacketDeclareCommands.java | 21 +++++++ .../play/PacketSculkVibrationSignal.java | 2 +- 32 files changed, 627 insertions(+), 28 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/AngleParser.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/ColorParser.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/GameProfileParser.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/ItemSlotParser.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/OperationParser.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/RotationParser.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/ScoreboardSlotParser.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/SwizzleParser.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/TeamParser.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/BadSwizzleCombinationCommandParseException.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/ColorNotFoundCommandParseException.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/UnknownInventorySlotCommandParseException.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/UnknownOperationCommandParseException.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/DimensionNotFoundCommandParseException.kt rename src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/{ => identifier}/EnchantmentNotFoundCommandParseException.kt (89%) create mode 100644 src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/EntityNotFoundCommandParseException.kt rename src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/{ => identifier}/InvalidIdentifierCommandParseException.kt (89%) rename src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/{ => identifier}/ItemNotFoundCommandParseException.kt (89%) rename src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/{ => identifier}/MobEffectNotFoundCommandParseException.kt (89%) diff --git a/src/main/java/de/bixilon/minosoft/config/Configuration.java b/src/main/java/de/bixilon/minosoft/config/Configuration.java index 30a681cc5..a1067913b 100644 --- a/src/main/java/de/bixilon/minosoft/config/Configuration.java +++ b/src/main/java/de/bixilon/minosoft/config/Configuration.java @@ -77,7 +77,7 @@ public class Configuration { Account account = switch (data.get("type").getAsString()) { case "mojang" -> MojangAccount.deserialize(data); case "offline" -> OfflineAccount.deserialize(data); - default -> throw new IllegalStateException("Unexpected value: " + data.get("type").getAsString()); + default -> throw new IllegalArgumentException("Unexpected value: " + data.get("type").getAsString()); }; this.accountList.put(account.getId(), account); } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java b/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java index aaf070bd7..87323c840 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java @@ -48,7 +48,7 @@ public class CommandArgumentNode extends CommandLiteralNode { case "minecraft:available_sounds" -> CommandArgumentNode.SuggestionTypes.AVAILABLE_SOUNDS; case "minecraft:summonable_entities" -> CommandArgumentNode.SuggestionTypes.SUMMONABLE_ENTITIES; case "minecraft:available_biomes" -> CommandArgumentNode.SuggestionTypes.AVAILABLE_BIOMES; - default -> throw new IllegalStateException("Unexpected value: " + fullIdentifier); + default -> throw new IllegalArgumentException("Unexpected value: " + fullIdentifier); }; } else { this.suggestionType = null; diff --git a/src/main/java/de/bixilon/minosoft/data/commands/CommandStringReader.java b/src/main/java/de/bixilon/minosoft/data/commands/CommandStringReader.java index 8d31e582a..185020222 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/CommandStringReader.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/CommandStringReader.java @@ -14,8 +14,8 @@ package de.bixilon.minosoft.data.commands; import de.bixilon.minosoft.data.commands.parser.exceptions.BooleanCommandParseException; -import de.bixilon.minosoft.data.commands.parser.exceptions.InvalidIdentifierCommandParseException; import de.bixilon.minosoft.data.commands.parser.exceptions.StringCommandParseException; +import de.bixilon.minosoft.data.commands.parser.exceptions.identifier.InvalidIdentifierCommandParseException; import de.bixilon.minosoft.data.commands.parser.exceptions.number.DoubleCommandParseException; import de.bixilon.minosoft.data.commands.parser.exceptions.number.FloatCommandParseException; import de.bixilon.minosoft.data.commands.parser.exceptions.number.IntegerCommandParseException; @@ -24,6 +24,8 @@ import de.bixilon.minosoft.data.commands.parser.exceptions.properties.BadPropert import de.bixilon.minosoft.data.commands.parser.exceptions.properties.DuplicatedPropertyKeyCommandParseException; import de.bixilon.minosoft.data.mappings.ModIdentifier; import de.bixilon.minosoft.util.Pair; +import de.bixilon.minosoft.util.nbt.tag.CompoundTag; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; @@ -32,11 +34,11 @@ public class CommandStringReader { private final String string; private int cursor; - public CommandStringReader(String string) { + public CommandStringReader(@NotNull String string) { this.string = string; } - public CommandStringReader(CommandStringReader stringReader) { + public CommandStringReader(@NotNull CommandStringReader stringReader) { this.string = stringReader.string; this.cursor = stringReader.cursor; } @@ -105,6 +107,7 @@ public class CommandStringReader { return skipped; } + @NotNull public String readUnquotedString() { StringBuilder builder = new StringBuilder(); while (canRead()) { @@ -119,6 +122,7 @@ public class CommandStringReader { return builder.toString(); } + @NotNull public String readQuotedString() throws StringCommandParseException { if (!canRead() || !peekExpected('"', '\'')) { throw new StringCommandParseException(this, String.valueOf(peek()), "String is not quoted!"); @@ -126,6 +130,7 @@ public class CommandStringReader { return readStringUntil(read()); } + @NotNull public String readNumericString() { StringBuilder builder = new StringBuilder(); while (canRead()) { @@ -140,6 +145,7 @@ public class CommandStringReader { return builder.toString(); } + @NotNull public Pair readProperty() throws StringCommandParseException, BadPropertyMapCommandParseException { skipWhitespaces(); StringBuilder builder = new StringBuilder(); @@ -154,6 +160,7 @@ public class CommandStringReader { return new Pair<>(key, value); } + @NotNull public Map readProperties() throws StringCommandParseException, DuplicatedPropertyKeyCommandParseException, BadPropertyMapCommandParseException { Map ret = new HashMap<>(); if (peek() != '[') { @@ -180,6 +187,7 @@ public class CommandStringReader { return ret; } + @NotNull public Pair readModIdentifier() throws InvalidIdentifierCommandParseException { StringBuilder builder = new StringBuilder(); while (canRead()) { @@ -199,6 +207,7 @@ public class CommandStringReader { } } + @NotNull public String readString() throws StringCommandParseException { if (!canRead()) { return ""; @@ -219,10 +228,12 @@ public class CommandStringReader { return false; } + @NotNull private String readStringUntil(boolean requiresTerminator, char terminator) throws StringCommandParseException { return readStringUntil(requiresTerminator, new char[]{terminator}).getKey(); } + @NotNull private Pair readStringUntil(boolean requiresTerminator, char... terminators) throws StringCommandParseException { StringBuilder builder = new StringBuilder(); boolean isNextCharEscaped = false; @@ -297,6 +308,7 @@ public class CommandStringReader { } } + @NotNull public Pair readStringUntilOrEnd(char... terminators) { try { return readStringUntil(false, terminators); @@ -306,10 +318,12 @@ public class CommandStringReader { } } + @NotNull public Pair readStringUntil(char... terminators) throws StringCommandParseException { return readStringUntil(true, terminators); } + @NotNull public String readStringUntilOrEnd(char terminator) { try { return readStringUntil(false, terminator); @@ -319,26 +333,34 @@ public class CommandStringReader { } } + @NotNull public String readStringUntil(char terminator) throws StringCommandParseException { return readStringUntil(true, terminator); } + public CompoundTag readNBTCompoundTag() { + throw new IllegalArgumentException("TODO"); + } + public boolean readExpected(char... expected) { boolean ret = peekExpected(expected); skip(); return ret; } + @NotNull public String readRemaining() { String ret = this.string.substring(this.cursor); this.cursor = this.string.length() + 1; return ret; } + @NotNull public String peekRemaining() { return this.string.substring(this.cursor); } + @NotNull public String getString() { return this.string; } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/AngleParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/AngleParser.kt new file mode 100644 index 000000000..9c1c8f27e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/AngleParser.kt @@ -0,0 +1,30 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties +import de.bixilon.minosoft.protocol.network.Connection + +class AngleParser : CoordinateParser() { + + @Throws(CommandParseException::class) + override fun isParsable(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader) { + readCoordinates(stringReader, true, 1) + } + + companion object { + val ANGLE_PARSER = AngleParser() + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/ColorParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/ColorParser.kt new file mode 100644 index 000000000..76ca138a4 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/ColorParser.kt @@ -0,0 +1,37 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.ColorNotFoundCommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties +import de.bixilon.minosoft.data.text.ChatColors +import de.bixilon.minosoft.protocol.network.Connection + +class ColorParser : CommandParser() { + + @Throws(CommandParseException::class) + override fun isParsable(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader) { + val color = stringReader.readUnquotedString() + try { + ChatColors.getChatFormattingByName(color) + } catch (exception: IllegalArgumentException) { + throw ColorNotFoundCommandParseException(stringReader, color, exception) + } + } + + companion object { + val COLOR_PARSER = ColorParser() + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/CommandParsers.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/CommandParsers.kt index 30f29c583..bcfc8847c 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/CommandParsers.kt +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/CommandParsers.kt @@ -25,8 +25,9 @@ object CommandParsers { ModIdentifier("brigadier:float") to FloatParser.FLOAT_PARSER, ModIdentifier("brigadier:integer") to IntegerParser.INTEGER_PARSER, ModIdentifier("brigadier:string") to StringParser.STRING_PARSER, + ModIdentifier("angle") to AngleParser.ANGLE_PARSER, ModIdentifier("entity") to EntityParser.ENTITY_PARSER, - // game_profile + ModIdentifier("game_profile") to GameProfileParser.GAME_PROFILE_PARSER, ModIdentifier("block_pos") to BlockPositionParser.BLOCK_POSITION_PARSER, ModIdentifier("column_pos") to ColumnPositionParser.COLUMN_POSITION_PARSER, ModIdentifier("vec3") to Vec3Parser.VEC3_PARSER, @@ -35,21 +36,21 @@ object CommandParsers { // block_predicate ModIdentifier("item_stack") to ItemStackParser.ITEM_STACK_PARSER, // item_predicate - // color + ModIdentifier("color") to ColorParser.COLOR_PARSER, // chat component ModIdentifier("message") to MessageParser.MESSAGE_PARSER, // nbt - // nbt_pat + // nbt_path ModIdentifier("objective") to ObjectiveParser.OBJECTIVE_PARSER, // objective_criteria - // operation + ModIdentifier("operation") to OperationParser.OPERATION_PARSER, // particle - // rotation - // scoreboard_slot + ModIdentifier("rotation") to RotationParser.ROTATION_PARSER, + ModIdentifier("scoreboard_slot") to ScoreboardSlotParser.SCOREBOARD_SLOT_PARSER, ModIdentifier("score_holder") to ScoreHolderParser.SCORE_HOLDER_PARSER, - // swizzle - // team - // item_slot + ModIdentifier("swizzle") to SwizzleParser.SWIZZLE_PARSER, + ModIdentifier("team") to TeamParser.TEAM_PARSER, + ModIdentifier("item_slot") to ItemSlotParser.ITEM_SLOT_PARSER, ModIdentifier("resource_location") to IdentifierParser.IDENTIFIER_PARSER, ModIdentifier("mob_effect") to IdentifierListParser.MOB_EFFECT_PARSER, // function @@ -58,8 +59,8 @@ object CommandParsers { ModIdentifier("int_range") to IntRangeParser.INT_RANGE_PARSER, ModIdentifier("float_range") to FloatRangeParser.FLOAT_RANGE_PARSER, ModIdentifier("item_enchantment") to IdentifierListParser.ENCHANTMENT_PARSER, - // entity_summon - // dimension + ModIdentifier("entity_summon") to IdentifierListParser.SUMMONABLE_ENTITY_PARSER, + ModIdentifier("dimension") to IdentifierListParser.DIMENSION_EFFECT_PARSER, ModIdentifier("uuid") to UUIDParser.UUID_PARSER, // nbt_tag // nbt_compound_tag diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/GameProfileParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/GameProfileParser.kt new file mode 100644 index 000000000..5645fe8c2 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/GameProfileParser.kt @@ -0,0 +1,36 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException +import de.bixilon.minosoft.data.commands.parser.properties.EntityParserProperties +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties +import de.bixilon.minosoft.protocol.network.Connection +import de.bixilon.minosoft.protocol.protocol.InByteBuffer + +class GameProfileParser(val properties: EntityParserProperties) : EntityParser() { + + override fun readParserProperties(buffer: InByteBuffer?): ParserProperties? { + return null + } + + @Throws(CommandParseException::class) + override fun isParsable(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader) { + super.isParsable(connection, properties, stringReader) + } + + companion object { + val GAME_PROFILE_PARSER = GameProfileParser(EntityParserProperties(false, false)) // ToDo own parser? + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/IdentifierListParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/IdentifierListParser.kt index b6e7bceee..3769d5078 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/IdentifierListParser.kt +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/IdentifierListParser.kt @@ -12,10 +12,13 @@ */ package de.bixilon.minosoft.data.commands.parser +import de.bixilon.minosoft.data.EntityClassMappings import de.bixilon.minosoft.data.commands.CommandStringReader import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException -import de.bixilon.minosoft.data.commands.parser.exceptions.EnchantmentNotFoundCommandParseException -import de.bixilon.minosoft.data.commands.parser.exceptions.MobEffectNotFoundCommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.identifier.DimensionNotFoundCommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.identifier.EnchantmentNotFoundCommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.identifier.EntityNotFoundCommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.identifier.MobEffectNotFoundCommandParseException import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties import de.bixilon.minosoft.protocol.network.Connection @@ -38,10 +41,26 @@ class IdentifierListParser : CommandParser() { } return } + if (this == DIMENSION_EFFECT_PARSER) { + if (!connection.mapping.doesDimensionExist(identifier.value)) { + throw DimensionNotFoundCommandParseException(stringReader, identifier.key) + } + return + } + if (this == SUMMONABLE_ENTITY_PARSER) { + // ToDo: only summonable entities, not all of them + + if (EntityClassMappings.getByIdentifier(identifier.value) == null) { + throw EntityNotFoundCommandParseException(stringReader, identifier.key) + } + return + } } companion object { val ENCHANTMENT_PARSER = IdentifierListParser() val MOB_EFFECT_PARSER = IdentifierListParser() + val DIMENSION_EFFECT_PARSER = IdentifierListParser() + val SUMMONABLE_ENTITY_PARSER = IdentifierListParser() } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/ItemSlotParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/ItemSlotParser.kt new file mode 100644 index 000000000..adf2753ca --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/ItemSlotParser.kt @@ -0,0 +1,61 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.UnknownInventorySlotCommandParseException +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties +import de.bixilon.minosoft.protocol.network.Connection + +class ItemSlotParser : CommandParser() { + + @Throws(CommandParseException::class) + override fun isParsable(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader) { + val slot = stringReader.readUnquotedString() + + if (!SLOTS.contains(slot)) { + throw UnknownInventorySlotCommandParseException(stringReader, slot) + } + + } + + companion object { + private val SLOTS = HashSet() + + init { + + for (i in 0 until 54) { + SLOTS.add("container.$i") + } + for (i in 0 until 9) { + SLOTS.add("hotbar.$i") + } + for (i in 0 until 27) { + SLOTS.add("inventory." + (9 + i)) + } + for (i in 0 until 27) { + SLOTS.add("enderchest." + (200 + i)) + } + for (i in 0 until 8) { + SLOTS.add("villager." + (300 + i)) + } + for (i in 0 until 15) { + SLOTS.add("horse." + (500 + i)) + } + SLOTS.addAll(setOf("weapon", "weapon.mainhand", "weapon.offhand", "armor.head", "armor.chest", "armor.legs", "armor.feet", "horse.saddle", "horse.armor", "horse.chest")) + } + + val ITEM_SLOT_PARSER = ItemSlotParser() + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/ItemStackParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/ItemStackParser.kt index 0941f0563..caeb13d19 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/ItemStackParser.kt +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/ItemStackParser.kt @@ -14,7 +14,7 @@ package de.bixilon.minosoft.data.commands.parser import de.bixilon.minosoft.data.commands.CommandStringReader import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException -import de.bixilon.minosoft.data.commands.parser.exceptions.ItemNotFoundCommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.identifier.ItemNotFoundCommandParseException import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties import de.bixilon.minosoft.protocol.network.Connection @@ -27,7 +27,7 @@ class ItemStackParser : CommandParser() { throw ItemNotFoundCommandParseException(stringReader, argument.key) } if (stringReader.peek() == '{') { - throw TODO("NBT Data needs to be implemented") + stringReader.readNBTCompoundTag() } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/ObjectiveParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/ObjectiveParser.kt index c01a6d0b0..2dbe4aea6 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/ObjectiveParser.kt +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/ObjectiveParser.kt @@ -14,7 +14,7 @@ package de.bixilon.minosoft.data.commands.parser import de.bixilon.minosoft.data.commands.CommandStringReader import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException -import de.bixilon.minosoft.data.commands.parser.exceptions.InvalidIdentifierCommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.identifier.InvalidIdentifierCommandParseException import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties import de.bixilon.minosoft.protocol.network.Connection import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/OperationParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/OperationParser.kt new file mode 100644 index 000000000..6e9793969 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/OperationParser.kt @@ -0,0 +1,37 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.UnknownOperationCommandParseException +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties +import de.bixilon.minosoft.protocol.network.Connection + +class OperationParser : CommandParser() { + + @Throws(CommandParseException::class) + override fun isParsable(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader) { + val operation = stringReader.readUnquotedString() + + if (!OPERATIONS.contains(operation)) { + throw UnknownOperationCommandParseException(stringReader, operation) + } + + } + + companion object { + private val OPERATIONS = setOf("=", "+=", "-=", "*=", "/=", "%=", "<", ">", "><") + val OPERATION_PARSER = OperationParser() + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/RotationParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/RotationParser.kt new file mode 100644 index 000000000..031ebcdb6 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/RotationParser.kt @@ -0,0 +1,30 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties +import de.bixilon.minosoft.protocol.network.Connection + +class RotationParser : CoordinateParser() { + + @Throws(CommandParseException::class) + override fun isParsable(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader) { + readCoordinates(stringReader, true, 2) + } + + companion object { + val ROTATION_PARSER = RotationParser() + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/ScoreboardSlotParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/ScoreboardSlotParser.kt new file mode 100644 index 000000000..b80913d34 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/ScoreboardSlotParser.kt @@ -0,0 +1,49 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.ColorNotFoundCommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.UnknownOperationCommandParseException +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties +import de.bixilon.minosoft.data.text.ChatColors +import de.bixilon.minosoft.protocol.network.Connection + +class ScoreboardSlotParser : CommandParser() { + + @Throws(CommandParseException::class) + override fun isParsable(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader) { + val slot = stringReader.readUnquotedString() + + if (slot.startsWith("sidebar.team.")) { + val color = slot.substring("sidebar.team.".length) + try { + ChatColors.getChatFormattingByName(color) + } catch (exception: IllegalArgumentException) { + throw ColorNotFoundCommandParseException(stringReader, color) + } + return + } + + if (!SCOREBOARD_SLOTS.contains(slot)) { + throw UnknownOperationCommandParseException(stringReader, slot) + } + + } + + companion object { + private val SCOREBOARD_SLOTS = setOf("list", "sidebar", "belowName") + val SCOREBOARD_SLOT_PARSER = ScoreboardSlotParser() + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/SwizzleParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/SwizzleParser.kt new file mode 100644 index 000000000..2ea556d6c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/SwizzleParser.kt @@ -0,0 +1,46 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.BadSwizzleCombinationCommandParseException +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties +import de.bixilon.minosoft.protocol.network.Connection + +class SwizzleParser : CommandParser() { + + @Throws(CommandParseException::class) + override fun isParsable(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader) { + val swizzle = stringReader.readUnquotedString() + + val containing: HashSet = HashSet() + + for (char in swizzle.toCharArray()) { + when (char) { + 'x', 'y', 'z' -> { + if (containing.contains(char)) { + throw BadSwizzleCombinationCommandParseException(stringReader, swizzle) + } + containing.add(char) + } + else -> throw BadSwizzleCombinationCommandParseException(stringReader, swizzle) + } + } + + } + + companion object { + val SWIZZLE_PARSER = SwizzleParser() + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/TeamParser.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/TeamParser.kt new file mode 100644 index 000000000..3fb0a3b8b --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/TeamParser.kt @@ -0,0 +1,30 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties +import de.bixilon.minosoft.protocol.network.Connection + +class TeamParser : CommandParser() { + + @Throws(CommandParseException::class) + override fun isParsable(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader) { + stringReader.readUnquotedString() + } + + companion object { + val TEAM_PARSER = TeamParser() + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/BadSwizzleCombinationCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/BadSwizzleCombinationCommandParseException.kt new file mode 100644 index 000000000..757347040 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/BadSwizzleCombinationCommandParseException.kt @@ -0,0 +1,25 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser.exceptions + +import de.bixilon.minosoft.data.commands.CommandStringReader + +class BadSwizzleCombinationCommandParseException : CommandParseException { + constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) + + constructor(command: CommandStringReader, currentArgument: String, cause: Throwable) : super(ERROR_MESSAGE, command, currentArgument, cause) + + companion object { + private const val ERROR_MESSAGE = "Bad combination (use x, y and/or z)!" + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/ColorNotFoundCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/ColorNotFoundCommandParseException.kt new file mode 100644 index 000000000..e3271931d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/ColorNotFoundCommandParseException.kt @@ -0,0 +1,25 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser.exceptions + +import de.bixilon.minosoft.data.commands.CommandStringReader + +class ColorNotFoundCommandParseException : CommandParseException { + constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) + + constructor(command: CommandStringReader, currentArgument: String, cause: Throwable) : super(ERROR_MESSAGE, command, currentArgument, cause) + + companion object { + private const val ERROR_MESSAGE = "Unknown color!" + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/UnknownInventorySlotCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/UnknownInventorySlotCommandParseException.kt new file mode 100644 index 000000000..0cfe3bd70 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/UnknownInventorySlotCommandParseException.kt @@ -0,0 +1,25 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser.exceptions + +import de.bixilon.minosoft.data.commands.CommandStringReader + +class UnknownInventorySlotCommandParseException : CommandParseException { + constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) + + constructor(command: CommandStringReader, currentArgument: String, cause: Throwable) : super(ERROR_MESSAGE, command, currentArgument, cause) + + companion object { + private const val ERROR_MESSAGE = "Unknown slot!" + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/UnknownOperationCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/UnknownOperationCommandParseException.kt new file mode 100644 index 000000000..16e681cb2 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/UnknownOperationCommandParseException.kt @@ -0,0 +1,25 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser.exceptions + +import de.bixilon.minosoft.data.commands.CommandStringReader + +class UnknownOperationCommandParseException : CommandParseException { + constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) + + constructor(command: CommandStringReader, currentArgument: String, cause: Throwable) : super(ERROR_MESSAGE, command, currentArgument, cause) + + companion object { + private const val ERROR_MESSAGE = "Unknown operation!" + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/DimensionNotFoundCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/DimensionNotFoundCommandParseException.kt new file mode 100644 index 000000000..3c4438897 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/DimensionNotFoundCommandParseException.kt @@ -0,0 +1,26 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser.exceptions.identifier + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException + +class DimensionNotFoundCommandParseException : CommandParseException { + constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) + + constructor(command: CommandStringReader, currentArgument: String, cause: Throwable) : super(ERROR_MESSAGE, command, currentArgument, cause) + + companion object { + private const val ERROR_MESSAGE = "Dimension not found!" + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/EnchantmentNotFoundCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/EnchantmentNotFoundCommandParseException.kt similarity index 89% rename from src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/EnchantmentNotFoundCommandParseException.kt rename to src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/EnchantmentNotFoundCommandParseException.kt index 4b708d522..4cf928282 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/EnchantmentNotFoundCommandParseException.kt +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/EnchantmentNotFoundCommandParseException.kt @@ -10,9 +10,10 @@ * * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.data.commands.parser.exceptions +package de.bixilon.minosoft.data.commands.parser.exceptions.identifier import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException class EnchantmentNotFoundCommandParseException : CommandParseException { constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/EntityNotFoundCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/EntityNotFoundCommandParseException.kt new file mode 100644 index 000000000..774d0514c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/EntityNotFoundCommandParseException.kt @@ -0,0 +1,26 @@ +/* + * Minosoft + * Copyright (C) 2020 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.data.commands.parser.exceptions.identifier + +import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException + +class EntityNotFoundCommandParseException : CommandParseException { + constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) + + constructor(command: CommandStringReader, currentArgument: String, cause: Throwable) : super(ERROR_MESSAGE, command, currentArgument, cause) + + companion object { + private const val ERROR_MESSAGE = "Entity not found!" + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/InvalidIdentifierCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/InvalidIdentifierCommandParseException.kt similarity index 89% rename from src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/InvalidIdentifierCommandParseException.kt rename to src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/InvalidIdentifierCommandParseException.kt index 614d23a57..e7ae66a74 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/InvalidIdentifierCommandParseException.kt +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/InvalidIdentifierCommandParseException.kt @@ -10,9 +10,10 @@ * * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.data.commands.parser.exceptions +package de.bixilon.minosoft.data.commands.parser.exceptions.identifier import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException class InvalidIdentifierCommandParseException : CommandParseException { constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/ItemNotFoundCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/ItemNotFoundCommandParseException.kt similarity index 89% rename from src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/ItemNotFoundCommandParseException.kt rename to src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/ItemNotFoundCommandParseException.kt index 7fc23d1eb..31106eee3 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/ItemNotFoundCommandParseException.kt +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/ItemNotFoundCommandParseException.kt @@ -10,9 +10,10 @@ * * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.data.commands.parser.exceptions +package de.bixilon.minosoft.data.commands.parser.exceptions.identifier import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException class ItemNotFoundCommandParseException : CommandParseException { constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/MobEffectNotFoundCommandParseException.kt b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/MobEffectNotFoundCommandParseException.kt similarity index 89% rename from src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/MobEffectNotFoundCommandParseException.kt rename to src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/MobEffectNotFoundCommandParseException.kt index 5647d4aff..06d229450 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/MobEffectNotFoundCommandParseException.kt +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/identifier/MobEffectNotFoundCommandParseException.kt @@ -10,9 +10,10 @@ * * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.data.commands.parser.exceptions +package de.bixilon.minosoft.data.commands.parser.exceptions.identifier import de.bixilon.minosoft.data.commands.CommandStringReader +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException class MobEffectNotFoundCommandParseException : CommandParseException { constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument) diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/EntityParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/EntityParserProperties.java index e3c92d850..ba638a94c 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/EntityParserProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/EntityParserProperties.java @@ -26,6 +26,11 @@ public class EntityParserProperties implements ParserProperties { this.onlyPlayers = BitByte.isBitMask(flags, 0x02); } + public EntityParserProperties(boolean onlySingleEntity, boolean onlyPlayers) { + this.onlySingleEntity = onlySingleEntity; + this.onlyPlayers = onlyPlayers; + } + public boolean isOnlySingleEntity() { return this.onlySingleEntity; } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/BedEntityMetaData.java b/src/main/java/de/bixilon/minosoft/data/entities/block/BedEntityMetaData.java index eb35a9043..23316c2e9 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/BedEntityMetaData.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/BedEntityMetaData.java @@ -53,7 +53,7 @@ public class BedEntityMetaData extends BlockEntityMetaData { case 13 -> new RGBColor(77, 97, 34); // green case 14 -> new RGBColor(139, 30, 31); // red case 15 -> new RGBColor(15, 16, 19); // black - default -> throw new IllegalStateException("Unexpected value: " + ((IntTag) nbt).getValue()); + default -> throw new IllegalArgumentException("Unexpected value: " + ((IntTag) nbt).getValue()); }; } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java b/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java index e78db2830..c2c045e39 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java @@ -605,4 +605,14 @@ public class VersionMapping { } return this.mobEffectMap.containsValue(identifier); } + + public boolean doesDimensionExist(ModIdentifier identifier) { + if (this.parentMapping != null) { + if (this.parentMapping.doesDimensionExist(identifier)) { + return true; + } + } + return this.dimensionMap.containsValue(identifier); + } + } diff --git a/src/main/java/de/bixilon/minosoft/data/text/ChatColors.java b/src/main/java/de/bixilon/minosoft/data/text/ChatColors.java index 8ed44b865..47c56432b 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/ChatColors.java +++ b/src/main/java/de/bixilon/minosoft/data/text/ChatColors.java @@ -89,6 +89,10 @@ public final class ChatColors { } public static RGBColor getColorByName(String name) { + return (RGBColor) getChatFormattingByName(name); + } + + public static ChatCode getChatFormattingByName(String name) { return switch (name.toLowerCase()) { case "black" -> BLACK; case "dark_blue" -> DARK_BLUE; @@ -106,7 +110,12 @@ public final class ChatColors { case "light_purple" -> LIGHT_PURPLE; case "yellow" -> YELLOW; case "white", "reset" -> WHITE; - default -> throw new IllegalStateException("Unexpected value: " + name); + case "bold" -> PreChatFormattingCodes.BOLD; + case "italic" -> PreChatFormattingCodes.ITALIC; + case "underlined" -> PreChatFormattingCodes.UNDERLINED; + case "strikethrough" -> PreChatFormattingCodes.STRIKETHROUGH; + case "obfuscated" -> PreChatFormattingCodes.OBFUSCATED; + default -> throw new IllegalArgumentException("Unexpected value: " + name); }; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareCommands.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareCommands.java index 807f2924d..fda4704ba 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareCommands.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareCommands.java @@ -15,6 +15,7 @@ package de.bixilon.minosoft.protocol.packets.clientbound.play; import de.bixilon.minosoft.data.commands.CommandNode; import de.bixilon.minosoft.data.commands.CommandRootNode; +import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.network.Connection; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; @@ -37,6 +38,26 @@ public class PacketDeclareCommands extends ClientboundPacket { @Override public void handle(Connection connection) { connection.setCommandRootNode(getRootNode()); + // ToDo: Remove these dummy commands + String[] commands = { + "setblock ~3 ^3 3 minecraft:anvil", + "setblock ~3 3 3 minecraft:anvila", + "setblock ~3 3 3 minecraft:anvil[facing=east]", + "setblock ~3 3 3 minecraft:anvil[facing=\"east\"]", + "setblock ~3 3 3 minecraft:anvil[facing=east\"]", + "setblock ~3 3 3 minecraft:anvil[facing=aeast]", + }; + for (String command : commands) { + try { + getRootNode().isSyntaxCorrect(connection, command); + Log.game("Command \"%s\" is valid", command); + } catch (CommandParseException e) { + Log.game("Command \"%s\" is invalid, %s: %s", command, e.getClass().getSimpleName(), e.getErrorMessage()); + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } } @Override diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSculkVibrationSignal.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSculkVibrationSignal.java index 64a23c2d2..4ea07a818 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSculkVibrationSignal.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSculkVibrationSignal.java @@ -32,7 +32,7 @@ public class PacketSculkVibrationSignal extends ClientboundPacket { this.vibrationTargetData = switch (this.vibrationTargetType.getFullIdentifier()) { case "minecraft:block" -> buffer.readPosition(); // sculk source position case "minecraft:entity" -> buffer.readEntityId(); - default -> throw new IllegalStateException("Unexpected value: " + this.vibrationTargetType.getFullIdentifier()); + default -> throw new IllegalArgumentException("Unexpected value: " + this.vibrationTargetType.getFullIdentifier()); }; this.arrivalTicks = buffer.readVarInt(); return true;