Skip to content

Commit

Permalink
Release 1.5.8.2
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
retrooper committed Aug 19, 2020
1 parent 6725caa commit 4ce0463
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.retrooper</groupId>
<artifactId>packetevents</artifactId>
<version>1.5.8</version>
<version>1.5.8.2</version>

<!-- You can build the project with this: "mvn clean compile assembly:single" -->
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
}
}
}

Expand All @@ -43,37 +47,40 @@ 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);
final Object enumDirectionObj = Reflection.getField(blockDigClass, enumDirectionClass, 0).get(packet);
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());
}
} 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() {
Expand Down

0 comments on commit 4ce0463

Please sign in to comment.