Removed some illegal access reflection.

This commit is contained in:
Brianna 2021-06-09 12:33:53 -05:00
parent e0bed2d80e
commit 3d415d6da6
2 changed files with 18 additions and 11 deletions

View File

@ -309,7 +309,7 @@ public class BlockUtils {
} }
private static Class<?> clazzCraftWorld, clazzCraftBlock, clazzBlockPosition; private static Class<?> clazzCraftWorld, clazzCraftBlock, clazzBlockPosition;
private static Method getHandle, updateAdjacentComparators, getNMSBlock; private static Method getHandle, updateAdjacentComparators, craftBlock_getNMS, nmsBlockData_getBlock;
/** /**
* Manually trigger the updateAdjacentComparators method for containers * Manually trigger the updateAdjacentComparators method for containers
@ -331,8 +331,10 @@ public class BlockUtils {
getHandle = clazzCraftWorld.getMethod("getHandle"); getHandle = clazzCraftWorld.getMethod("getHandle");
updateAdjacentComparators = clazzWorld.getMethod("updateAdjacentComparators", clazzBlockPosition, clazzBlock); updateAdjacentComparators = clazzWorld.getMethod("updateAdjacentComparators", clazzBlockPosition, clazzBlock);
getNMSBlock = clazzCraftBlock.getDeclaredMethod("getNMSBlock");
getNMSBlock.setAccessible(true); craftBlock_getNMS = clazzCraftBlock.getDeclaredMethod("getNMS");
Class<?> clazzBlockData = Class.forName("net.minecraft.server." + ver + ".BlockBase$BlockData");
nmsBlockData_getBlock = clazzBlockData.getDeclaredMethod("getBlock");
} }
// invoke and cast objects. // invoke and cast objects.
@ -344,7 +346,7 @@ public class BlockUtils {
updateAdjacentComparators updateAdjacentComparators
.invoke(world, clazzBlockPosition.getConstructor(double.class, double.class, double.class) .invoke(world, clazzBlockPosition.getConstructor(double.class, double.class, double.class)
.newInstance(location.getX(), location.getY(), location.getZ()), .newInstance(location.getX(), location.getY(), location.getZ()),
getNMSBlock.invoke(craftBlock)); nmsBlockData_getBlock.invoke(craftBlock_getNMS.invoke(craftBlock)));
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -74,10 +74,13 @@ public class BlockUtilsModern {
} }
} }
private static Class<?> clazzCraftWorld, clazzCraftBlock, private static Class<?> clazzCraftWorld;
clazzLeverBlock, clazzButtonBlock, clazzPressurePlateBlock; private static Class<?> clazzCraftBlock;
private static Method craftWorld_getHandle, craftBlock_getNMSBlock, craftBlock_getPostition, craftBlockData_getState, private static Class<?> clazzLeverBlock;
nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours; private static Class<?> clazzButtonBlock;
private static Class<?> clazzPressurePlateBlock;
private static Method craftWorld_getHandle, craftBlock_getNMS, craftBlock_getPostition, craftBlockData_getState,
nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours, nmsBlockData_getBlock;
static { static {
try { try {
@ -89,10 +92,12 @@ public class BlockUtilsModern {
//clazzBlockPosition = Class.forName("net.minecraft.server." + ver + ".BlockPosition"); //clazzBlockPosition = Class.forName("net.minecraft.server." + ver + ".BlockPosition");
craftWorld_getHandle = clazzCraftWorld.getMethod("getHandle"); craftWorld_getHandle = clazzCraftWorld.getMethod("getHandle");
craftBlock_getNMSBlock = clazzCraftBlock.getDeclaredMethod("getNMSBlock");
craftBlock_getNMSBlock.setAccessible(true);
craftBlock_getPostition = clazzCraftBlock.getDeclaredMethod("getPosition"); craftBlock_getPostition = clazzCraftBlock.getDeclaredMethod("getPosition");
craftBlock_getNMS = clazzCraftBlock.getDeclaredMethod("getNMS");
Class<?> clazzBlockData = Class.forName("net.minecraft.server." + ver + ".BlockBase$BlockData");
nmsBlockData_getBlock = clazzBlockData.getDeclaredMethod("getBlock");
Class<?> clazzCraftBlockData = Class.forName("org.bukkit.craftbukkit." + ver + ".block.data.CraftBlockData"); Class<?> clazzCraftBlockData = Class.forName("org.bukkit.craftbukkit." + ver + ".block.data.CraftBlockData");
craftBlockData_getState = clazzCraftBlockData.getDeclaredMethod("getState"); craftBlockData_getState = clazzCraftBlockData.getDeclaredMethod("getState");
@ -131,7 +136,7 @@ public class BlockUtilsModern {
Object cworld = clazzCraftWorld.cast(block.getWorld()); Object cworld = clazzCraftWorld.cast(block.getWorld());
Object mworld = craftWorld_getHandle.invoke(cworld); Object mworld = craftWorld_getHandle.invoke(cworld);
Object cblock = clazzCraftBlock.cast(block); Object cblock = clazzCraftBlock.cast(block);
Object mblock = craftBlock_getNMSBlock.invoke(cblock); Object mblock = nmsBlockData_getBlock.invoke(craftBlock_getNMS.invoke(cblock));
Object mpos = craftBlock_getPostition.invoke(cblock); Object mpos = craftBlock_getPostition.invoke(cblock);
//System.out.println(mblock.getClass()); //System.out.println(mblock.getClass());