This commit is contained in:
mfnalex 2021-12-09 19:15:42 +01:00
parent 7be76e2343
commit 3563a827f7
6 changed files with 68 additions and 3 deletions

View File

@ -1,5 +1,8 @@
# Changelog # Changelog
## 12.1.1
- ChestSort will no longer move any shulkerboxes in the inventory around if this shulkerbox is currently open in ShulkerPacks
## 12.0.6 ## 12.0.6
- Fixed "additional-hotkeys" not working for ender chests - Fixed "additional-hotkeys" not working for ender chests

View File

@ -9,7 +9,7 @@
<name>ChestSort</name> <name>ChestSort</name>
<url>https://www.chestsort.de</url> <url>https://www.chestsort.de</url>
<description>Allows automatic chest sorting!</description> <description>Allows automatic chest sorting!</description>
<version>12.1.0</version> <version>12.1.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>

View File

@ -5,6 +5,7 @@ import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.data.Category; import de.jeff_media.chestsort.data.Category;
import de.jeff_media.chestsort.hooks.CrackShotHook; import de.jeff_media.chestsort.hooks.CrackShotHook;
import de.jeff_media.chestsort.hooks.InventoryPagesHook; import de.jeff_media.chestsort.hooks.InventoryPagesHook;
import de.jeff_media.chestsort.hooks.ShulkerPacksHook;
import de.jeff_media.chestsort.hooks.SlimeFunHook; import de.jeff_media.chestsort.hooks.SlimeFunHook;
import de.jeff_media.chestsort.data.CategoryLinePair; import de.jeff_media.chestsort.data.CategoryLinePair;
import de.jeff_media.chestsort.utils.EnchantmentUtils; import de.jeff_media.chestsort.utils.EnchantmentUtils;
@ -552,6 +553,7 @@ public class ChestSortOrganizer {
if ((plugin.isHookMinepacks() && plugin.getListener().minepacksHook.isMinepacksBackpack(items[i])) if ((plugin.isHookMinepacks() && plugin.getListener().minepacksHook.isMinepacksBackpack(items[i]))
|| (plugin.isHookInventoryPages() && inventoryPagesHook.isButton(items[i], i, inv)) || (plugin.isHookInventoryPages() && inventoryPagesHook.isButton(items[i], i, inv))
|| (plugin.getConfig().getBoolean("dont-move-slimefun-backpacks") && SlimeFunHook.isSlimefunBackpack(items[i])) || (plugin.getConfig().getBoolean("dont-move-slimefun-backpacks") && SlimeFunHook.isSlimefunBackpack(items[i]))
|| ShulkerPacksHook.isOpenShulkerPack(items[i])
|| isOversizedStack(items[i]) || isOversizedStack(items[i])
|| chestSortEvent.isUnmovable(i) || chestSortEvent.isUnmovable(i)
|| chestSortEvent.isUnmovable(items[i])) { || chestSortEvent.isUnmovable(items[i])) {
@ -718,6 +720,8 @@ public class ChestSortOrganizer {
if (plugin.isHookInventoryPages() if (plugin.isHookInventoryPages()
&& plugin.getOrganizer().inventoryPagesHook.isButton(currentItem, i, source)) continue; && plugin.getOrganizer().inventoryPagesHook.isButton(currentItem, i, source)) continue;
if(ShulkerPacksHook.isOpenShulkerPack(currentItem)) continue;
if (destinationIsShulkerBox && currentItem.getType().name().endsWith("SHULKER_BOX")) continue; if (destinationIsShulkerBox && currentItem.getType().name().endsWith("SHULKER_BOX")) continue;
if (isOversizedStack(currentItem)) continue; if (isOversizedStack(currentItem)) continue;

View File

@ -0,0 +1,59 @@
package de.jeff_media.chestsort.hooks;
import de.jeff_media.chestsort.ChestSortPlugin;
import de.jeff_media.chestsort.api.ChestSortEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.w3c.dom.ls.LSOutput;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ShulkerPacksHook {
private static Method checkIfOpenMethod;
private static Boolean installed = null;
public static boolean isOpenShulkerPack(ItemStack item) {
if(installed == null) {
if (Bukkit.getPluginManager().getPlugin("ShulkerPacks") == null) {
installed = false;
return false;
}
try {
checkIfOpenMethod = Class.forName("me.darkolythe.shulkerpacks.ShulkerListener").getDeclaredMethod("checkIfOpen",ItemStack.class);
//System.out.println("Found ShulkerPacks method: " + checkIfOpenMethod);
if(checkIfOpenMethod != null) checkIfOpenMethod.setAccessible(true);
installed = checkIfOpenMethod != null;
} catch (Throwable t) {
installed = false;
ChestSortPlugin.getInstance().getLogger().severe("Error while hooking into ShulkerPacks. Try updating ShulkerPacks to the newest version.");
t.printStackTrace();
return false;
}
}
if(installed) {
try {
return (boolean) checkIfOpenMethod.invoke(null, item);
} catch (IllegalAccessException | InvocationTargetException ignored) {
return false;
}
} else {
return false;
}
}
public static boolean containsOpenShulkerPack(Inventory inventory) {
for(ItemStack item : inventory.getContents()) {
if(item == null) continue;
if(!item.getType().name().endsWith("SHULKER_BOX")) continue;
if(isOpenShulkerPack(item)) return true;
}
return false;
}
}

View File

@ -502,7 +502,6 @@ public class Listener implements org.bukkit.event.Listener {
return; return;
} }
switch (event.getClick()) { switch (event.getClick()) {
case MIDDLE: case MIDDLE:
cause = Logger.SortCause.H_MIDDLE; cause = Logger.SortCause.H_MIDDLE;

View File

@ -10,7 +10,7 @@ website: ${project.url}
prefix: ${spigot.prefix} prefix: ${spigot.prefix}
database: false database: false
loadbefore: [InvUnload] loadbefore: [InvUnload]
softdepend: [CrackShot,InventoryPages,Minepacks,PlaceholderAPI,AdvancedChests] softdepend: [CrackShot,InventoryPages,Minepacks,PlaceholderAPI,AdvancedChests,ShulkerPacks]
commands: commands:
sort: sort:
description: Toggle automatic chest sorting or change your hotkey settings description: Toggle automatic chest sorting or change your hotkey settings