From e9e5c2cf434553b709fd17bf9c255e12e1bb8263 Mon Sep 17 00:00:00 2001
From: mfnalex <1122571+mfnalex@users.noreply.github.com>
Date: Thu, 9 Sep 2021 20:04:33 +0200
Subject: [PATCH] 11.5.1
---
CHANGELOG.md | 3 ++
pom.xml | 6 +--
.../chestsort/hooks/SlimeFunHook.java | 38 +++++++++++++++++--
3 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a85285d..ec471aa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
# Changelog
+## 11.5.1
+- Added support for new Slimefun API
+
## 11.5.0
- Added support for AdvancedChests (thanks to its author)
diff --git a/pom.xml b/pom.xml
index 2d9d992..686bde7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
ChestSort
https://www.chestsort.de
Allows automatic chest sorting!
- 11.5.0
+ 11.5.1
jar
@@ -239,9 +239,9 @@
- com.github.TheBusyBiscuit
+ com.github.Slimefun
Slimefun4
- RC-15
+ RC-28
provided
diff --git a/src/main/java/de/jeff_media/chestsort/hooks/SlimeFunHook.java b/src/main/java/de/jeff_media/chestsort/hooks/SlimeFunHook.java
index 4a5a18b..7bc0d46 100644
--- a/src/main/java/de/jeff_media/chestsort/hooks/SlimeFunHook.java
+++ b/src/main/java/de/jeff_media/chestsort/hooks/SlimeFunHook.java
@@ -1,12 +1,42 @@
package de.jeff_media.chestsort.hooks;
-import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
-import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
+import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
+import java.lang.reflect.Method;
+
public class SlimeFunHook {
public static boolean isSlimefunBackpack(ItemStack item) {
- return SlimefunItem.getByItem(item) instanceof SlimefunBackpack;
+
+ if(Bukkit.getPluginManager().getPlugin("Slimefun") == null) {
+ return false;
+ }
+
+ // New Slimefun API
+ try {
+ final Class> slimefunItemClass = Class.forName("io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem");
+ final Class> slimefunBackpackClass = Class.forName("io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack");
+ final Method getByItemMethod = slimefunItemClass.getMethod("getByItem", ItemStack.class);
+ final Object result = getByItemMethod.invoke(null, item);
+ if(result == null) return false;
+ return slimefunBackpackClass.isInstance(result);
+ } catch (Throwable ignored) {
+
+ }
+
+ // Old Slimefun API
+ try {
+ final Class> slimefunItemClass = Class.forName("me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem");
+ final Class> slimefunBackpackClass = Class.forName("io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack");
+ final Method getByItemMethod = slimefunItemClass.getMethod("getByItem", ItemStack.class);
+ final Object result = getByItemMethod.invoke(null, item);
+ if(result == null) return false;
+ return slimefunBackpackClass.isInstance(result);
+ } catch (Throwable ignored) {
+
+ }
+
+ return false;
}
-}
+}
\ No newline at end of file