diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65e1d36..606aa1b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog
+## 11.5.4
+- Fixed CratesReloaded preview GUI not opening when leftclicking chests
+
## 11.5.3
- Fixed "disabled-worlds" not working for "left-click hotkey"
diff --git a/pom.xml b/pom.xml
index ee95f43..355c38e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
ChestSort
https://www.chestsort.de
Allows automatic chest sorting!
- 11.5.3
+ 11.5.4
jar
diff --git a/src/main/java/de/jeff_media/chestsort/hooks/CrateReloadedHook.java b/src/main/java/de/jeff_media/chestsort/hooks/CrateReloadedHook.java
index b249790..1ef360b 100644
--- a/src/main/java/de/jeff_media/chestsort/hooks/CrateReloadedHook.java
+++ b/src/main/java/de/jeff_media/chestsort/hooks/CrateReloadedHook.java
@@ -1,23 +1,50 @@
package de.jeff_media.chestsort.hooks;
import de.jeff_media.chestsort.ChestSortPlugin;
+import org.bukkit.Location;
+import org.bukkit.block.Block;
import org.bukkit.inventory.Inventory;
+import org.jetbrains.annotations.NotNull;
+import java.lang.reflect.Method;
+import java.util.Locale;
+
+/**
+ * Who doesn't make their API available in a public maven repository
+ * deserves to be touched using Reflection only.
+ */
public class CrateReloadedHook {
- private final ChestSortPlugin main;
+ private static final ChestSortPlugin main = ChestSortPlugin.getInstance();
+ private static Object blockCrateRegistrarObject;
+ private static Method isCrateMethod;
- public CrateReloadedHook(ChestSortPlugin main) {
- this.main=main;
+ static {
+ try {
+ Class> crateApiClazz = Class.forName("com.hazebyte.crate.api.CrateAPI");
+ Method getBlockCrateRegistrarMethod = crateApiClazz.getMethod("getBlockCrateRegistrar");
+ Class> blockCrateRegistrarClazz = Class.forName("com.hazebyte.crate.api.crate.BlockCrateRegistrar");
+ blockCrateRegistrarObject = getBlockCrateRegistrarMethod.invoke(null);
+ isCrateMethod = blockCrateRegistrarClazz.getMethod("hasCrates", Location.class);
+ } catch (Throwable ignored) {
+ isCrateMethod = null;
+ }
}
- // CrateReloaded inventories seem to have a holder called cratereloaded.bo
- // Maybe this changes? We just check if the String starts with cratereloaded
- public boolean isCrate(Inventory inv) {
+ public static boolean isCrate(@NotNull final Block block) {
+ try {
+ if(isCrateMethod != null) {
+ return (boolean) isCrateMethod.invoke(blockCrateRegistrarObject, block.getLocation());
+ }
+ } catch (Throwable ignored) { }
+ return false;
+ }
+
+ public static boolean isCrate(@NotNull final Inventory inv) {
if(inv==null) return false;
if(inv.getHolder()==null) return false;
if(!main.getConfig().getBoolean("hook-cratereloaded",true)) return false;
- return inv.getHolder().getClass().getName().startsWith("cratereloaded");
+ return inv.getHolder().getClass().getName().toLowerCase(Locale.ROOT).contains("cratereloaded");
}
}
diff --git a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java b/src/main/java/de/jeff_media/chestsort/listeners/Listener.java
index e19182d..132a3e9 100644
--- a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java
+++ b/src/main/java/de/jeff_media/chestsort/listeners/Listener.java
@@ -41,7 +41,6 @@ public class Listener implements org.bukkit.event.Listener {
final ChestSortPlugin plugin;
public final MinepacksHook minepacksHook;
final HeadDatabaseHook headDatabaseHook;
- final CrateReloadedHook crateReloadedHook;
final GoldenCratesHook goldenCratesHook;
final AdvancedChestsHook advancedChestsHook;
@@ -49,7 +48,6 @@ public class Listener implements org.bukkit.event.Listener {
this.plugin = plugin;
this.minepacksHook = new MinepacksHook(plugin);
this.headDatabaseHook = new HeadDatabaseHook(plugin);
- this.crateReloadedHook = new CrateReloadedHook(plugin);
this.goldenCratesHook = new GoldenCratesHook(plugin);
this.advancedChestsHook = new AdvancedChestsHook(plugin);
}
@@ -67,6 +65,9 @@ public class Listener implements org.bukkit.event.Listener {
if(!plugin.getConfig().getBoolean("allow-left-click-to-sort")) return;
Block clickedBlock = event.getClickedBlock();
if(!(clickedBlock.getState() instanceof Container)) return;
+ if(CrateReloadedHook.isCrate(clickedBlock)) {
+ return;
+ }
if(!ProtectionUtils.canInteract(event.getPlayer(), clickedBlock)) {
//System.out.println("ChestSort: cannot interact!");
return;
@@ -637,8 +638,8 @@ public class Listener implements org.bukkit.event.Listener {
}
// CrateReloaded hook
- if(crateReloadedHook.isCrate(e.getClickedInventory())
- || crateReloadedHook.isCrate(e.getInventory())) {
+ if(CrateReloadedHook.isCrate(e.getClickedInventory())
+ || CrateReloadedHook.isCrate(e.getInventory())) {
//if(plugin.debug) plugin.getLogger().info("Aborting hotkey because this is a CrateReloaded crate");
return;
}