From bdfaf9a621851b0044ec9bfe8bdb309a26fa7407 Mon Sep 17 00:00:00 2001 From: RK_01 <50594595+RaphiMC@users.noreply.github.com> Date: Fri, 5 Feb 2021 12:18:28 +0100 Subject: [PATCH] Remap declare command parser types in 1.14 -> 1.13.2 (#2316) --- .../api/rewriters/CommandRewriter.java | 52 +++++++++++++++++++ .../Protocol1_13To1_12_2.java | 9 ++-- .../Protocol1_14To1_13_2.java | 4 ++ .../data/CommandRewriter1_14.java | 22 ++++++++ 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/CommandRewriter1_14.java diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/CommandRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/CommandRewriter.java index 998bf6e09..fbf8a7a75 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/CommandRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/CommandRewriter.java @@ -19,6 +19,58 @@ public abstract class CommandRewriter { protected CommandRewriter(Protocol protocol) { this.protocol = protocol; + + // Register default parsers + this.parserHandlers.put("brigadier:double", new CommandArgumentConsumer() { + @Override + public void accept(PacketWrapper wrapper) throws Exception { + byte propertyFlags = wrapper.passthrough(Type.BYTE); // Flags + if ((propertyFlags & 0x01) != 0) wrapper.passthrough(Type.DOUBLE); // Min Value + if ((propertyFlags & 0x02) != 0) wrapper.passthrough(Type.DOUBLE); // Max Value + } + }); + this.parserHandlers.put("brigadier:float", new CommandArgumentConsumer() { + @Override + public void accept(PacketWrapper wrapper) throws Exception { + byte propertyFlags = wrapper.passthrough(Type.BYTE); // Flags + if ((propertyFlags & 0x01) != 0) wrapper.passthrough(Type.FLOAT); // Min Value + if ((propertyFlags & 0x02) != 0) wrapper.passthrough(Type.FLOAT); // Max Value + } + }); + this.parserHandlers.put("brigadier:integer", new CommandArgumentConsumer() { + @Override + public void accept(PacketWrapper wrapper) throws Exception { + byte propertyFlags = wrapper.passthrough(Type.BYTE); // Flags + if ((propertyFlags & 0x01) != 0) wrapper.passthrough(Type.INT); // Min Value + if ((propertyFlags & 0x02) != 0) wrapper.passthrough(Type.INT); // Max Value + } + }); + this.parserHandlers.put("brigadier:long", new CommandArgumentConsumer() { + @Override + public void accept(PacketWrapper wrapper) throws Exception { + byte propertyFlags = wrapper.passthrough(Type.BYTE); // Flags + if ((propertyFlags & 0x01) != 0) wrapper.passthrough(Type.LONG); // Min Value + if ((propertyFlags & 0x02) != 0) wrapper.passthrough(Type.LONG); // Max Value + } + }); + this.parserHandlers.put("brigadier:string", new CommandArgumentConsumer() { + @Override + public void accept(PacketWrapper wrapper) throws Exception { + wrapper.passthrough(Type.VAR_INT); // Flags + } + }); + this.parserHandlers.put("minecraft:entity", new CommandArgumentConsumer() { + @Override + public void accept(PacketWrapper wrapper) throws Exception { + wrapper.passthrough(Type.BYTE); // Flags + } + }); + this.parserHandlers.put("minecraft:score_holder", new CommandArgumentConsumer() { + @Override + public void accept(PacketWrapper wrapper) throws Exception { + wrapper.passthrough(Type.BYTE); // Flags + } + }); } public void handleArgument(PacketWrapper wrapper, String argumentType) throws Exception { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 29d910c96..21cc17fff 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -73,13 +73,12 @@ public class Protocol1_13To1_12_2 extends Protocol