From b760ab42909fbf726d38544697760be0c2d04c02 Mon Sep 17 00:00:00 2001
From: mfnalex <1122571+mfnalex@users.noreply.github.com>
Date: Sat, 23 May 2020 23:27:03 +0200
Subject: [PATCH] 8.6 update
---
CHANGELOG.md | 3 +
SpigotMC-description.bb | 8 +-
pom.xml | 21 +++--
...JeffChestSortAdditionalHotkeyListener.java | 58 -------------
.../JeffChestSortChestSortCommand.java | 3 -
.../JeffChestSort/JeffChestSortListener.java | 83 +++++++++++++++++--
.../JeffChestSort/JeffChestSortPlugin.java | 13 ++-
.../java/de/jeffclan/hooks/MinepacksHook.java | 47 +++++++++++
src/main/resources/config.yml | 27 +++++-
src/main/resources/plugin.yml | 4 +-
10 files changed, 179 insertions(+), 88 deletions(-)
delete mode 100644 src/main/java/de/jeffclan/JeffChestSort/JeffChestSortAdditionalHotkeyListener.java
create mode 100644 src/main/java/de/jeffclan/hooks/MinepacksHook.java
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a106ff4..13e01ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,7 @@
# Changelog
+## 8.6
+- Added support for Minepacks
+
## 8.5
- Prevent Right-Click-Hotkey from putting items in the hotbar
- Fixed InventoryPages support: when using &f at the beginning of button names, it was not detected by ChestSort as button
diff --git a/SpigotMC-description.bb b/SpigotMC-description.bb
index 7d18863..305b1f0 100644
--- a/SpigotMC-description.bb
+++ b/SpigotMC-description.bb
@@ -131,6 +131,12 @@ All CrackShot weapons will be grouped together and will be put into the default
[B]InventoryPages[/B]
ChestSort will ignore the "Next Page" and "Prev. Page" buttons when you have InventoryPages installed, so that your GUI does not get messed up.
+[B]Better Shulker Boxes / Minepacks / ShulkerPacks[/B][/SIZE]
+[SIZE=4]Sort your backpacks just like every other chest! Should work with almost every backpack plugin.
+
+[B]Plugins using GUI inventories[/B]
+ChestSort tries to detect GUI inventories created by 3rd party plugins. If this detection fails, please message me at GitHub so that I can add support for that plugin.
+
[SIZE=6]API for plugin developers[/SIZE][/SIZE]
[SIZE=4]ChestSort provides a method to sort any Inventory instance, using the advanced grouping features that ChestSort provides! Read more about the API [URL='https://github.com/JEFF-Media-GbR/Spigot-ChestSort/blob/master/HOW_TO_USE_API.md']here[/URL].
@@ -152,4 +158,4 @@ May the odds be ever in your favor! Have an angel protect your loot when you die
[URL='https://www.spigotmc.org/resources/1-13-angelchest.60383/'][1.13+] AngelChest: Stores your inventory in a protected chest when you die![/URL]
Don't want to collect all drops manually? Use Drop2Inventory. Also reduces lag.
-[URL='https://www.spigotmc.org/resources/1-13-drop2inventory.62214/'][1.13] Drop2Inventory: No more need to collect drops![/URL][/SIZE]
+[URL='https://www.spigotmc.org/resources/1-13-drop2inventory.62214/'][1.13] Drop2Inventory: No more need to collect drops![/URL][/SIZE]
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 32ee01f..c3bf7c5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
de.jeffclan
JeffChestSort
- 8.5
+ 8.6
jar
JeffChestSort
@@ -77,6 +77,10 @@
CodeMC
https://repo.codemc.org/repository/maven-public
+
+ pcgf-repo
+ https://repo.pcgamingfreaks.at/repository/maven-everything
+
@@ -86,12 +90,8 @@
1.15.2-R0.1-SNAPSHOT
provided
-
+
org.bstats
bstats-bukkit
@@ -104,7 +104,12 @@
0.98.9
system
${project.basedir}/lib/CrackShot.jar
-
+
+
+ at.pcgamingfreaks
+ Minepacks-API
+ 2.2
+
Automatically sorts your chests!
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortAdditionalHotkeyListener.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortAdditionalHotkeyListener.java
deleted file mode 100644
index 0e557b7..0000000
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortAdditionalHotkeyListener.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package de.jeffclan.JeffChestSort;
-
-import org.bukkit.block.Block;
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.inventory.InventoryClickEvent;
-import org.bukkit.event.inventory.InventoryType;
-
-public class JeffChestSortAdditionalHotkeyListener implements Listener {
-
- JeffChestSortPlugin plugin;
-
- public JeffChestSortAdditionalHotkeyListener(JeffChestSortPlugin jeffChestSortPlugin) {
- this.plugin = jeffChestSortPlugin;
- }
-
- @EventHandler
- public void onInventoryClickEvent(InventoryClickEvent e) {
- if(!plugin.getConfig().getBoolean("allow-hotkeys")) {
- return;
- }
- if(!(e.getWhoClicked() instanceof Player)) {
- return;
- }
- Player p = (Player) e.getWhoClicked();
- // Only continue if clicked outside of the chest
- if(e.getClickedInventory()!=null) {
- return;
- }
- // Possible fix for #57
- if(e.getInventory().getHolder()==null) return;
- if(e.getInventory().getHolder() == p && e.getInventory() != p.getInventory()) return;
- // End Possible fix for #57
- if(e.getInventory().getType() != InventoryType.CHEST
- && e.getInventory().getType() != InventoryType.DISPENSER
- && e.getInventory().getType() != InventoryType.DROPPER
- && e.getInventory().getType() != InventoryType.ENDER_CHEST
- && !e.getInventory().getType().name().equalsIgnoreCase("SHULKER_BOX")
- && (e.getInventory().getHolder() == null || !e.getInventory().getHolder().getClass().toString().endsWith(".CraftBarrel"))) {
- return;
- }
-
- if(!p.hasPermission("chestsort.use")) return;
-
- plugin.registerPlayerIfNeeded(p);
- JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
-
- if(e.isLeftClick() && setting.leftClick) {
- plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory());
- plugin.sortInventory(e.getInventory());
- plugin.organizer.updateInventoryView(e.getInventory());
- } else if(e.isRightClick() && setting.rightClick) {
- plugin.organizer.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(),e.getInventory());
- }
- }
-
-}
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortChestSortCommand.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortChestSortCommand.java
index deb458b..9037e2b 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortChestSortCommand.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortChestSortCommand.java
@@ -5,9 +5,6 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-import de.jeffclan.JeffChestSort.JeffChestSortPlayerSetting;
-import de.jeffclan.JeffChestSort.JeffChestSortPlugin;
-
public class JeffChestSortChestSortCommand implements CommandExecutor {
JeffChestSortPlugin plugin;
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java
index 76e96a8..b865009 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java
@@ -4,15 +4,12 @@ import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
-import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
-import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
-import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.inventory.InventoryType;
@@ -21,12 +18,16 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
+import de.jeffclan.hooks.MinepacksHook;
+
public class JeffChestSortListener implements Listener {
JeffChestSortPlugin plugin;
+ MinepacksHook minepacksHook;
JeffChestSortListener(JeffChestSortPlugin plugin) {
this.plugin = plugin;
+ this.minepacksHook = new MinepacksHook(plugin);
}
@EventHandler
@@ -51,6 +52,29 @@ public class JeffChestSortListener implements Listener {
}
+ @EventHandler
+ public void onBackPackClose(InventoryCloseEvent event) {
+ if(plugin.getConfig().getString("sort-time").equalsIgnoreCase("close")
+ || plugin.getConfig().getString("sort-time").equalsIgnoreCase("both"))
+ onBackPackUse(event.getInventory(),(Player)event.getPlayer());
+ }
+
+ @EventHandler
+ public void onBackPackOpen(InventoryOpenEvent event) {
+ if(plugin.getConfig().getString("sort-time").equalsIgnoreCase("open")
+ || plugin.getConfig().getString("sort-time").equalsIgnoreCase("both"))
+ onBackPackUse(event.getInventory(),(Player)event.getPlayer());
+ }
+
+ void onBackPackUse(Inventory inv, Player p) {
+ if(!minepacksHook.isMinepacksBackpack(inv)) return;
+ if(!p.hasPermission("chestsort.use")) return;
+ plugin.registerPlayerIfNeeded(p);
+ JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
+ if(!setting.sortingEnabled) return;
+ plugin.organizer.sortInventory(inv);
+ }
+
@EventHandler
public void onPlayerInventoryClose(InventoryCloseEvent event) {
if(event.getInventory()==null) return;
@@ -58,6 +82,7 @@ public class JeffChestSortListener implements Listener {
if(event.getInventory().getType() == null) return;
if(event.getInventory().getType() != InventoryType.CRAFTING) return; // Weird! Returns CRAFTING instead of PLAYER
if(!(event.getInventory().getHolder() instanceof Player)) return;
+
Player p = (Player) event.getInventory().getHolder();
if(!p.hasPermission("chestsort.use.inventory")) return;
@@ -270,7 +295,7 @@ public class JeffChestSortListener implements Listener {
// p.sendMessage("Shift click: " + event.isShiftClick());
// p.sendMessage("=====================");
// DEBUG END
-
+
if(!p.hasPermission("chestsort.use") && !p.hasPermission("chestsort.use.inventory")) {
return;
}
@@ -294,13 +319,11 @@ public class JeffChestSortListener implements Listener {
if(event.getClickedInventory() == setting.guiInventory) {
return;
}
-
// Prevent player from putting items into GUI inventory
if(event.getInventory() == setting.guiInventory) {
event.setCancelled(true);
return;
}
-
switch(event.getClick()) {
case MIDDLE:
//if(plugin.getConfig().getBoolean("hotkeys.middle-click")) {
@@ -340,18 +363,17 @@ public class JeffChestSortListener implements Listener {
if(!sort) {
return;
}
-
- if(belongsToChestLikeBlock(event.getClickedInventory())) {
+ if(belongsToChestLikeBlock(event.getClickedInventory()) || minepacksHook.isMinepacksBackpack(event.getClickedInventory())) {
if(!p.hasPermission("chestsort.use")) {
return;
}
+
plugin.organizer.sortInventory(event.getClickedInventory());
plugin.organizer.updateInventoryView(event);
return;
} else if(holder instanceof Player) {
-
if(!p.hasPermission("chestsort.use.inventory")) {
return;
}
@@ -370,6 +392,49 @@ public class JeffChestSortListener implements Listener {
}
}
+ @EventHandler
+ public void onAdditionalHotkeys(InventoryClickEvent e) {
+ // Backpacks must not go into backpacks, however I am unsure on how to
+ // check if something is a backpack, so will just disable the fill-chest hotkey
+ if(minepacksHook.isMinepacksBackpack(e.getInventory())) return;
+ if(!plugin.getConfig().getBoolean("allow-hotkeys")) {
+ return;
+ }
+ if(!(e.getWhoClicked() instanceof Player)) {
+ return;
+ }
+ Player p = (Player) e.getWhoClicked();
+ // Only continue if clicked outside of the chest
+ if(e.getClickedInventory()!=null) {
+ return;
+ }
+ // Possible fix for #57
+ if(e.getInventory().getHolder()==null) return;
+ if(e.getInventory().getHolder() == p && e.getInventory() != p.getInventory()) return;
+ // End Possible fix for #57
+ if(e.getInventory().getType() != InventoryType.CHEST
+ && e.getInventory().getType() != InventoryType.DISPENSER
+ && e.getInventory().getType() != InventoryType.DROPPER
+ && e.getInventory().getType() != InventoryType.ENDER_CHEST
+ && !e.getInventory().getType().name().equalsIgnoreCase("SHULKER_BOX")
+ && (e.getInventory().getHolder() == null || !e.getInventory().getHolder().getClass().toString().endsWith(".CraftBarrel"))) {
+ return;
+ }
+
+ if(!p.hasPermission("chestsort.use")) return;
+
+ plugin.registerPlayerIfNeeded(p);
+ JeffChestSortPlayerSetting setting = plugin.perPlayerSettings.get(p.getUniqueId().toString());
+
+ if(e.isLeftClick() && setting.leftClick) {
+ plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory());
+ plugin.sortInventory(e.getInventory());
+ plugin.organizer.updateInventoryView(e.getInventory());
+ } else if(e.isRightClick() && setting.rightClick) {
+ plugin.organizer.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(),e.getInventory());
+ }
+ }
+
}
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java
index 958c0e3..093f2b4 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java
@@ -50,6 +50,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
+import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
import de.jeffclan.utils.Utils;
public class JeffChestSortPlugin extends JavaPlugin {
@@ -59,11 +60,10 @@ public class JeffChestSortPlugin extends JavaPlugin {
JeffChestSortOrganizer organizer;
JeffChestSortUpdateChecker updateChecker;
JeffChestSortListener listener;
- JeffChestSortAdditionalHotkeyListener additionalHotkeys;
JeffChestSortSettingsGUI settingsGUI;
String sortingMethod;
ArrayList disabledWorlds;
- int currentConfigVersion = 27;
+ int currentConfigVersion = 28;
boolean usingMatchingConfig = true;
protected boolean debug = false;
boolean verbose = true;
@@ -71,6 +71,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
public boolean hookCrackShot = false;
public boolean hookInventoryPages = false;
+ public boolean hookMinepacks = false;
private static long updateCheckInterval = 4*60*60; // in seconds. We check on startup and every 4 hours
@@ -169,6 +170,7 @@ public class JeffChestSortPlugin extends JavaPlugin {
getConfig().addDefault("hook-crackshot", true);
getConfig().addDefault("hook-crackshot-prefix", "crackshot_weapon");
getConfig().addDefault("hook-inventorypages", true);
+ getConfig().addDefault("hook-minepacks", true);
getConfig().addDefault("verbose", true); // Prints some information in onEnable()
}
@@ -227,6 +229,11 @@ public class JeffChestSortPlugin extends JavaPlugin {
hookInventoryPages=true;
}
}
+ if(getConfig().getBoolean("hook-minepacks")) {
+ if(Bukkit.getPluginManager().getPlugin("Minepacks") instanceof MinepacksPlugin) {
+ hookMinepacks=true;
+ }
+ }
debug = getConfig().getBoolean("debug");
@@ -254,14 +261,12 @@ public class JeffChestSortPlugin extends JavaPlugin {
// the Organizer to sort inventories when a player closes a chest, shulkerbox or
// barrel inventory
listener = new JeffChestSortListener(this);
- additionalHotkeys = new JeffChestSortAdditionalHotkeyListener(this);
// The sorting method will determine how stuff is sorted
sortingMethod = getConfig().getString("sorting-method");
// Register the events for our Listener
getServer().getPluginManager().registerEvents(listener, this);
- getServer().getPluginManager().registerEvents(additionalHotkeys, this);
// Register events for the GUI interaction
getServer().getPluginManager().registerEvents(settingsGUI, this);
diff --git a/src/main/java/de/jeffclan/hooks/MinepacksHook.java b/src/main/java/de/jeffclan/hooks/MinepacksHook.java
new file mode 100644
index 0000000..4c31a32
--- /dev/null
+++ b/src/main/java/de/jeffclan/hooks/MinepacksHook.java
@@ -0,0 +1,47 @@
+package de.jeffclan.hooks;
+
+import org.bukkit.Bukkit;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.plugin.Plugin;
+
+import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin;
+import de.jeffclan.JeffChestSort.JeffChestSortPlugin;
+
+public class MinepacksHook {
+
+ JeffChestSortPlugin plugin;
+ MinepacksPlugin minepacks = null;
+
+ public MinepacksHook(JeffChestSortPlugin plugin) {
+ this.plugin = plugin;
+ Plugin bukkitPlugin = Bukkit.getPluginManager().getPlugin("Minepacks");
+ if(plugin.hookMinepacks && bukkitPlugin instanceof MinepacksPlugin) {
+ // Do something if Minepacks is not available
+ minepacks = (MinepacksPlugin) bukkitPlugin;
+ }
+ }
+
+ public boolean isMinepacksBackpack(Inventory inv) {
+
+ if(minepacks == null) return false;
+
+ if( inv.getHolder() == null) return false;
+
+ if( inv.getHolder().getClass().getName().equalsIgnoreCase("at.pcgamingfreaks.MinepacksStandalone.Bukkit.Backpack")) {
+ return true;
+ }
+
+ return false;
+
+ //System.out.println(inv.getHolder().getClass().getName());
+
+ /*if(inv.getHolder() instanceof Backpack) {
+ return true;
+ }
+
+ if(minepacks.getBackpackCachedOnly(p).getInventory() == inv) {
+ return true;
+ }*/
+ }
+
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 70458ce..b4d3fee 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -144,22 +144,43 @@ disabled-worlds:
# installed. ChestSort will automatically check if the plugins
# are installed.
-##### CrackShot #####
+##### CrackShot ##### -> https://www.spigotmc.org/resources/crackshot-guns.48301/
# When CrackShot is installed, all CrackShot weapons will be
# grouped together and sorted by their name
hook-crackshot: true
+
# You can define a custom name that will be used as prefix
# for all CrackShot weapon names.
# E.g. when you set this to "crackshot_weapon", an AK-47
# will be called "crackshot_weapon_AK-47"
hook-crackshot-prefix: "crackshot_weapon"
-##### InventoryPages #####
+##### InventoryPages ##### -> https://www.spigotmc.org/resources/inventorypages.32432/
# When InventoryPages is installed, ChestSort will not sort
# the "Next Page" and "Prev Page" buttons. You should not
# disable this behaviour unless you know what you are doing!
hook-inventorypages: true
+##### Minepacks ##### -> https://www.spigotmc.org/resources/minepacks-backpack-plugin-mc-1-7-1-15.19286/
+# When Minepacks is installed, ChestSort can detect your
+# backpacks and sort them like a regular chest. Please note
+# that the left-click and right-click hotkey will not work
+# with a Minepack backpack to avoid the possibility of
+# putting a backpack inside of itself.
+hook-minepacks: true
+
+##### Other backpack plugins #####
+# ChestSort is able to detect backpacks from most backpack
+# plugins like ShulkerPacks or Better Shulker Boxes.
+# This detection is always enabled, you cannot turn it off.
+
+##### Other GUI plugins #####
+# ChestSort tries to detect if an inventory belongs to a
+# 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
+
##########################
##### Sorting Method #####
##########################
@@ -526,4 +547,4 @@ debug: false
# Please DO NOT change the following line manually!
# It is used by the automatic config updater.
-config-version: 27
+config-version: 28
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 89a20e3..9cc5f5f 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,6 @@
main: de.jeffclan.JeffChestSort.JeffChestSortPlugin
name: ChestSort
-version: 8.5
+version: 8.6
api-version: 1.13
description: Allows automatic chest sorting
author: mfnalex
@@ -8,7 +8,7 @@ website: https://www.chestsort.de
prefix: ChestSort
database: false
loadbefore: [InvUnload]
-softdepend: [CrackShot, InventoryPages]
+softdepend: [CrackShot, InventoryPages,Minepacks]
commands:
chestsort:
description: Toggle automatic chest sorting.