From 1c6039b55e66b6da65a6ffa07f889c9fe3301c79 Mon Sep 17 00:00:00 2001 From: Shevchik Date: Sat, 28 May 2022 13:20:44 +0300 Subject: [PATCH] Implement commands codec and mapper --- .../play/MiddleDeclareCommands.java | 111 +++++++++++++-- .../DeclareCommands.java | 127 +++++++++++++++++- .../legacy/LegacyCommandDataRegistry.java | 55 ++++++++ .../protocol/types/command/CommandNode.java | 57 ++++++++ .../command/CommandNodeDoubleProperties.java | 27 ++++ .../command/CommandNodeEntityProperties.java | 15 +++ .../command/CommandNodeFloatProperties.java | 27 ++++ .../command/CommandNodeIntegerProperties.java | 27 ++++ .../command/CommandNodeLongProperties.java | 27 ++++ .../types/command/CommandNodeProperties.java | 4 + .../command/CommandNodeRangeProperties.java | 15 +++ .../CommandNodeResourceOrTagProperties.java | 15 +++ .../CommandNodeResourceProperties.java | 15 +++ .../CommandNodeScoreHolderProperties.java | 15 +++ .../command/CommandNodeSimpleProperties.java | 16 +++ .../command/CommandNodeStringProperties.java | 24 ++++ .../utils/ProtocolVersionsHelper.java | 2 + 17 files changed, 570 insertions(+), 9 deletions(-) create mode 100644 src/protocolsupport/protocol/typeremapper/legacy/LegacyCommandDataRegistry.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNode.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeDoubleProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeEntityProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeFloatProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeIntegerProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeLongProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeRangeProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeResourceOrTagProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeResourceProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeScoreHolderProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeSimpleProperties.java create mode 100644 src/protocolsupport/protocol/types/command/CommandNodeStringProperties.java diff --git a/src/protocolsupport/protocol/packet/middle/base/clientbound/play/MiddleDeclareCommands.java b/src/protocolsupport/protocol/packet/middle/base/clientbound/play/MiddleDeclareCommands.java index 27050efcc..e7576b63e 100644 --- a/src/protocolsupport/protocol/packet/middle/base/clientbound/play/MiddleDeclareCommands.java +++ b/src/protocolsupport/protocol/packet/middle/base/clientbound/play/MiddleDeclareCommands.java @@ -1,10 +1,28 @@ package protocolsupport.protocol.packet.middle.base.clientbound.play; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + import io.netty.buffer.ByteBuf; +import protocolsupport.protocol.codec.ArrayCodec; import protocolsupport.protocol.codec.MiscDataCodec; -import protocolsupport.protocol.packet.middle.MiddlePacketCancelException; +import protocolsupport.protocol.codec.StringCodec; +import protocolsupport.protocol.codec.VarNumberCodec; import protocolsupport.protocol.packet.middle.base.clientbound.ClientBoundMiddlePacket; -import protocolsupport.protocol.utils.ProtocolVersionsHelper; +import protocolsupport.protocol.types.command.CommandNode; +import protocolsupport.protocol.types.command.CommandNodeDoubleProperties; +import protocolsupport.protocol.types.command.CommandNodeEntityProperties; +import protocolsupport.protocol.types.command.CommandNodeIntegerProperties; +import protocolsupport.protocol.types.command.CommandNodeLongProperties; +import protocolsupport.protocol.types.command.CommandNodeProperties; +import protocolsupport.protocol.types.command.CommandNodeRangeProperties; +import protocolsupport.protocol.types.command.CommandNodeResourceOrTagProperties; +import protocolsupport.protocol.types.command.CommandNodeResourceProperties; +import protocolsupport.protocol.types.command.CommandNodeScoreHolderProperties; +import protocolsupport.protocol.types.command.CommandNodeSimpleProperties; +import protocolsupport.protocol.types.command.CommandNodeStringProperties; +import protocolsupport.utils.BitUtils; public abstract class MiddleDeclareCommands extends ClientBoundMiddlePacket { @@ -12,17 +30,94 @@ protected MiddleDeclareCommands(IMiddlePacketInit init) { super(init); } - //TODO: structure - protected ByteBuf data; + protected CommandNode[] nodes; + protected int rootNodeIndex; @Override protected void decode(ByteBuf serverdata) { - data = MiscDataCodec.readAllBytesSlice(serverdata); + nodes = ArrayCodec.readVarIntTArray(serverdata, CommandNode.class, MiddleDeclareCommands::readNode); + rootNodeIndex = VarNumberCodec.readVarInt(serverdata); + } + + protected static final int NODE_FLAGS_TYPE_MASK = BitUtils.createIBitMaskFromBits(new int[] {0, 1}); + protected static final int NODE_FLAGS_HAS_REDIRECT_BIT = 3; + protected static final int NODE_FLAGS_HAS_SUGGESTIONS_TYPE = 4; + + protected static final int NODE_TYPE_ROOT = 0; + protected static final int NODE_TYPE_LITERAL = 1; + protected static final int NODE_TYPE_ARGUMENT = 2; - //TODO: remove after implementing - if (version.isBefore(ProtocolVersionsHelper.LATEST_PC)) { - throw MiddlePacketCancelException.INSTANCE; + protected static final Map> propertiesDeserializer = new HashMap<>(); + static { + propertiesDeserializer.put("brigadier:double", data -> { + int flags = data.readByte(); + double min = BitUtils.isIBitSet(flags, 0) ? data.readDouble() : Double.MIN_VALUE; + double max = BitUtils.isIBitSet(flags, 1) ? data.readDouble() : Double.MAX_VALUE; + return new CommandNodeDoubleProperties(flags, min, max); + }); + propertiesDeserializer.put("brigadier:float", data -> { + int flags = data.readByte(); + float min = BitUtils.isIBitSet(flags, 0) ? data.readFloat() : Float.MIN_VALUE; + float max = BitUtils.isIBitSet(flags, 1) ? data.readFloat() : Float.MAX_VALUE; + return new CommandNodeDoubleProperties(flags, min, max); + }); + propertiesDeserializer.put("brigadier:long", data -> { + int flags = data.readByte(); + long min = BitUtils.isIBitSet(flags, 0) ? data.readLong() : Long.MIN_VALUE; + long max = BitUtils.isIBitSet(flags, 1) ? data.readLong() : Long.MAX_VALUE; + return new CommandNodeLongProperties(flags, min, max); + }); + propertiesDeserializer.put("brigadier:integer", data -> { + int flags = data.readByte(); + int min = BitUtils.isIBitSet(flags, 0) ? data.readInt() : Integer.MIN_VALUE; + int max = BitUtils.isIBitSet(flags, 1) ? data.readInt() : Integer.MAX_VALUE; + return new CommandNodeIntegerProperties(flags, min, max); + }); + propertiesDeserializer.put("brigadier:string", data -> { + CommandNodeStringProperties.Type type = MiscDataCodec.readVarIntEnum(data, CommandNodeStringProperties.Type.CONSTANT_LOOKUP); + return new CommandNodeStringProperties(type); + }); + propertiesDeserializer.put("minecraft:entity", data -> { + int flags = data.readByte(); + return new CommandNodeEntityProperties(flags); + }); + propertiesDeserializer.put("minecraft:score_holder", data -> { + int flags = data.readByte(); + return new CommandNodeScoreHolderProperties(flags); + }); + propertiesDeserializer.put("minecraft:range", data -> { + boolean allowDecimals = data.readBoolean(); + return new CommandNodeRangeProperties(allowDecimals); + }); + propertiesDeserializer.put("minecraft:resource_or_tag", data -> { + String identifier = StringCodec.readVarIntUTF8String(data); + return new CommandNodeResourceOrTagProperties(identifier); + }); + propertiesDeserializer.put("minecraft:resource", data -> { + String identifier = StringCodec.readVarIntUTF8String(data); + return new CommandNodeResourceProperties(identifier); + }); + } + + protected static CommandNode readNode(ByteBuf data) { + byte flags = data.readByte(); + int nodeType = flags & NODE_FLAGS_TYPE_MASK; + int[] childNodesIndexes = ArrayCodec.readVarIntVarIntArray(data); + int redirectNodeIndex = BitUtils.isIBitSet(flags, NODE_FLAGS_HAS_REDIRECT_BIT) ? VarNumberCodec.readVarInt(data) : -1; + String name = (nodeType == NODE_TYPE_LITERAL) || (nodeType == NODE_TYPE_ARGUMENT) ? StringCodec.readVarIntUTF8String(data) : null; + String parser = nodeType == NODE_TYPE_ARGUMENT ? StringCodec.readVarIntUTF8String(data) : null; + CommandNodeProperties properties = null; + if (parser != null) { + Function propertiesFunc = propertiesDeserializer.get(parser); + if (propertiesFunc != null) { + properties = propertiesFunc.apply(data); + } else { + properties = new CommandNodeSimpleProperties(parser); + } } + String suggestionsType = BitUtils.isIBitSet(flags, NODE_FLAGS_HAS_SUGGESTIONS_TYPE) ? StringCodec.readVarIntUTF8String(data) : null; + return new CommandNode(flags, childNodesIndexes, redirectNodeIndex, name, parser, properties, suggestionsType); } + } diff --git a/src/protocolsupport/protocol/packet/middle/impl/clientbound/play/v_13_14r1_14r2_15_16r1_16r2_17r1_17r2_18/DeclareCommands.java b/src/protocolsupport/protocol/packet/middle/impl/clientbound/play/v_13_14r1_14r2_15_16r1_16r2_17r1_17r2_18/DeclareCommands.java index 79068c3f9..3137010cc 100644 --- a/src/protocolsupport/protocol/packet/middle/impl/clientbound/play/v_13_14r1_14r2_15_16r1_16r2_17r1_17r2_18/DeclareCommands.java +++ b/src/protocolsupport/protocol/packet/middle/impl/clientbound/play/v_13_14r1_14r2_15_16r1_16r2_17r1_17r2_18/DeclareCommands.java @@ -1,5 +1,14 @@ package protocolsupport.protocol.packet.middle.impl.clientbound.play.v_13_14r1_14r2_15_16r1_16r2_17r1_17r2_18; +import java.util.HashMap; +import java.util.Map; +import java.util.function.BiConsumer; + +import io.netty.buffer.ByteBuf; +import protocolsupport.protocol.codec.ArrayCodec; +import protocolsupport.protocol.codec.MiscDataCodec; +import protocolsupport.protocol.codec.StringCodec; +import protocolsupport.protocol.codec.VarNumberCodec; import protocolsupport.protocol.packet.ClientBoundPacketData; import protocolsupport.protocol.packet.ClientBoundPacketType; import protocolsupport.protocol.packet.middle.base.clientbound.play.MiddleDeclareCommands; @@ -12,6 +21,21 @@ import protocolsupport.protocol.packet.middle.impl.clientbound.IClientboundMiddlePacketV17r1; import protocolsupport.protocol.packet.middle.impl.clientbound.IClientboundMiddlePacketV17r2; import protocolsupport.protocol.packet.middle.impl.clientbound.IClientboundMiddlePacketV18; +import protocolsupport.protocol.typeremapper.legacy.LegacyCommandDataRegistry; +import protocolsupport.protocol.typeremapper.legacy.LegacyCommandDataRegistry.LegacyCommandDataMappingTable; +import protocolsupport.protocol.types.command.CommandNodeDoubleProperties; +import protocolsupport.protocol.types.command.CommandNodeEntityProperties; +import protocolsupport.protocol.types.command.CommandNodeFloatProperties; +import protocolsupport.protocol.types.command.CommandNodeIntegerProperties; +import protocolsupport.protocol.types.command.CommandNodeLongProperties; +import protocolsupport.protocol.types.command.CommandNodeProperties; +import protocolsupport.protocol.types.command.CommandNodeRangeProperties; +import protocolsupport.protocol.types.command.CommandNodeResourceOrTagProperties; +import protocolsupport.protocol.types.command.CommandNodeResourceProperties; +import protocolsupport.protocol.types.command.CommandNodeScoreHolderProperties; +import protocolsupport.protocol.types.command.CommandNodeSimpleProperties; +import protocolsupport.protocol.types.command.CommandNodeStringProperties; +import protocolsupport.utils.BitUtils; public class DeclareCommands extends MiddleDeclareCommands implements IClientboundMiddlePacketV13, @@ -28,11 +52,112 @@ public DeclareCommands(IMiddlePacketInit init) { super(init); } + protected final LegacyCommandDataMappingTable commanddataTabe = LegacyCommandDataRegistry.INSTANCE.getTable(version); + @Override protected void write() { ClientBoundPacketData declarecommands = ClientBoundPacketData.create(ClientBoundPacketType.PLAY_DECLARE_COMMANDS); - declarecommands.writeBytes(data); + ArrayCodec.writeVarIntTArray(declarecommands, nodes, (nodeData, node) -> { + int flags = node.getFlags(); + int nodeType = flags & NODE_FLAGS_TYPE_MASK; + nodeData.writeByte(flags); + ArrayCodec.writeVarIntVarIntArray(nodeData, node.getChildNodesIndexes()); + if (BitUtils.isIBitSet(flags, NODE_FLAGS_HAS_REDIRECT_BIT)) { + VarNumberCodec.writeVarInt(nodeData, node.getRedirectNodeIndex()); + } + if (nodeType == NODE_TYPE_LITERAL || nodeType == NODE_TYPE_ARGUMENT) { + StringCodec.writeVarIntUTF8String(nodeData, node.getName()); + } + if (nodeType == NODE_TYPE_ARGUMENT) { + CommandNodeProperties properties = node.getProperties(); + properties = commanddataTabe.get(properties.getClass()).apply(properties); + propertiesSerializer.get(properties.getClass()).accept(nodeData, properties); + } + if (BitUtils.isIBitSet(flags, NODE_FLAGS_HAS_SUGGESTIONS_TYPE)) { + StringCodec.writeVarIntUTF8String(nodeData, node.getSuggestType()); + } + }); + VarNumberCodec.writeVarInt(declarecommands, rootNodeIndex); io.writeClientbound(declarecommands); } + protected static final Map, BiConsumer> propertiesSerializer = new HashMap<>(); + @SuppressWarnings("unchecked") + protected static void registerPropertiesSerializer(Class clazz, BiConsumer serializer) { + propertiesSerializer.put((Class) clazz, (BiConsumer) serializer); + } + static { + registerPropertiesSerializer(CommandNodeSimpleProperties.class, (data, properties) -> { + StringCodec.writeVarIntUTF8String(data, properties.getParser()); + }); + registerPropertiesSerializer(CommandNodeDoubleProperties.class, (data, properties) -> { + int flags = properties.getFlags(); + StringCodec.writeVarIntUTF8String(data, "brigadier:double"); + data.writeByte(flags); + if (BitUtils.isIBitSet(flags, 0)) { + data.writeDouble(properties.getMin()); + } + if (BitUtils.isIBitSet(flags, 1)) { + data.writeDouble(properties.getMax()); + } + }); + registerPropertiesSerializer(CommandNodeFloatProperties.class, (data, properties) -> { + int flags = properties.getFlags(); + StringCodec.writeVarIntUTF8String(data, "brigadier:float"); + data.writeByte(flags); + if (BitUtils.isIBitSet(flags, 0)) { + data.writeFloat(properties.getMin()); + } + if (BitUtils.isIBitSet(flags, 1)) { + data.writeFloat(properties.getMax()); + } + }); + registerPropertiesSerializer(CommandNodeLongProperties.class, (data, properties) -> { + int flags = properties.getFlags(); + StringCodec.writeVarIntUTF8String(data, "brigadier:long"); + data.writeByte(flags); + if (BitUtils.isIBitSet(flags, 0)) { + data.writeLong(properties.getMin()); + } + if (BitUtils.isIBitSet(flags, 1)) { + data.writeLong(properties.getMax()); + } + }); + registerPropertiesSerializer(CommandNodeIntegerProperties.class, (data, properties) -> { + int flags = properties.getFlags(); + StringCodec.writeVarIntUTF8String(data, "brigadier:integer"); + data.writeByte(flags); + if (BitUtils.isIBitSet(flags, 0)) { + data.writeInt(properties.getMin()); + } + if (BitUtils.isIBitSet(flags, 1)) { + data.writeInt(properties.getMax()); + } + }); + registerPropertiesSerializer(CommandNodeStringProperties.class, (data, properties) -> { + StringCodec.writeVarIntUTF8String(data, "brigadier:string"); + MiscDataCodec.writeVarIntEnum(data, properties.getType()); + }); + registerPropertiesSerializer(CommandNodeEntityProperties.class, (data, properties) -> { + StringCodec.writeVarIntUTF8String(data, "minecraft:entity"); + data.writeByte(properties.getFlags()); + }); + registerPropertiesSerializer(CommandNodeScoreHolderProperties.class, (data, properties) -> { + StringCodec.writeVarIntUTF8String(data, "minecraft:score_holder"); + data.writeByte(properties.getFlags()); + }); + registerPropertiesSerializer(CommandNodeRangeProperties.class, (data, properties) -> { + StringCodec.writeVarIntUTF8String(data, "minecraft:range"); + data.writeBoolean(properties.allowDecimals()); + }); + registerPropertiesSerializer(CommandNodeResourceOrTagProperties.class, (data, properties) -> { + StringCodec.writeVarIntUTF8String(data, "minecraft:resource_or_tag"); + StringCodec.writeVarIntUTF8String(data, properties.getIdentifier()); + }); + registerPropertiesSerializer(CommandNodeResourceProperties.class, (data, properties) -> { + StringCodec.writeVarIntUTF8String(data, "minecraft:resource"); + StringCodec.writeVarIntUTF8String(data, properties.getIdentifier()); + }); + } + } diff --git a/src/protocolsupport/protocol/typeremapper/legacy/LegacyCommandDataRegistry.java b/src/protocolsupport/protocol/typeremapper/legacy/LegacyCommandDataRegistry.java new file mode 100644 index 000000000..86029e232 --- /dev/null +++ b/src/protocolsupport/protocol/typeremapper/legacy/LegacyCommandDataRegistry.java @@ -0,0 +1,55 @@ +package protocolsupport.protocol.typeremapper.legacy; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.function.UnaryOperator; + +import protocolsupport.api.ProtocolVersion; +import protocolsupport.protocol.typeremapper.legacy.LegacyCommandDataRegistry.LegacyCommandDataMappingTable; +import protocolsupport.protocol.typeremapper.utils.MappingRegistry; +import protocolsupport.protocol.typeremapper.utils.MappingTable; +import protocolsupport.protocol.types.command.CommandNodeProperties; +import protocolsupport.protocol.types.command.CommandNodeResourceOrTagProperties; +import protocolsupport.protocol.types.command.CommandNodeResourceProperties; +import protocolsupport.protocol.types.command.CommandNodeStringProperties; +import protocolsupport.protocol.utils.ProtocolVersionsHelper; +import protocolsupportbuildprocessor.Preload; + +@Preload +public class LegacyCommandDataRegistry extends MappingRegistry { + + public static final LegacyCommandDataRegistry INSTANCE = new LegacyCommandDataRegistry(); + + public LegacyCommandDataRegistry() { + register(CommandNodeResourceOrTagProperties.class, properties -> new CommandNodeStringProperties(CommandNodeStringProperties.Type.SINGLE_WORD), ProtocolVersionsHelper.DOWN_1_18); + register(CommandNodeResourceProperties.class, properties -> new CommandNodeStringProperties(CommandNodeStringProperties.Type.SINGLE_WORD), ProtocolVersionsHelper.DOWN_1_18); + } + + protected void register(Class clazz, Function func, ProtocolVersion... versions) { + for (ProtocolVersion version : versions) { + getTable(version).set(clazz, func); + } + } + + @Override + protected LegacyCommandDataMappingTable createTable() { + return new LegacyCommandDataMappingTable(); + } + + public static class LegacyCommandDataMappingTable extends MappingTable { + + protected final Map, Function> table = new HashMap<>(); + + public void set(Class clazz, Function func) { + table.put(clazz, func); + } + + @SuppressWarnings("unchecked") + public Function get(Class clazz) { + return (Function) table.getOrDefault(clazz, UnaryOperator.identity()); + } + + } + +} diff --git a/src/protocolsupport/protocol/types/command/CommandNode.java b/src/protocolsupport/protocol/types/command/CommandNode.java new file mode 100644 index 000000000..2545c61e9 --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNode.java @@ -0,0 +1,57 @@ +package protocolsupport.protocol.types.command; + +public class CommandNode { + + protected final int flags; + protected final int[] childNodesIndexes; + protected final int redirectNodeIndex; + protected final String name; + protected final String parser; + protected final CommandNodeProperties properties; + protected final String suggestType; + + public CommandNode(int flags, int[] childNodesIndexes, int redirectNodeIndex, String name, String parser, CommandNodeProperties properties, String suggestType) { + this.flags = flags; + this.childNodesIndexes = childNodesIndexes; + this.redirectNodeIndex = redirectNodeIndex; + this.name = name; + this.parser = parser; + this.properties = properties; + this.suggestType = suggestType; + } + + public int getFlags() { + return flags; + } + + + public int[] getChildNodesIndexes() { + return childNodesIndexes; + } + + + public int getRedirectNodeIndex() { + return redirectNodeIndex; + } + + + public String getName() { + return name; + } + + + public String getParser() { + return parser; + } + + + public CommandNodeProperties getProperties() { + return properties; + } + + + public String getSuggestType() { + return suggestType; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeDoubleProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeDoubleProperties.java new file mode 100644 index 000000000..fde30d51a --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeDoubleProperties.java @@ -0,0 +1,27 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeDoubleProperties extends CommandNodeProperties { + + protected final int flags; + protected final double min; + protected final double max; + + public CommandNodeDoubleProperties(int flags, double min, double max) { + this.flags = flags; + this.min = min; + this.max = max; + } + + public int getFlags() { + return flags; + } + + public double getMin() { + return min; + } + + public double getMax() { + return max; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeEntityProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeEntityProperties.java new file mode 100644 index 000000000..f78566ff1 --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeEntityProperties.java @@ -0,0 +1,15 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeEntityProperties extends CommandNodeProperties { + + protected final int flags; + + public CommandNodeEntityProperties(int flags) { + this.flags = flags; + } + + public int getFlags() { + return flags; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeFloatProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeFloatProperties.java new file mode 100644 index 000000000..3275d967a --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeFloatProperties.java @@ -0,0 +1,27 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeFloatProperties extends CommandNodeProperties { + + protected final int flags; + protected final float min; + protected final float max; + + public CommandNodeFloatProperties(int flags, float min, float max) { + this.flags = flags; + this.min = min; + this.max = max; + } + + public int getFlags() { + return flags; + } + + public float getMin() { + return min; + } + + public float getMax() { + return max; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeIntegerProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeIntegerProperties.java new file mode 100644 index 000000000..d8a8fb4bb --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeIntegerProperties.java @@ -0,0 +1,27 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeIntegerProperties extends CommandNodeProperties { + + protected final int flags; + protected final int min; + protected final int max; + + public CommandNodeIntegerProperties(int flags, int min, int max) { + this.flags = flags; + this.min = min; + this.max = max; + } + + public int getFlags() { + return flags; + } + + public int getMin() { + return min; + } + + public int getMax() { + return max; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeLongProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeLongProperties.java new file mode 100644 index 000000000..faefb2093 --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeLongProperties.java @@ -0,0 +1,27 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeLongProperties extends CommandNodeProperties { + + protected final int flags; + protected final long min; + protected final long max; + + public CommandNodeLongProperties(int flags, long min, long max) { + this.flags = flags; + this.min = min; + this.max = max; + } + + public int getFlags() { + return flags; + } + + public long getMin() { + return min; + } + + public long getMax() { + return max; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeProperties.java new file mode 100644 index 000000000..d87f1f695 --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeProperties.java @@ -0,0 +1,4 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeProperties { +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeRangeProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeRangeProperties.java new file mode 100644 index 000000000..3100d50c7 --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeRangeProperties.java @@ -0,0 +1,15 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeRangeProperties extends CommandNodeProperties { + + protected final boolean allowDecimals; + + public CommandNodeRangeProperties(boolean allowDecimals) { + this.allowDecimals = allowDecimals; + } + + public boolean allowDecimals() { + return allowDecimals; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeResourceOrTagProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeResourceOrTagProperties.java new file mode 100644 index 000000000..c990c03f5 --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeResourceOrTagProperties.java @@ -0,0 +1,15 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeResourceOrTagProperties extends CommandNodeProperties { + + protected final String identifier; + + public CommandNodeResourceOrTagProperties(String identifier) { + this.identifier = identifier; + } + + public String getIdentifier() { + return identifier; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeResourceProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeResourceProperties.java new file mode 100644 index 000000000..51b76616f --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeResourceProperties.java @@ -0,0 +1,15 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeResourceProperties extends CommandNodeProperties { + + protected final String identifier; + + public CommandNodeResourceProperties(String identifier) { + this.identifier = identifier; + } + + public String getIdentifier() { + return identifier; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeScoreHolderProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeScoreHolderProperties.java new file mode 100644 index 000000000..639486b6e --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeScoreHolderProperties.java @@ -0,0 +1,15 @@ +package protocolsupport.protocol.types.command; + +public class CommandNodeScoreHolderProperties extends CommandNodeProperties { + + protected final int flags; + + public CommandNodeScoreHolderProperties(int flags) { + this.flags = flags; + } + + public int getFlags() { + return flags; + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/types/command/CommandNodeSimpleProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeSimpleProperties.java new file mode 100644 index 000000000..9bf8c6f1b --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeSimpleProperties.java @@ -0,0 +1,16 @@ +package protocolsupport.protocol.types.command; + +//TODO: implement properties for each parser +public class CommandNodeSimpleProperties extends CommandNodeProperties { + + protected final String parser; + + public CommandNodeSimpleProperties(String type) { + this.parser = type; + } + + public String getParser() { + return parser; + } + +} diff --git a/src/protocolsupport/protocol/types/command/CommandNodeStringProperties.java b/src/protocolsupport/protocol/types/command/CommandNodeStringProperties.java new file mode 100644 index 000000000..367736a21 --- /dev/null +++ b/src/protocolsupport/protocol/types/command/CommandNodeStringProperties.java @@ -0,0 +1,24 @@ +package protocolsupport.protocol.types.command; + +import protocolsupport.protocol.utils.EnumConstantLookup; + +public class CommandNodeStringProperties extends CommandNodeProperties { + + protected final CommandNodeStringProperties.Type type; + + public CommandNodeStringProperties(CommandNodeStringProperties.Type type) { + this.type = type; + } + + public CommandNodeStringProperties.Type getType() { + return type; + } + + public enum Type { + + SINGLE_WORD, QUOTABLE_PHRASE, GREEDY_PHRASE; + public static final EnumConstantLookup CONSTANT_LOOKUP = new EnumConstantLookup<>(CommandNodeStringProperties.Type.class); + + } + +} \ No newline at end of file diff --git a/src/protocolsupport/protocol/utils/ProtocolVersionsHelper.java b/src/protocolsupport/protocol/utils/ProtocolVersionsHelper.java index df58bffb7..7b223bbaa 100644 --- a/src/protocolsupport/protocol/utils/ProtocolVersionsHelper.java +++ b/src/protocolsupport/protocol/utils/ProtocolVersionsHelper.java @@ -81,6 +81,8 @@ private ProtocolVersionsHelper() { public static final ProtocolVersion[] DOWN_1_17_1 = ProtocolVersion.getAllBeforeI(ProtocolVersion.MINECRAFT_1_17_1); + public static final ProtocolVersion[] DOWN_1_18 = ProtocolVersion.getAllBeforeI(ProtocolVersion.MINECRAFT_1_18); + public static final ProtocolVersion[] ALL_PC = ProtocolVersion.getAllBetween(ProtocolVersion.getOldest(ProtocolType.PC), LATEST_PC); public static final ProtocolVersion[] ALL_1_16 = ProtocolVersion.getAllBetween(ProtocolVersion.MINECRAFT_1_16, ProtocolVersion.MINECRAFT_1_16_4);