Skip to content

Commit

Permalink
* WrappedPacketInUpdateSign issue fixed for versions > than 1.8.8
Browse files Browse the repository at this point in the history
* WrappedPacket#readObjectArray() bug fix and for all other ones
  • Loading branch information
retrooper committed Sep 16, 2020
1 parent 291994d commit 33ed5ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
import io.github.retrooper.packetevents.packettype.PacketType;
import io.github.retrooper.packetevents.packetwrappers.in.updatesign.WrappedPacketInUpdateSign;
import io.github.retrooper.packetevents.packetwrappers.out.entityvelocity.WrappedPacketOutEntityVelocity;
import org.bukkit.plugin.java.JavaPlugin;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public double readDouble(int index) {
public boolean[] readBooleanArray(int index) {
int currentIndex = 0;
for(Field f : fields) {
if (boolean.class.isAssignableFrom(f.getType())) {
if (boolean[].class.isAssignableFrom(f.getType())) {
if(index == currentIndex++) {
try {
return (boolean[]) f.get(packet);
Expand All @@ -192,7 +192,7 @@ public boolean[] readBooleanArray(int index) {
public byte[] readByteArray(int index) {
int currentIndex = 0;
for(Field f : fields) {
if (byte.class.isAssignableFrom(f.getType())) {
if (byte[].class.isAssignableFrom(f.getType())) {
if(index == currentIndex++) {
try {
return (byte[]) f.get(packet);
Expand All @@ -209,7 +209,7 @@ public byte[] readByteArray(int index) {
public short[] readShortArray(int index) {
int currentIndex = 0;
for(Field f : fields) {
if (short.class.isAssignableFrom(f.getType())) {
if (short[].class.isAssignableFrom(f.getType())) {
if(index == currentIndex++) {
try {
return (short[]) f.get(packet);
Expand All @@ -226,7 +226,7 @@ public short[] readShortArray(int index) {
public int[] readIntArray(int index) {
int currentIndex = 0;
for(Field f : fields) {
if (int.class.isAssignableFrom(f.getType())) {
if (int[].class.isAssignableFrom(f.getType())) {
if(index == currentIndex++) {
try {
return (int[]) f.get(packet);
Expand All @@ -243,7 +243,7 @@ public int[] readIntArray(int index) {
public long[] readLongArray(int index) {
int currentIndex = 0;
for(Field f : fields) {
if (long.class.isAssignableFrom(f.getType())) {
if (long[].class.isAssignableFrom(f.getType())) {
if(index == currentIndex++) {
try {
return (long[]) f.get(packet);
Expand Down Expand Up @@ -277,7 +277,7 @@ public float[] readFloatArray(int index) {
public double[] readDoubleArray(int index) {
int currentIndex = 0;
for(Field f : fields) {
if (double.class.isAssignableFrom(f.getType())) {
if (double[].class.isAssignableFrom(f.getType())) {
if(index == currentIndex++) {
try {
return (double[]) f.get(packet);
Expand All @@ -292,7 +292,13 @@ public double[] readDoubleArray(int index) {

@Override
public String[] readStringArray(int index) {
return (String[]) readObjectArray(index, String.class);
Object[] array = readObjectArray(index, String[].class);
int len = array.length;
String[] stringArray = new String[len];
for(int i = 0; i < len; i++) {
stringArray[i] = array[i].toString();
}
return stringArray;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@
import io.github.retrooper.packetevents.utils.reflection.Reflection;

public class WrappedPacketInUpdateSign extends WrappedPacket {
private static boolean v_1_7_mode;
private static boolean v_1_7_mode, strArrayMode;
private static Class<?> blockPosClass, iChatBaseComponentClass;

private int x, y, z;
private String[] lines;

public static void load() {
v_1_7_mode = Reflection.getField(PacketTypeClasses.Client.UPDATE_SIGN, int.class, 0) != null;
strArrayMode = Reflection.getField(PacketTypeClasses.Client.UPDATE_SIGN, String[].class, 0) != null;

try {
blockPosClass = NMSUtils.getNMSClass("BlockPosition");
} catch (ClassNotFoundException e) {
if(!v_1_7_mode) {
if (!v_1_7_mode) {
e.printStackTrace();
}
}
Expand All @@ -64,21 +65,23 @@ protected void setup() {
x = readInt(0);
y = readInt(1);
z = readInt(2);
lines = readStringArray(0);
}
else {
} else {
Object blockPos = readObject(0, blockPosClass);

try {
x = Reflection.getField(blockPosClass, int.class, 0).getInt(packet);
y = Reflection.getField(blockPosClass, int.class, 1).getInt(packet);
z = Reflection.getField(blockPosClass, int.class, 2).getInt(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}

}
if (strArrayMode) {
//1.7.10 and the newest versions use this
lines = readStringArray(0);
} else {
//1.8 uses this for example
Object[] iChatComponents = readObjectArray(0, iChatBaseComponentClass);
for(int i = 0; i < iChatComponents.length; i++) {
for (int i = 0; i < iChatComponents.length; i++) {
lines[i] = WrappedPacketOutChat.
toStringFromIChatBaseComponent(iChatComponents[i]);
}
Expand Down

0 comments on commit 33ed5ff

Please sign in to comment.