Move comparator system to SongodaCore.

This commit is contained in:
Brianna 2020-04-22 10:32:23 -04:00
parent ee9aa64197
commit c120b57866
3 changed files with 5 additions and 44 deletions

View File

@ -1,6 +1,7 @@
package com.songoda.epichoppers.listeners;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.utils.BlockUtils;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.hopper.Hopper;
import com.songoda.epichoppers.hopper.levels.modules.Module;
@ -138,10 +139,10 @@ public class HopperListeners implements Listener {
//event.setItem(moveInstead);
// we need to instead cancel and manually remove the item to move
source.removeItem(moveInstead);
Methods.updateAdjacentComparators(sourceLocation);
BlockUtils.updateAdjacentComparators(sourceLocation);
// now add it to the hopper
destination.addItem(moveInstead);
Methods.updateAdjacentComparators(destinationLocation);
BlockUtils.updateAdjacentComparators(destinationLocation);
}
return;
}

View File

@ -188,47 +188,6 @@ public class Methods {
serializeCache.put(cacheKey, location.clone());
return location;
}
private static Class<?> clazzCraftWorld, clazzCraftBlock, clazzBlockPosition;
private static Method getHandle, updateAdjacentComparators, getNMSBlock;
public static void updateAdjacentComparators(Location location) {
if(location == null || location.getWorld() == null) {
return;
}
try {
// Cache reflection.
if (clazzCraftWorld == null) {
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");
Class<?> clazzWorld = Class.forName("net.minecraft.server." + ver + ".World");
Class<?> clazzBlock = Class.forName("net.minecraft.server." + ver + ".Block");
getHandle = clazzCraftWorld.getMethod("getHandle");
updateAdjacentComparators = clazzWorld.getMethod("updateAdjacentComparators", clazzBlockPosition, clazzBlock);
getNMSBlock = clazzCraftBlock.getDeclaredMethod("getNMSBlock");
getNMSBlock.setAccessible(true);
}
// invoke and cast objects.
Object craftWorld = clazzCraftWorld.cast(location.getWorld());
Object world = getHandle.invoke(craftWorld);
Object craftBlock = clazzCraftBlock.cast(location.getBlock());
// Invoke final method.
updateAdjacentComparators
.invoke(world, clazzBlockPosition.getConstructor(double.class, double.class, double.class)
.newInstance(location.getX(), location.getY(), location.getZ()),
getNMSBlock.invoke(craftBlock));
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
}
public static String convertToInvisibleString(String s) {
if (s == null || s.equals(""))
return "";

View File

@ -2,6 +2,7 @@ package com.songoda.epichoppers.utils;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.utils.BlockUtils;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -108,7 +109,7 @@ public class StorageContainerCache {
inventory.setItem(i, cachedInventory[i]);
}
}
Methods.updateAdjacentComparators(e.getKey().getLocation());
BlockUtils.updateAdjacentComparators(e.getKey().getLocation());
});
inventoryCache.clear();
}