From 4ce0463465fb23b5cc73661e1ab8c096fd4110fb Mon Sep 17 00:00:00 2001 From: retrooper Date: Wed, 19 Aug 2020 16:07:57 +0200 Subject: [PATCH] Release 1.5.8.2 * WrappedPacketInBlockDig fixed for 1.7.10. Only the Direction field is set to Direction.NULL. I cannot get it to work, this is a quick solution for now. --- pom.xml | 2 +- .../packetevents/example/MainExample.java | 5 ++- .../in/blockdig/WrappedPacketInBlockDig.java | 43 +++++++++++-------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index dcd4c33038..9c66465472 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.retrooper packetevents - 1.5.8 + 1.5.8.2 diff --git a/src/main/java/io/github/retrooper/packetevents/example/MainExample.java b/src/main/java/io/github/retrooper/packetevents/example/MainExample.java index f70c7388a4..e01daa016a 100644 --- a/src/main/java/io/github/retrooper/packetevents/example/MainExample.java +++ b/src/main/java/io/github/retrooper/packetevents/example/MainExample.java @@ -2,10 +2,13 @@ import io.github.retrooper.packetevents.PacketEvents; import io.github.retrooper.packetevents.annotations.PacketHandler; +import io.github.retrooper.packetevents.enums.Direction; +import io.github.retrooper.packetevents.enums.minecraft.PlayerDigType; import io.github.retrooper.packetevents.event.PacketListener; import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent; import io.github.retrooper.packetevents.packet.PacketType; import io.github.retrooper.packetevents.packetwrappers.in.armanimation.WrappedPacketInArmAnimation; +import io.github.retrooper.packetevents.packetwrappers.in.blockdig.WrappedPacketInBlockDig; import io.github.retrooper.packetevents.packetwrappers.in.custompayload.WrappedPacketInCustomPayload; import io.github.retrooper.packetevents.packetwrappers.in.helditemslot.WrappedPacketInHeldItemSlot; import io.github.retrooper.packetevents.packetwrappers.in.settings.WrappedPacketInSettings; @@ -24,7 +27,7 @@ public void onEnable() { PacketEvents.getSettings().setIdentifier("official_api"); PacketEvents.start(this); - //If packetevents cannot detect your server version, it will use the default you specify version + //If PacketEvents cannot detect your server version, it will use the default you specify version // getAPI().getSettings().setDefaultServerVersion(ServerVersion.v_1_7_10); diff --git a/src/main/java/io/github/retrooper/packetevents/packetwrappers/in/blockdig/WrappedPacketInBlockDig.java b/src/main/java/io/github/retrooper/packetevents/packetwrappers/in/blockdig/WrappedPacketInBlockDig.java index 3c39c90298..df61ae4136 100644 --- a/src/main/java/io/github/retrooper/packetevents/packetwrappers/in/blockdig/WrappedPacketInBlockDig.java +++ b/src/main/java/io/github/retrooper/packetevents/packetwrappers/in/blockdig/WrappedPacketInBlockDig.java @@ -8,6 +8,8 @@ import io.github.retrooper.packetevents.utils.NMSUtils; import io.github.retrooper.packetevents.utils.vector.Vector3i; +import java.util.Vector; + public final class WrappedPacketInBlockDig extends WrappedPacket { private static Class blockDigClass, blockPositionClass, enumDirectionClass, digTypeClass; @@ -23,11 +25,13 @@ public final class WrappedPacketInBlockDig extends WrappedPacket { e.printStackTrace(); } - try { - digTypeClass = NMSUtils.getNMSClass("EnumPlayerDigType"); - } catch (ClassNotFoundException e) { - //It is probably a subclass - digTypeClass = Reflection.getSubClass(blockDigClass, "EnumPlayerDigType"); + if(version.isHigherThan(ServerVersion.v_1_7_10)) { + try { + digTypeClass = NMSUtils.getNMSClass("EnumPlayerDigType"); + } catch (ClassNotFoundException e) { + //It is probably a subclass + digTypeClass = Reflection.getSubClass(blockDigClass, "EnumPlayerDigType"); + } } } @@ -43,12 +47,15 @@ public WrappedPacketInBlockDig(Object packet) { protected void setup() { Direction enumDirection = null; PlayerDigType enumDigType = null; + int x = 0, y = 0, z = 0; //1.7.10 try { if (version.isLowerThan(ServerVersion.v_1_8)) { - setupCoordinates(blockDigClass, packet); - enumDirection = Direction.get(Reflection.getField(digTypeClass, int.class, 3).getInt(packet)); - enumDigType = PlayerDigType.get(Reflection.getField(digTypeClass, int.class, 4).getInt(packet)); + enumDigType = PlayerDigType.get(Reflection.getField(blockDigClass, int.class, 4).getInt(packet)); + x = Reflection.getField(blockDigClass, int.class, 0).getInt(packet); + y = Reflection.getField(blockDigClass, int.class, 1).getInt(packet); + z = Reflection.getField(blockDigClass, int.class, 2).getInt(packet); + enumDirection = null; } else { //1.8+ final Object blockPosObj = Reflection.getField(blockDigClass, blockPositionClass, 0).get(packet); @@ -56,7 +63,9 @@ protected void setup() { final Object digTypeObj = Reflection.getField(blockDigClass, digTypeClass, 0).get(packet); Class blockPosSuper = blockPositionClass; - setupCoordinates(blockPosSuper, blockPosObj); + x = Reflection.getField(blockPosSuper, int.class, 0).getInt(blockPosObj); + y = Reflection.getField(blockPosSuper, int.class, 1).getInt(blockPosObj); + z = Reflection.getField(blockPosSuper, int.class, 2).getInt(blockPosObj); enumDirection = Direction.valueOf(((Enum) enumDirectionObj).name()); enumDigType = PlayerDigType.valueOf(((Enum) digTypeObj).name()); @@ -64,16 +73,14 @@ protected void setup() { } catch (IllegalAccessException e) { e.printStackTrace(); } - this.direction = enumDirection; - this.digType = enumDigType; - } - - private void setupCoordinates(final Class cls, final Object object) throws IllegalAccessException { - final int x = Reflection.getField(cls, int.class, 0).getInt(object); - final int y = Reflection.getField(cls, int.class, 1).getInt(object); - final int z = Reflection.getField(cls, int.class, 2).getInt(object); - this.blockPosition = new Vector3i(x, y, z); + if(enumDirection == null) { + this.direction = Direction.NULL; + } + else { + this.direction = enumDirection; + } + this.digType = enumDigType; } public Vector3i getBlockPosition() {