From ed7958540d0ecc78b2129f7d5a424c9ba7552da4 Mon Sep 17 00:00:00 2001 From: mfnalex <1122571+mfnalex@users.noreply.github.com> Date: Wed, 15 Jul 2020 00:09:59 +0200 Subject: [PATCH] 8.15.2-SNAPSHOT --- CHANGELOG.md | 3 +++ pom.xml | 2 +- .../ChestSort/ChestSortListener.java | 15 +++++++++++ .../jeff_media/ChestSort/ChestSortPlugin.java | 12 ++++++++- .../ChestSort/hooks/GenericGUIHook.java | 25 +++++++++++++++++++ src/main/resources/config.yml | 5 ++-- src/main/resources/plugin.yml | 2 +- 7 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/jeff_media/ChestSort/hooks/GenericGUIHook.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 3756c94..8ea42cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 8.15.2 +- Added generic hook for 3rd plugin GUIs + ## 8.15.1 - Fixed dirt in containers being affected by the right-click hotkey even though the player had no dirt in his inventory diff --git a/pom.xml b/pom.xml index 1c4ae4c..3ee2a20 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ ChestSort https://www.chestsort.de Automatically sorts your chests! - 8.15.1 + 8.15.2-SNAPSHOT jar diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java b/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java index 7079b9e..ea32588 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java @@ -334,6 +334,13 @@ public class ChestSortListener implements Listener { boolean isAPICall = isAPICall(event.getClickedInventory()); + // Detect generic GUIs + if(!isAPICall && + (plugin.genericHook.isPluginGUI(event.getInventory()) + || plugin.genericHook.isPluginGUI(event.getInventory()))) { + return; + } + // Possible fix for #57 if (!isAPICall && (event.getClickedInventory().getHolder() != null && event.getClickedInventory().getHolder() == p @@ -445,6 +452,7 @@ public class ChestSortListener implements Listener { } private boolean isAPICall(Inventory inv) { + if(inv==null) return false; return inv.getHolder() instanceof ISortable; } @@ -497,6 +505,13 @@ public class ChestSortListener implements Listener { return; } + // Detect generic GUIs + if(!isAPICall(e.getInventory()) && !isAPICall(e.getClickedInventory()) && + (plugin.genericHook.isPluginGUI(e.getInventory()) + || plugin.genericHook.isPluginGUI(e.getInventory()))) { + return; + } + // Don't sort inventories belonging to BossShopPro if (e.getInventory() != null && e.getInventory().getHolder() != null && e.getInventory().getHolder().getClass().getName().equalsIgnoreCase("org.black_ixx.bossshop.core.BSShopHolder")) { return; diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java b/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java index a748c41..2649d31 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java @@ -41,6 +41,7 @@ import java.util.Iterator; import java.util.Map; import java.util.UUID; +import de.jeff_media.ChestSort.hooks.GenericGUIHook; import de.jeff_media.PluginUpdateChecker.PluginUpdateChecker; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; @@ -68,7 +69,7 @@ public class ChestSortPlugin extends JavaPlugin implements de.jeff_media.ChestSo String sortingMethod; ArrayList disabledWorlds; ChestSortAPIHandler api; - final int currentConfigVersion = 37; + final int currentConfigVersion = 38; boolean usingMatchingConfig = true; protected boolean debug = false; boolean verbose = true; @@ -77,6 +78,8 @@ public class ChestSortPlugin extends JavaPlugin implements de.jeff_media.ChestSo public boolean hookCrackShot = false; public boolean hookInventoryPages = false; public boolean hookMinepacks = false; + + public GenericGUIHook genericHook; private static long updateCheckInterval = 4*60*60; // in seconds. We check on startup and every 4 hours @@ -125,6 +128,10 @@ public class ChestSortPlugin extends JavaPlugin implements de.jeff_media.ChestSo return perPlayerSettings.get(p.getUniqueId().toString()).sortingEnabled; } + public void debug(String t) { + if(debug) getLogger().warning("[DEBUG] "+t); + } + // Creates the default configuration file // Also checks the config-version of an already existing file. If the existing // config is too @@ -199,6 +206,7 @@ public class ChestSortPlugin extends JavaPlugin implements de.jeff_media.ChestSo getConfig().addDefault("hook-crackshot-prefix", "crackshot_weapon"); getConfig().addDefault("hook-inventorypages", true); getConfig().addDefault("hook-minepacks", true); + getConfig().addDefault("hook-generic",true); getConfig().addDefault("verbose", true); // Prints some information in onEnable() } @@ -447,6 +455,8 @@ public class ChestSortPlugin extends JavaPlugin implements de.jeff_media.ChestSo hookMinepacks = getConfig().getBoolean("hook-minepacks") && Bukkit.getPluginManager().getPlugin("Minepacks") instanceof MinepacksPlugin; + genericHook = new GenericGUIHook(this,getConfig().getBoolean("hook-generic")); + saveDefaultCategories(); verbose = getConfig().getBoolean("verbose"); diff --git a/src/main/java/de/jeff_media/ChestSort/hooks/GenericGUIHook.java b/src/main/java/de/jeff_media/ChestSort/hooks/GenericGUIHook.java new file mode 100644 index 0000000..04e4c44 --- /dev/null +++ b/src/main/java/de/jeff_media/ChestSort/hooks/GenericGUIHook.java @@ -0,0 +1,25 @@ +package de.jeff_media.ChestSort.hooks; + +import de.jeff_media.ChestSort.ChestSortPlugin; +import org.bukkit.inventory.Inventory; + +public class GenericGUIHook { + + ChestSortPlugin main; + boolean enabled; + + public GenericGUIHook(ChestSortPlugin main, boolean enabled) { + this.main=main; + this.enabled=enabled; + } + + public boolean isPluginGUI(Inventory inv) { + if(!enabled) return false; + if(inv.getHolder()!=null && inv.getHolder().getClass().getName().contains("GUI")) { + main.debug("Generic GUI detected by class name containing \"GUI\""); + return true; + } + return false; + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index af265f8..09f1fc3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -200,7 +200,8 @@ hook-headdatabase: true # 3rd party plugin's GUI and then prevents it from being sorted. # If you encounter any problems, like a sortable GUI inventory, # please open a new issue at Github: -# https://github.com/JEFF-Media-GbR/Spigot-ChestSort/issues +# https://github.com/JEFF-Media-GbR/Spigot-ChestSort/issues +hook-generic: true ########################## ##### Sorting Method ##### @@ -576,4 +577,4 @@ log: false # Please DO NOT change the following line manually! # It is used by the automatic config updater. -config-version: 37 +config-version: 38 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d078b01..2539cb2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: de.jeff_media.ChestSort.ChestSortPlugin name: ChestSort -version: 8.15.1 +version: 8.15.2-SNAPSHOT api-version: "1.13" description: Allows automatic chest sorting author: mfnalex