Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
retrooper committed Feb 12, 2021
2 parents 0eed580 + 88ccbdb commit e994c34
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
import io.github.retrooper.packetevents.utils.server.ServerVersion;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.*;

public final class WrappedPacketInBlockDig extends WrappedPacket {
private static Class<?> blockPositionClass;
Expand Down Expand Up @@ -83,7 +83,7 @@ public int getX() {
blockPosObj = readObject(0, blockPositionClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosX.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -104,7 +104,7 @@ public int getY() {
blockPosObj = readObject(0, blockPositionClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosY.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -125,7 +125,7 @@ public int getZ() {
blockPosObj = readObject(0, blockPositionClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosZ.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@

package io.github.retrooper.packetevents.packetwrappers.play.in.blockplace;

import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import io.github.retrooper.packetevents.packetwrappers.*;
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
import io.github.retrooper.packetevents.utils.reflection.Reflection;
import org.bukkit.inventory.ItemStack;

import java.lang.reflect.InvocationTargetException;
Expand All @@ -44,7 +42,7 @@ public int getX() {
blockPosObj = readObject(1, NMSUtils.blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosX.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -57,7 +55,7 @@ public int getY() {
blockPosObj = readObject(1, NMSUtils.blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosY.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -69,7 +67,7 @@ public int getZ() {
blockPosObj = readObject(1, NMSUtils.blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosZ.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
import io.github.retrooper.packetevents.utils.reflection.Reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.*;

final class WrappedPacketInBlockPlace_1_9 extends WrappedPacket {
private static Class<?> movingObjectPositionBlockClass;
Expand All @@ -56,7 +56,7 @@ public int getX() {
}
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosX.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -74,7 +74,7 @@ public int getY() {
}
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosY.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -92,7 +92,7 @@ public int getZ() {
}
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosZ.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
package io.github.retrooper.packetevents.packetwrappers.play.in.updatesign;

import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import io.github.retrooper.packetevents.packetwrappers.*;
import io.github.retrooper.packetevents.packetwrappers.play.out.chat.WrappedPacketOutChat;
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
import io.github.retrooper.packetevents.utils.reflection.Reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.*;

public class WrappedPacketInUpdateSign extends WrappedPacket {
private static boolean v_1_7_mode, strArrayMode;
Expand Down Expand Up @@ -65,7 +64,7 @@ public int getX() {
blockPosObj = readObject(0, blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosX.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -81,7 +80,7 @@ public int getY() {
blockPosObj = readObject(0, blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosY.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -97,7 +96,7 @@ public int getZ() {
blockPosObj = readObject(0, blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosZ.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -115,7 +114,7 @@ public String[] getTextLines() {
String[] lines = new String[iChatComponents.length];
for (int i = 0; i < iChatComponents.length; i++) {
lines[i] = WrappedPacketOutChat.
toStringFromIChatBaseComponent(iChatComponents[i]);
toStringFromIChatBaseComponent(iChatComponents[i]);
}
return lines;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public int getBlockX() {
blockPosObj = readObject(0, NMSUtils.blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getX", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosX.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -120,7 +120,7 @@ public int getBlockY() {
blockPosObj = readObject(0, NMSUtils.blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getY", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosY.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand All @@ -140,7 +140,7 @@ public int getBlockZ() {
blockPosObj = readObject(0, NMSUtils.blockPosClass);
}
try {
return (int) Reflection.getMethod(blockPosObj.getClass().getSuperclass(), "getZ", 0).invoke(blockPosObj);
return (int) NMSUtils.getBlockPosZ.invoke(blockPosObj);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public final class NMSUtils {
craftPlayerClass, serverConnectionClass, craftEntityClass, nmsItemStackClass, networkManagerClass, nettyChannelClass, gameProfileClass, iChatBaseComponentClass,
blockPosClass, enumDirectionClass, vec3DClass, channelFutureClass, blockClass, iBlockDataClass, watchableObjectClass, nmsWorldClass, craftItemStackClass,
soundEffectClass, minecraftKeyClass;
public static Method getBlockPosX, getBlockPosY, getBlockPosZ;
private static Method getCraftPlayerHandle;
private static Method getCraftEntityHandle;
private static Method getCraftWorldHandle;
Expand Down Expand Up @@ -172,6 +173,9 @@ public static void load() {
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
getBlockPosX = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "getX", 0);
getBlockPosY = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "getY", 0);
getBlockPosZ = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "getZ", 0);
}

public static Object getMinecraftServerInstance() {
Expand Down

0 comments on commit e994c34

Please sign in to comment.