This commit is contained in:
mfnalex 2021-09-09 20:04:33 +02:00
parent f8e865aa0c
commit e9e5c2cf43
3 changed files with 40 additions and 7 deletions

View File

@ -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)

View File

@ -9,7 +9,7 @@
<name>ChestSort</name>
<url>https://www.chestsort.de</url>
<description>Allows automatic chest sorting!</description>
<version>11.5.0</version>
<version>11.5.1</version>
<packaging>jar</packaging>
<properties>
@ -239,9 +239,9 @@
</dependency>
<dependency>
<groupId>com.github.TheBusyBiscuit</groupId>
<groupId>com.github.Slimefun</groupId>
<artifactId>Slimefun4</artifactId>
<version>RC-15</version>
<version>RC-28</version>
<scope>provided</scope>
</dependency>

View File

@ -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;
}
}
}