From b11456d86b22c079563cc02170c5bc3ad51cfb99 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Wed, 2 Oct 2019 11:17:55 +0200 Subject: [PATCH] Helper methods for cancelling packets --- .../ViaVersion/api/ViaVersionConfig.java | 7 --- .../ViaVersion/api/protocol/Protocol.java | 18 +++++++ .../Protocol1_12To1_11_1.java | 40 +++------------- .../Protocol1_13To1_12_2.java | 37 ++------------ .../packets/EntityPackets.java | 3 +- .../Protocol1_14To1_13_2.java | 38 ++------------- .../packets/EntityPackets.java | 12 +---- .../packets/PlayerPackets.java | 48 ++----------------- 8 files changed, 40 insertions(+), 163 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java index d84d180f0..3ef26d04d 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -331,13 +331,6 @@ public interface ViaVersionConfig { boolean is1_14HealthNaNFix(); - /** - * Fixes non full blocks having 0 light for 1.14+ clients on sub 1.14 servers. - * - * @return True if enabled - */ - boolean isNonFullBlockLightFix(); - /** * Should 1.15 clients respawn instantly / without showing the death screen * diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index d6576b355..23d0acb49 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -116,6 +116,15 @@ public abstract class Protocol { incoming.put(pair, protocolPacket); } + public void cancelIncoming(State state, int newPacketID) { + registerIncoming(state, -1, newPacketID, new PacketRemapper() { + @Override + public void registerMap() { + handler(PacketWrapper::cancel); + } + }); + } + /** * Register an outgoing packet, with simple id transformation. * @@ -149,6 +158,15 @@ public abstract class Protocol { outgoing.put(pair, protocolPacket); } + public void cancelOutgoing(State state, int oldPacketID) { + registerIncoming(state, oldPacketID, -1, new PacketRemapper() { + @Override + public void registerMap() { + handler(PacketWrapper::cancel); + } + }); + } + /** * Transform a packet using this protocol * diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java index f9bc869ae..84af37f9b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java @@ -272,18 +272,8 @@ public class Protocol1_12To1_11_1 extends Protocol { // Incoming // New packet at 0x01 - registerIncoming(State.PLAY, 0x01, 0x01, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { + cancelIncoming(State.PLAY, 0x01); - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); registerIncoming(State.PLAY, 0x01, 0x02); registerIncoming(State.PLAY, 0x02, 0x03); registerIncoming(State.PLAY, 0x03, 0x04); @@ -336,33 +326,15 @@ public class Protocol1_12To1_11_1 extends Protocol { registerIncoming(State.PLAY, 0x13, 0x14); registerIncoming(State.PLAY, 0x14, 0x15); registerIncoming(State.PLAY, 0x15, 0x16); + // New packet at 0x17 - registerIncoming(State.PLAY, 0x17, 0x17, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { + cancelIncoming(State.PLAY, 0x17); - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); registerIncoming(State.PLAY, 0x16, 0x18); - // New packet 0x19 - registerIncoming(State.PLAY, 0x19, 0x19, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + // New packet 0x19 + cancelIncoming(State.PLAY, 0x19); + registerIncoming(State.PLAY, 0x17, 0x1a); // registerIncoming(State.PLAY, 0x18, 0x1b); - Handled in InventoryPackets registerIncoming(State.PLAY, 0x19, 0x1c); 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 db72dfb65..cca497ea8 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 @@ -799,30 +799,10 @@ public class Protocol1_13To1_12_2 extends Protocol { // Incoming packets // New packet 0x02 - Login Plugin Message - registerIncoming(State.LOGIN, -1, 0x02, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.LOGIN, 0x02); // New 0x01 - Query Block NBT - registerIncoming(State.PLAY, -1, 0x01, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x01); // Tab-Complete registerIncoming(State.PLAY, 0x1, 0x5, new PacketRemapper() { @@ -890,17 +870,8 @@ public class Protocol1_13To1_12_2 extends Protocol { } }); // New 0x0C - Query Entity NBT - registerIncoming(State.PLAY, -1, 0x0C, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x0C); + registerIncoming(State.PLAY, 0x0A, 0x0D); registerIncoming(State.PLAY, 0x0B, 0x0E); registerIncoming(State.PLAY, 0x0C, 0x0F); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java index 56b4ef20d..6333a9235 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java @@ -10,6 +10,7 @@ import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; public class EntityPackets { @@ -60,7 +61,7 @@ public class EntityPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) { - wrapper.user().get(EntityTracker.class).removeEntity(entity); + wrapper.user().get(EntityTracker1_14.class).removeEntity(entity); } } }); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java index ec26d7976..c3e387772 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java @@ -217,17 +217,8 @@ public class Protocol1_14To1_13_2 extends Protocol { }); //Set Difficulty packet added in 19w11a - registerIncoming(State.PLAY, -1, 0x02, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x02); + registerIncoming(State.PLAY, 0x02, 0x03); registerIncoming(State.PLAY, 0x03, 0x04); registerIncoming(State.PLAY, 0x04, 0x05); @@ -242,17 +233,8 @@ public class Protocol1_14To1_13_2 extends Protocol { registerIncoming(State.PLAY, 0x0D, 0x0E); //Lock Difficulty packet added in 19w11a - registerIncoming(State.PLAY, -1, 0x10, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x10); + registerIncoming(State.PLAY, 0x0E, 0x0F); registerIncoming(State.PLAY, 0x0F, 0x14); registerIncoming(State.PLAY, 0x10, 0x11); @@ -276,17 +258,7 @@ public class Protocol1_14To1_13_2 extends Protocol { registerIncoming(State.PLAY, 0x23, 0x25); //Unknown packet added in 19w13a - registerIncoming(State.PLAY, -1, 0x27, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) { - wrapper.cancel(); - } - }); - } - }); + cancelIncoming(State.PLAY, 0x27); registerIncoming(State.PLAY, 0x27, 0x2A); registerIncoming(State.PLAY, 0x28, 0x2B); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java index 4e3b50380..dd61f1ad4 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -249,17 +249,7 @@ public class EntityPackets { // Update Entity NBT - protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelOutgoing(State.PLAY, 0x49); // Combat Event Packet protocol.registerOutgoing(State.PLAY, 0x42, 0x2C, new PacketRemapper() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index 3bada15be..3294f7bb8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -402,17 +402,7 @@ public class PlayerPackets { /* Removed packets */ // Set Compression - protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelOutgoing(State.PLAY, 0x46); /* Packets which do not have any field remapping or handlers */ @@ -482,43 +472,13 @@ public class PlayerPackets { }); // TP Confirm - protocol.registerIncoming(State.PLAY, -1, 0x00, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelIncoming(State.PLAY, 0x00); // Vehicle Move - protocol.registerIncoming(State.PLAY, -1, 0x10, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelIncoming(State.PLAY, 0x10); // Steer Boat - protocol.registerIncoming(State.PLAY, -1, 0x11, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.cancel(); - } - }); - } - }); + protocol.cancelIncoming(State.PLAY, 0x11); // Packet Plugin Message Incoming protocol.registerIncoming(State.PLAY, 0x17, 0x09, new PacketRemapper() {