diff --git a/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java b/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java new file mode 100644 index 000000000..226fae2dd --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java @@ -0,0 +1,65 @@ +/* + * 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; + +import de.bixilon.minosoft.data.commands.parser.CommandParser; +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.util.BitByte; + +import javax.annotation.Nullable; + +public class CommandArgumentNode extends CommandLiteralNode { + private final CommandParser parser; + private final ParserProperties properties; + private final SuggestionTypes suggestionType; + + public CommandArgumentNode(byte flags, InByteBuffer buffer) { + super(flags, buffer); + parser = CommandParser.createInstance(buffer.readIdentifier()); + properties = parser.readParserProperties(buffer); + if (BitByte.isBitMask(flags, 0x10)) { + String fullIdentifier = buffer.readIdentifier().getFullIdentifier(); + suggestionType = switch (fullIdentifier) { + case "minecraft:ask_server" -> CommandArgumentNode.SuggestionTypes.ASK_SERVER; + case "minecraft:all_recipes " -> CommandArgumentNode.SuggestionTypes.ALL_RECIPES; + case "minecraft:available_sounds " -> CommandArgumentNode.SuggestionTypes.AVAILABLE_SOUNDS; + case "minecraft:summonable_entities " -> CommandArgumentNode.SuggestionTypes.SUMMONABLE_ENTITIES; + default -> throw new IllegalStateException("Unexpected value: " + fullIdentifier); + }; + } else { + suggestionType = null; + } + } + + public CommandParser getParser() { + return parser; + } + + @Nullable + public ParserProperties getProperties() { + return properties; + } + + public SuggestionTypes getSuggestionType() { + return suggestionType; + } + + public enum SuggestionTypes { + ASK_SERVER, + ALL_RECIPES, + AVAILABLE_SOUNDS, + SUMMONABLE_ENTITIES + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/CommandLiteralNode.java b/src/main/java/de/bixilon/minosoft/data/commands/CommandLiteralNode.java new file mode 100644 index 000000000..92c6f9ffe --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/CommandLiteralNode.java @@ -0,0 +1,29 @@ +/* + * 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; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +public class CommandLiteralNode extends CommandNode { + private final String name; + + public CommandLiteralNode(byte flags, InByteBuffer buffer) { + super(flags, buffer); + name = buffer.readString(); + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/CommandNode.java b/src/main/java/de/bixilon/minosoft/data/commands/CommandNode.java new file mode 100644 index 000000000..4412f6dfe --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/CommandNode.java @@ -0,0 +1,74 @@ +/* + * 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; + +import com.google.errorprone.annotations.DoNotCall; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.util.BitByte; + +import java.util.HashSet; + +public abstract class CommandNode { + protected final boolean isExecutable; + protected final HashSet children = new HashSet<>(); + protected final int[] childrenIds; + protected final int redirectNodeId; + protected CommandNode redirectNode; + + public CommandNode(byte flags, InByteBuffer buffer) { + this.isExecutable = BitByte.isBitMask(flags, 0x04); + childrenIds = buffer.readVarIntArray(); + if (BitByte.isBitMask(flags, 0x08)) { + redirectNodeId = buffer.readVarInt(); + } else { + redirectNodeId = -1; + } + } + + public boolean isExecutable() { + return isExecutable; + } + + public HashSet getChildren() { + return children; + } + + public CommandNode getRedirectNode() { + return redirectNode; + } + + @DoNotCall + public void setRedirectNode(CommandNode redirectNode) { + if (this.redirectNode != null) { + throw new IllegalArgumentException("Object already initialized!"); + } + this.redirectNode = redirectNode; + } + + @DoNotCall + public int getRedirectNodeId() { + return redirectNodeId; + } + + @DoNotCall + public int[] getChildrenIds() { + return childrenIds; + } + + public enum NodeTypes { + ROOT, + LITERAL, + ARGUMENT + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/CommandRootNode.java b/src/main/java/de/bixilon/minosoft/data/commands/CommandRootNode.java new file mode 100644 index 000000000..70d7ab123 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/CommandRootNode.java @@ -0,0 +1,22 @@ +/* + * 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; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +public class CommandRootNode extends CommandNode { + public CommandRootNode(byte flags, InByteBuffer buffer) { + super(flags, buffer); + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/BooleanParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/BooleanParser.java new file mode 100644 index 000000000..d9edda9ee --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/BooleanParser.java @@ -0,0 +1,17 @@ +/* + * 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; + +public class BooleanParser extends CommandParser { +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/CommandParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/CommandParser.java new file mode 100644 index 000000000..28746059c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/CommandParser.java @@ -0,0 +1,48 @@ +/* + * 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 com.google.common.collect.HashBiMap; +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties; +import de.bixilon.minosoft.data.mappings.ModIdentifier; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +import javax.annotation.Nullable; + +public abstract class CommandParser { + @Deprecated + private static final DummyParser dummyParser = new DummyParser(); + public static HashBiMap COMMAND_PARSERS = HashBiMap.create(); + + static { + COMMAND_PARSERS.put(new ModIdentifier("brigadier:bool"), new BooleanParser()); + COMMAND_PARSERS.put(new ModIdentifier("brigadier:double"), new DoubleParser()); + COMMAND_PARSERS.put(new ModIdentifier("brigadier:float"), new FloatParser()); + COMMAND_PARSERS.put(new ModIdentifier("brigadier:integer"), new IntegerParser()); + COMMAND_PARSERS.put(new ModIdentifier("brigadier:string"), new StringParser()); + COMMAND_PARSERS.put(new ModIdentifier("entity"), new EntityParser()); + COMMAND_PARSERS.put(new ModIdentifier("score_holder"), new ScoreHolderParser()); + COMMAND_PARSERS.put(new ModIdentifier("range"), new RangeParser()); + } + + public static CommandParser createInstance(ModIdentifier identifier) { + return COMMAND_PARSERS.getOrDefault(identifier, dummyParser); + } + + @Nullable + public ParserProperties readParserProperties(InByteBuffer buffer) { + return null; + } + +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/DoubleParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/DoubleParser.java new file mode 100644 index 000000000..e9fd469d8 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/DoubleParser.java @@ -0,0 +1,32 @@ +/* + * 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.parser.properties.DoubleParserProperties; +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +import javax.annotation.Nullable; + +public class DoubleParser extends CommandParser { + public boolean isValidValue(DoubleParserProperties properties, double value) { + return value >= properties.getMinValue() && value <= properties.getMaxValue(); + } + + @Override + @Nullable + public ParserProperties readParserProperties(InByteBuffer buffer) { + return new DoubleParserProperties(buffer); + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/DummyParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/DummyParser.java new file mode 100644 index 000000000..3f9ff090a --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/DummyParser.java @@ -0,0 +1,18 @@ +/* + * 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; + +@Deprecated +public class DummyParser extends CommandParser { +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/EntityParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/EntityParser.java new file mode 100644 index 000000000..e5e883c6d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/EntityParser.java @@ -0,0 +1,28 @@ +/* + * 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.parser.properties.EntityParserProperties; +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +import javax.annotation.Nullable; + +public class EntityParser extends CommandParser { + @Override + @Nullable + public ParserProperties readParserProperties(InByteBuffer buffer) { + return new EntityParserProperties(buffer); + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/FloatParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/FloatParser.java new file mode 100644 index 000000000..0b39ade7f --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/FloatParser.java @@ -0,0 +1,32 @@ +/* + * 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.parser.properties.FloatParserProperties; +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +import javax.annotation.Nullable; + +public class FloatParser extends CommandParser { + public boolean isValidValue(FloatParserProperties properties, float value) { + return value >= properties.getMinValue() && value <= properties.getMaxValue(); + } + + @Override + @Nullable + public ParserProperties readParserProperties(InByteBuffer buffer) { + return new FloatParserProperties(buffer); + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/IntegerParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/IntegerParser.java new file mode 100644 index 000000000..e28e69d90 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/IntegerParser.java @@ -0,0 +1,32 @@ +/* + * 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.parser.properties.IntegerParserProperties; +import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +import javax.annotation.Nullable; + +public class IntegerParser extends CommandParser { + public boolean isValidValue(IntegerParserProperties properties, int value) { + return value >= properties.getMinValue() && value <= properties.getMaxValue(); + } + + @Override + @Nullable + public ParserProperties readParserProperties(InByteBuffer buffer) { + return new IntegerParserProperties(buffer); + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/RangeParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/RangeParser.java new file mode 100644 index 000000000..53a8fa3e7 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/RangeParser.java @@ -0,0 +1,28 @@ +/* + * 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.parser.properties.ParserProperties; +import de.bixilon.minosoft.data.commands.parser.properties.RangeParserProperties; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +import javax.annotation.Nullable; + +public class RangeParser extends CommandParser { + @Override + @Nullable + public ParserProperties readParserProperties(InByteBuffer buffer) { + return new RangeParserProperties(buffer); + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/ScoreHolderParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/ScoreHolderParser.java new file mode 100644 index 000000000..b7e3602cf --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/ScoreHolderParser.java @@ -0,0 +1,28 @@ +/* + * 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.parser.properties.ParserProperties; +import de.bixilon.minosoft.data.commands.parser.properties.ScoreHolderParserProperties; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +import javax.annotation.Nullable; + +public class ScoreHolderParser extends CommandParser { + @Override + @Nullable + public ParserProperties readParserProperties(InByteBuffer buffer) { + return new ScoreHolderParserProperties(buffer); + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/StringParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/StringParser.java new file mode 100644 index 000000000..455934677 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/StringParser.java @@ -0,0 +1,28 @@ +/* + * 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.parser.properties.ParserProperties; +import de.bixilon.minosoft.data.commands.parser.properties.StringParserProperties; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +import javax.annotation.Nullable; + +public class StringParser extends CommandParser { + @Override + @Nullable + public ParserProperties readParserProperties(InByteBuffer buffer) { + return new StringParserProperties(buffer); + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/DoubleParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/DoubleParserProperties.java new file mode 100644 index 000000000..bfed21e55 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/DoubleParserProperties.java @@ -0,0 +1,44 @@ +/* + * 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.properties; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.util.BitByte; + +public class DoubleParserProperties implements ParserProperties { + private final double minValue; + private final double maxValue; + + public DoubleParserProperties(InByteBuffer buffer) { + byte flags = buffer.readByte(); + if (BitByte.isBitMask(flags, 0x01)) { + minValue = buffer.readDouble(); + } else { + minValue = Double.MIN_VALUE; + } + if (BitByte.isBitMask(flags, 0x02)) { + maxValue = buffer.readDouble(); + } else { + maxValue = Double.MAX_VALUE; + } + } + + public double getMinValue() { + return minValue; + } + + public double getMaxValue() { + return maxValue; + } +} 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 new file mode 100644 index 000000000..510703937 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/EntityParserProperties.java @@ -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.properties; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.util.BitByte; + +public class EntityParserProperties implements ParserProperties { + private final boolean onlySingleEntity; + private final boolean onlyPlayers; + + public EntityParserProperties(InByteBuffer buffer) { + byte flags = buffer.readByte(); + onlySingleEntity = BitByte.isBitMask(flags, 0x01); + onlyPlayers = BitByte.isBitMask(flags, 0x02); + } + + public boolean isOnlySingleEntity() { + return onlySingleEntity; + } + + public boolean isOnlyPlayers() { + return onlyPlayers; + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/FloatParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/FloatParserProperties.java new file mode 100644 index 000000000..d656078da --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/FloatParserProperties.java @@ -0,0 +1,44 @@ +/* + * 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.properties; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.util.BitByte; + +public class FloatParserProperties implements ParserProperties { + private final float minValue; + private final float maxValue; + + public FloatParserProperties(InByteBuffer buffer) { + byte flags = buffer.readByte(); + if (BitByte.isBitMask(flags, 0x01)) { + minValue = buffer.readFloat(); + } else { + minValue = Float.MIN_VALUE; + } + if (BitByte.isBitMask(flags, 0x02)) { + maxValue = buffer.readFloat(); + } else { + maxValue = Float.MAX_VALUE; + } + } + + public float getMinValue() { + return minValue; + } + + public float getMaxValue() { + return maxValue; + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/IntegerParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/IntegerParserProperties.java new file mode 100644 index 000000000..05954cc6e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/IntegerParserProperties.java @@ -0,0 +1,45 @@ +/* + * 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.properties; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.util.BitByte; + +public class IntegerParserProperties implements ParserProperties { + private final int minValue; + private final int maxValue; + + public IntegerParserProperties(InByteBuffer buffer) { + byte flags = buffer.readByte(); + if (BitByte.isBitMask(flags, 0x01)) { + minValue = buffer.readInt(); + } else { + minValue = Integer.MIN_VALUE; + } + if (BitByte.isBitMask(flags, 0x02)) { + maxValue = buffer.readInt(); + } else { + maxValue = Integer.MAX_VALUE; + } + } + + public int getMinValue() { + return minValue; + } + + public int getMaxValue() { + return maxValue; + } + +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ParserProperties.java new file mode 100644 index 000000000..be756f607 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ParserProperties.java @@ -0,0 +1,17 @@ +/* + * 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.properties; + +public interface ParserProperties { +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/RangeParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/RangeParserProperties.java new file mode 100644 index 000000000..cbcb347c6 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/RangeParserProperties.java @@ -0,0 +1,29 @@ +/* + * 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.properties; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.util.BitByte; + +public class RangeParserProperties implements ParserProperties { + private final boolean allowDecimals; + + public RangeParserProperties(InByteBuffer buffer) { + allowDecimals = BitByte.isBitMask(buffer.readByte(), 0x01); + } + + public boolean isAllowDecimals() { + return allowDecimals; + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ScoreHolderParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ScoreHolderParserProperties.java new file mode 100644 index 000000000..9c139a7e8 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ScoreHolderParserProperties.java @@ -0,0 +1,29 @@ +/* + * 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.properties; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.util.BitByte; + +public class ScoreHolderParserProperties implements ParserProperties { + private final boolean allowMultiple; + + public ScoreHolderParserProperties(InByteBuffer buffer) { + allowMultiple = BitByte.isBitMask(buffer.readByte(), 0x01); + } + + public boolean isAllowMultiple() { + return allowMultiple; + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/StringParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/StringParserProperties.java new file mode 100644 index 000000000..44c8471ea --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/StringParserProperties.java @@ -0,0 +1,34 @@ +/* + * 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.properties; + +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; + +public class StringParserProperties implements ParserProperties { + private final StringSettings setting; + + public StringParserProperties(InByteBuffer buffer) { + setting = StringSettings.values()[buffer.readVarInt()]; + } + + public StringSettings getSetting() { + return setting; + } + + public enum StringSettings { + SINGLE_WORD, + QUOTABLE_PHRASE, + GREEDY_PHRASE + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/ModIdentifier.java b/src/main/java/de/bixilon/minosoft/data/mappings/ModIdentifier.java index 9c3285853..e7a462d6a 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/ModIdentifier.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/ModIdentifier.java @@ -43,9 +43,13 @@ public class ModIdentifier { return identifier; } + public String getFullIdentifier() { + return String.format("%s:%s", mod, identifier); + } + @Override public String toString() { - return String.format("%s:%s", mod, identifier); + return getFullIdentifier(); } @Override diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipes.java b/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipes.java index 1bdf1c4bb..2f8ee5984 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipes.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipes.java @@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.mappings.recipes; import com.google.common.collect.HashBiMap; import de.bixilon.minosoft.data.inventory.Slot; +import de.bixilon.minosoft.data.mappings.ModIdentifier; import java.util.ArrayList; import java.util.Arrays; @@ -23,13 +24,13 @@ import java.util.HashSet; public class Recipes { final static ArrayList recipeList = new ArrayList<>(); final static HashBiMap recipeIdMap = HashBiMap.create(); // ids for version <= VERSION_1_12_2 - final static HashBiMap recipeNameMap = HashBiMap.create(); + final static HashBiMap recipeNameMap = HashBiMap.create(); public static Recipe getRecipeById(int id) { return recipeIdMap.get(id); } - public static Recipe getRecipe(String identifier) { + public static Recipe getRecipe(ModIdentifier identifier) { return recipeNameMap.get(identifier); } @@ -56,7 +57,7 @@ public class Recipes { recipeNameMap.clear(); } - public static void registerCustomRecipes(HashBiMap recipes) { + public static void registerCustomRecipes(HashBiMap recipes) { recipeNameMap.putAll(recipes); } } diff --git a/src/main/java/de/bixilon/minosoft/data/text/HoverEvent.java b/src/main/java/de/bixilon/minosoft/data/text/HoverEvent.java index 2504a4b9c..ae7697740 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/HoverEvent.java +++ b/src/main/java/de/bixilon/minosoft/data/text/HoverEvent.java @@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.text; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; import de.bixilon.minosoft.data.mappings.ModIdentifier; import de.bixilon.minosoft.util.Util; @@ -27,10 +28,17 @@ public class HoverEvent { public HoverEvent(JsonObject json) { this.action = HoverEventActions.valueOf(json.get("action").getAsString().toUpperCase()); - JsonElement data = json.get("value"); + JsonElement data = null; + if (json.has("value")) { + data = json.get("value"); + } + if (json.has("contents")) { + data = json.get("contents"); + } + json.get("value"); value = switch (action) { // ToDo case SHOW_TEXT -> ChatComponent.valueOf(data); - case SHOW_ENTITY -> EntityHoverData.deserialize(JsonParser.parseString(json.get("value").getAsString()).getAsJsonObject()); + case SHOW_ENTITY -> EntityHoverData.deserialize(data); default -> null; }; } @@ -56,8 +64,14 @@ public class HoverEvent { public static record EntityHoverData(UUID uuid, ModIdentifier identifier, ChatComponent name) { - public static EntityHoverData deserialize(JsonObject json) { - return new EntityHoverData(Util.getUUIDFromString(json.get("id").getAsString()), new ModIdentifier(json.get("type").getAsString()), ChatComponent.valueOf(json.get("name").getAsString())); + public static EntityHoverData deserialize(JsonElement data) { + JsonObject json; + if (data instanceof JsonPrimitive) { + json = JsonParser.parseString(data.getAsString()).getAsJsonObject(); + } else { + json = (JsonObject) data; + } + return new EntityHoverData(Util.getUUIDFromString(json.get("id").getAsString()), new ModIdentifier(json.get("type").getAsString()), ChatComponent.valueOf(json.get("name"))); } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java b/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java index 7af7883eb..698ceeeb6 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java +++ b/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java @@ -227,7 +227,7 @@ public class SocketNetwork implements Network { e.printStackTrace(); } } catch (Exception e) { - Log.printException(e, LogLevels.DEBUG); + Log.printException(e, LogLevels.VERBOSE); Log.protocol(String.format("An error occurred while parsing a packet (%s): %s", packet, e)); } } 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 new file mode 100644 index 000000000..4834377f5 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareCommands.java @@ -0,0 +1,50 @@ +/* + * 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.protocol.packets.clientbound.play; + +import de.bixilon.minosoft.data.commands.CommandNode; +import de.bixilon.minosoft.logging.Log; +import de.bixilon.minosoft.protocol.packets.ClientboundPacket; +import de.bixilon.minosoft.protocol.protocol.InByteBuffer; +import de.bixilon.minosoft.protocol.protocol.PacketHandler; + +public class PacketDeclareCommands implements ClientboundPacket { + private CommandNode[] nodes; + private CommandNode rootElement; + + @Override + public boolean read(InByteBuffer buffer) throws Exception { + nodes = buffer.readCommandNodesArray(); + rootElement = nodes[buffer.readVarInt()]; + return true; + } + + public CommandNode[] getNodes() { + return nodes; + } + + public CommandNode getRootElement() { + return rootElement; + } + + @Override + public void handle(PacketHandler h) { + h.handle(this); + } + + @Override + public void log() { + Log.protocol("Received declare commands packets (nodes=%d)", nodes.length); + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareRecipes.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareRecipes.java index ae5e6d850..05e7b64f8 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareRecipes.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareRecipes.java @@ -15,6 +15,7 @@ package de.bixilon.minosoft.protocol.packets.clientbound.play; import com.google.common.collect.HashBiMap; import de.bixilon.minosoft.data.inventory.Slot; +import de.bixilon.minosoft.data.mappings.ModIdentifier; import de.bixilon.minosoft.data.mappings.recipes.Ingredient; import de.bixilon.minosoft.data.mappings.recipes.Recipe; import de.bixilon.minosoft.data.mappings.recipes.RecipeTypes; @@ -24,20 +25,20 @@ import de.bixilon.minosoft.protocol.protocol.InByteBuffer; import de.bixilon.minosoft.protocol.protocol.PacketHandler; public class PacketDeclareRecipes implements ClientboundPacket { - final HashBiMap recipes = HashBiMap.create(); + private final HashBiMap recipes = HashBiMap.create(); @Override public boolean read(InByteBuffer buffer) { int length = buffer.readVarInt(); for (int i = 0; i < length; i++) { Recipe recipe; - String identifier; + ModIdentifier identifier; String typeName; if (buffer.getVersionId() >= 453) { // ToDo: find out version typeName = buffer.readString(); - identifier = buffer.readString(); + identifier = buffer.readIdentifier(); } else { - identifier = buffer.readString(); + identifier = buffer.readIdentifier(); typeName = buffer.readString(); } RecipeTypes type = RecipeTypes.byName(typeName); @@ -93,7 +94,7 @@ public class PacketDeclareRecipes implements ClientboundPacket { Log.protocol(String.format("[IN] Received declare recipe packet (recipeLength=%d)", recipes.size())); } - public HashBiMap getRecipes() { + public HashBiMap getRecipes() { return recipes; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java index db5a97f62..f66852787 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java @@ -14,6 +14,7 @@ package de.bixilon.minosoft.protocol.packets.clientbound.play; import de.bixilon.minosoft.data.SoundCategories; +import de.bixilon.minosoft.data.mappings.ModIdentifier; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; import de.bixilon.minosoft.protocol.protocol.InByteBuffer; @@ -22,13 +23,13 @@ import de.bixilon.minosoft.util.BitByte; public class PacketStopSound implements ClientboundPacket { SoundCategories category; - String soundIdentifier; + ModIdentifier soundIdentifier; @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 343) { // ToDo: these 2 values need to be switched in before 1.12.2 category = SoundCategories.valueOf(buffer.readString().toUpperCase()); - soundIdentifier = buffer.readString(); + soundIdentifier = buffer.readIdentifier(); return true; } byte flags = buffer.readByte(); @@ -36,7 +37,7 @@ public class PacketStopSound implements ClientboundPacket { category = SoundCategories.byId(buffer.readVarInt()); } if (BitByte.isBitMask(flags, 0x02)) { - soundIdentifier = buffer.readString(); + soundIdentifier = buffer.readIdentifier(); } return true; } @@ -55,7 +56,7 @@ public class PacketStopSound implements ClientboundPacket { return category; } - public String getSoundIdentifier() { + public ModIdentifier getSoundIdentifier() { return soundIdentifier; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnlockRecipes.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnlockRecipes.java index ff0551534..028de4cec 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnlockRecipes.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnlockRecipes.java @@ -57,7 +57,7 @@ public class PacketUnlockRecipes implements ClientboundPacket { if (buffer.getVersionId() < 348) { listed[i] = Recipes.getRecipeById(buffer.readVarInt()); } else { - listed[i] = Recipes.getRecipe(buffer.readString()); + listed[i] = Recipes.getRecipe(buffer.readIdentifier()); } } if (action == UnlockRecipeActions.INITIALIZE) { @@ -66,7 +66,7 @@ public class PacketUnlockRecipes implements ClientboundPacket { if (buffer.getVersionId() < 348) { tagged[i] = Recipes.getRecipeById(buffer.readVarInt()); } else { - tagged[i] = Recipes.getRecipe(buffer.readString()); + tagged[i] = Recipes.getRecipe(buffer.readIdentifier()); } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java index 7c587dc93..1d140167e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java @@ -16,10 +16,15 @@ package de.bixilon.minosoft.protocol.protocol; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import de.bixilon.minosoft.data.Directions; +import de.bixilon.minosoft.data.commands.CommandArgumentNode; +import de.bixilon.minosoft.data.commands.CommandLiteralNode; +import de.bixilon.minosoft.data.commands.CommandNode; +import de.bixilon.minosoft.data.commands.CommandRootNode; import de.bixilon.minosoft.data.entities.EntityMetaData; import de.bixilon.minosoft.data.entities.Location; import de.bixilon.minosoft.data.entities.Poses; import de.bixilon.minosoft.data.inventory.Slot; +import de.bixilon.minosoft.data.mappings.ModIdentifier; import de.bixilon.minosoft.data.mappings.particle.Particle; import de.bixilon.minosoft.data.mappings.particle.data.BlockParticleData; import de.bixilon.minosoft.data.mappings.particle.data.DustParticleData; @@ -156,8 +161,7 @@ public class InByteBuffer { int byteCount = 0; int result = 0; byte read; - do - { + do { read = readByte(); result |= (read & 0x7F) << (7 * byteCount); byteCount++; @@ -436,6 +440,10 @@ public class InByteBuffer { return ret; } + public int[] readVarIntArray() { + return readVarIntArray(readVarInt()); + } + public Ingredient readIngredient() { return new Ingredient(readSlotArray(readVarInt())); } @@ -466,4 +474,37 @@ public class InByteBuffer { } return readVarInt(); } + + public CommandNode[] readCommandNodesArray() { + CommandNode[] nodes = new CommandNode[readVarInt()]; + for (int i = 0; i < nodes.length; i++) { + nodes[i] = readCommandNode(); + } + // resole ids + for (CommandNode node : nodes) { + // redirect + if (node.getRedirectNodeId() != -1) { + node.setRedirectNode(nodes[node.getRedirectNodeId()]); + } + // children + for (int id : node.getChildrenIds()) { + node.getChildren().add(nodes[id]); + } + + } + return nodes; + } + + private CommandNode readCommandNode() { + byte flags = readByte(); + return switch (CommandNode.NodeTypes.values()[flags & 0x03]) { + case ROOT -> new CommandRootNode(flags, this); + case LITERAL -> new CommandLiteralNode(flags, this); + case ARGUMENT -> new CommandArgumentNode(flags, this); + }; + } + + public ModIdentifier readIdentifier() { + return new ModIdentifier(readString()); + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java index 778ff4f2e..10c7b24cb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -800,4 +800,7 @@ public class PacketHandler { public void handle(PacketVehicleMovement pkg) { } + + public void handle(PacketDeclareCommands pkg) { + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java index 84e8c88d3..c65012261 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java @@ -117,7 +117,7 @@ public class Packets { PLAY_CHAT_MESSAGE(PacketChatMessageReceiving.class), PLAY_MULTIBLOCK_CHANGE(PacketMultiBlockChange.class), PLAY_TAB_COMPLETE(PacketTabCompleteReceiving.class), - PLAY_DECLARE_COMMANDS(null), + PLAY_DECLARE_COMMANDS(PacketDeclareCommands.class), PLAY_WINDOW_CONFIRMATION(PacketConfirmTransactionReceiving.class), PLAY_CLOSE_WINDOW(PacketCloseWindowReceiving.class), PLAY_WINDOW_ITEMS(PacketWindowItems.class),