From da94ea34f9569e207cc088754acfb3da9282bb25 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 3 May 2020 19:53:11 -0400 Subject: [PATCH] updateAdjacentComparators updates. --- .../java/com/songoda/core/utils/BlockUtils.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/utils/BlockUtils.java b/Core/src/main/java/com/songoda/core/utils/BlockUtils.java index 0b61c69e..4a609e2b 100644 --- a/Core/src/main/java/com/songoda/core/utils/BlockUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/BlockUtils.java @@ -310,13 +310,15 @@ public class BlockUtils { /** * Manually trigger the updateAdjacentComparators method for containers * - * @param containerLocation location of the container + * @param location location of the container */ - public static void updateAdjacentComparators(Location containerLocation) { + public static void updateAdjacentComparators(Location location) { + if(location == null || location.getWorld() == null) return; try { // Cache reflection. if (clazzCraftWorld == null) { - String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23); + String serverPackagePath = Bukkit.getServer().getClass().getPackage().getName(); + String ver = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1); clazzCraftWorld = Class.forName("org.bukkit.craftbukkit." + ver + ".CraftWorld"); clazzCraftBlock = Class.forName("org.bukkit.craftbukkit." + ver + ".block.CraftBlock"); clazzBlockPosition = Class.forName("net.minecraft.server." + ver + ".BlockPosition"); @@ -330,14 +332,14 @@ public class BlockUtils { } // invoke and cast objects. - Object craftWorld = clazzCraftWorld.cast(containerLocation.getWorld()); + Object craftWorld = clazzCraftWorld.cast(location.getWorld()); Object world = getHandle.invoke(craftWorld); - Object craftBlock = clazzCraftBlock.cast(containerLocation.getBlock()); + Object craftBlock = clazzCraftBlock.cast(location.getBlock()); // Invoke final method. updateAdjacentComparators .invoke(world, clazzBlockPosition.getConstructor(double.class, double.class, double.class) - .newInstance(containerLocation.getX(), containerLocation.getY(), containerLocation.getZ()), + .newInstance(location.getX(), location.getY(), location.getZ()), getNMSBlock.invoke(craftBlock)); } catch (ReflectiveOperationException e) {