diff --git a/pom.xml b/pom.xml
index e70d08e..5cfc63c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -252,6 +252,13 @@
compile
+
+ com.github.DeadSilenceIV
+ AdvancedChestsAPI
+ 2.2
+ provided
+
+
diff --git a/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java b/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java
index d4b4773..510559c 100644
--- a/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java
+++ b/src/main/java/de/jeff_media/chestsort/ChestSortPlugin.java
@@ -76,6 +76,7 @@ public class ChestSortPlugin extends JavaPlugin {
private boolean hookCrackShot = false;
private boolean hookInventoryPages = false;
private boolean hookMinepacks = false;
+ private boolean hookAdvancedChests = false;
private PlayerVaultsHook playerVaultsHook;
private boolean debug = false;
private ArrayList disabledWorlds;
@@ -359,6 +360,14 @@ public class ChestSortPlugin extends JavaPlugin {
this.hookMinepacks = hookMinepacks;
}
+ public boolean isHookAdvancedChests() {
+ return hookAdvancedChests;
+ }
+
+ public void setHookAdvancedChests(boolean hookAdvancedChests) {
+ this.hookAdvancedChests = hookAdvancedChests;
+ }
+
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isHotkeyGUI() {
// TODO: Remove, it's unused
@@ -429,6 +438,9 @@ public class ChestSortPlugin extends JavaPlugin {
setHookMinepacks(getConfig().getBoolean("hook-minepacks")
&& Bukkit.getPluginManager().getPlugin("Minepacks") instanceof MinepacksPlugin);
+ setHookAdvancedChests(getConfig().getBoolean("hook-advancedchests")
+ && Bukkit.getPluginManager().getPlugin("AdvancedChests") != null);
+
setGenericHook(new GenericGUIHook(this, getConfig().getBoolean("hook-generic")));
saveDefaultCategories();
diff --git a/src/main/java/de/jeff_media/chestsort/hooks/AdvancedChestsHook.java b/src/main/java/de/jeff_media/chestsort/hooks/AdvancedChestsHook.java
new file mode 100644
index 0000000..3e89fcd
--- /dev/null
+++ b/src/main/java/de/jeff_media/chestsort/hooks/AdvancedChestsHook.java
@@ -0,0 +1,54 @@
+package de.jeff_media.chestsort.hooks;
+
+import de.jeff_media.chestsort.ChestSortPlugin;
+import org.bukkit.Location;
+import org.bukkit.inventory.Inventory;
+import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI;
+import us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest;
+import us.lynuxcraft.deadsilenceiv.advancedchests.chest.gui.page.ChestPage;
+
+public class AdvancedChestsHook {
+
+ final ChestSortPlugin plugin;
+
+ public AdvancedChestsHook(ChestSortPlugin plugin) {
+ this.plugin = plugin;
+ if(plugin.isHookAdvancedChests()){
+ double version = Double.parseDouble(plugin.getServer().getPluginManager()
+ .getPlugin("AdvancedChests")
+ .getDescription().getVersion());
+ if(version >= 20.3) {
+ plugin.getLogger().info("Successfully hooked into AdvancedChests");
+ }else plugin.setHookAdvancedChests(false);
+ }
+ }
+
+ public boolean isAnAdvancedChest(Inventory inventory){
+ return plugin.isHookAdvancedChests()
+ && inventory != null
+ && AdvancedChestsAPI.getInventoryManager().getAdvancedChest(inventory) != null;
+ }
+
+ public boolean handleAChestSortingIfPresent(Inventory inventory){
+ if(!plugin.isHookAdvancedChests())return false;
+ AdvancedChest chest = AdvancedChestsAPI.getInventoryManager().getAdvancedChest(inventory);
+ if(chest != null){
+ plugin.getOrganizer().sortInventory(inventory,0,inventory.getSize()-10);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean handleAChestSortingIfPresent(Location location){
+ if(!plugin.isHookAdvancedChests())return false;
+ AdvancedChest chest = AdvancedChestsAPI.getChestManager().getAdvancedChest(location);
+ if(chest != null){
+ for (ChestPage page : chest.getPages()) {
+ Inventory inventory = page.getBukkitInventory();
+ plugin.getOrganizer().sortInventory(inventory,0,inventory.getSize()-10);
+ }
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/de/jeff_media/chestsort/hooks/CrackShotHook.java b/src/main/java/de/jeff_media/chestsort/hooks/CrackShotHook.java
index 0a9bb47..5ddf2aa 100644
--- a/src/main/java/de/jeff_media/chestsort/hooks/CrackShotHook.java
+++ b/src/main/java/de/jeff_media/chestsort/hooks/CrackShotHook.java
@@ -16,7 +16,7 @@ public class CrackShotHook {
if(plugin.isHookCrackShot()) {
crackShotUtility = new CSUtility();
- plugin.getLogger().info("Succesfully hooked into CrackShot");
+ plugin.getLogger().info("Successfully hooked into CrackShot");
}
}
diff --git a/src/main/java/de/jeff_media/chestsort/hooks/MinepacksHook.java b/src/main/java/de/jeff_media/chestsort/hooks/MinepacksHook.java
index 08232a6..3588af3 100644
--- a/src/main/java/de/jeff_media/chestsort/hooks/MinepacksHook.java
+++ b/src/main/java/de/jeff_media/chestsort/hooks/MinepacksHook.java
@@ -20,7 +20,7 @@ public class MinepacksHook {
Plugin bukkitPlugin = Bukkit.getPluginManager().getPlugin("Minepacks");
if(plugin.isHookMinepacks() && bukkitPlugin instanceof MinepacksPlugin) {
minepacks = (MinepacksPlugin) bukkitPlugin;
- plugin.getLogger().info("Succesfully hooked into Minepacks");
+ plugin.getLogger().info("Successfully hooked into Minepacks");
}
}
diff --git a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java b/src/main/java/de/jeff_media/chestsort/listeners/Listener.java
index de3f99a..901d191 100644
--- a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java
+++ b/src/main/java/de/jeff_media/chestsort/listeners/Listener.java
@@ -42,6 +42,7 @@ public class Listener implements org.bukkit.event.Listener {
final HeadDatabaseHook headDatabaseHook;
final CrateReloadedHook crateReloadedHook;
final GoldenCratesHook goldenCratesHook;
+ final AdvancedChestsHook advancedChestsHook;
public Listener(ChestSortPlugin plugin) {
this.plugin = plugin;
@@ -49,6 +50,7 @@ public class Listener implements org.bukkit.event.Listener {
this.headDatabaseHook = new HeadDatabaseHook(plugin);
this.crateReloadedHook = new CrateReloadedHook(plugin);
this.goldenCratesHook = new GoldenCratesHook(plugin);
+ this.advancedChestsHook = new AdvancedChestsHook(plugin);
}
@EventHandler
@@ -65,7 +67,9 @@ public class Listener implements org.bukkit.event.Listener {
if(!playerSetting.leftClickOutside) return;
Container containerState = (Container) clickedBlock.getState();
Inventory inventory = containerState.getInventory();
- plugin.getOrganizer().sortInventory(inventory);
+ if(!advancedChestsHook.handleAChestSortingIfPresent(clickedBlock.getLocation())) {
+ plugin.getOrganizer().sortInventory(inventory);
+ }
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(Messages.MSG_CONTAINER_SORTED));
}
@@ -164,7 +168,7 @@ public class Listener implements org.bukkit.event.Listener {
}
// This event fires when someone closes an inventory
- // We check if the closed inventory belongs to a chest, shulkerbox or barrel,
+ // We check if the closed inventory belongs to a chest, advancedchest, shulkerbox or barrel,
// and then call the Organizer to sort the inventory (if the player has
// the chestsort.use permission and has /chestsort enabled)
@EventHandler
@@ -190,6 +194,7 @@ public class Listener implements org.bukkit.event.Listener {
&& !belongsToChestLikeBlock(inventory)
&& !plugin.getEnderContainersHook().isEnderchest(inventory)
&& !LlamaUtils.belongsToLlama(inventory)
+ && !advancedChestsHook.isAnAdvancedChest(inventory)
&& !plugin.getOrganizer().isMarkedAsSortable(inventory)) {
return;
}
@@ -209,9 +214,11 @@ public class Listener implements org.bukkit.event.Listener {
return;
}
+ // If the involved inventory belongs to an AdvancedChest, sort all the pages.
+ if(advancedChestsHook.handleAChestSortingIfPresent(event.getInventory()))return;
+
// Normal container inventories can be sorted completely
plugin.getOrganizer().sortInventory(event.getInventory());
-
}
@EventHandler(priority = EventPriority.MONITOR)
@@ -243,6 +250,7 @@ public class Listener implements org.bukkit.event.Listener {
&& !belongsToChestLikeBlock(inventory)
&& !plugin.getEnderContainersHook().isEnderchest(inventory)
&& !LlamaUtils.belongsToLlama(inventory)
+ && !advancedChestsHook.isAnAdvancedChest(inventory)
&& !plugin.getOrganizer().isMarkedAsSortable(inventory)) {
return;
}
@@ -263,6 +271,9 @@ public class Listener implements org.bukkit.event.Listener {
return;
}
+ // If the involved inventory belongs to an AdvancedChest, sort all the pages.
+ if(advancedChestsHook.handleAChestSortingIfPresent(event.getInventory()))return;
+
// Normal container inventories can be sorted completely
plugin.getOrganizer().sortInventory(event.getInventory());
@@ -525,23 +536,28 @@ public class Listener implements org.bukkit.event.Listener {
|| LlamaUtils.belongsToLlama(event.getClickedInventory())
|| minepacksHook.isMinepacksBackpack(event.getClickedInventory())
|| plugin.getPlayerVaultsHook().isPlayerVault(event.getClickedInventory())
- || plugin.getEnderContainersHook().isEnderchest(event.getClickedInventory())) {
+ || plugin.getEnderContainersHook().isEnderchest(event.getClickedInventory())
+ || advancedChestsHook.isAnAdvancedChest(event.getClickedInventory())) {
if (!p.hasPermission("chestsort.use")) {
return;
}
- if (LlamaUtils.belongsToLlama(event.getClickedInventory())) {
+ plugin.getLgr().logSort(p,cause);
- plugin.getLgr().logSort(p,cause);
+ if (LlamaUtils.belongsToLlama(event.getClickedInventory())) {
ChestedHorse llama = (ChestedHorse) event.getInventory().getHolder();
plugin.getOrganizer().sortInventory(event.getClickedInventory(), 2, LlamaUtils.getLlamaChestSize(llama) + 1);
plugin.getOrganizer().updateInventoryView(event);
return;
}
- plugin.getLgr().logSort(p,cause);
+ if(advancedChestsHook.handleAChestSortingIfPresent(event.getInventory())){
+ plugin.getOrganizer().updateInventoryView(event);
+ return;
+ }
+
plugin.getOrganizer().sortInventory(event.getClickedInventory());
plugin.getOrganizer().updateInventoryView(event);
} else if (holder instanceof Player) {
@@ -625,6 +641,12 @@ public class Listener implements org.bukkit.event.Listener {
return;
}
+ // AdvancedChests hook
+ if(advancedChestsHook.isAnAdvancedChest(e.getClickedInventory())
+ || advancedChestsHook.isAnAdvancedChest(e.getInventory())){
+ return;
+ }
+
// Detect generic GUIs
if(!isAPICall(e.getInventory()) && !isAPICall(e.getClickedInventory()) &&
(plugin.getGenericHook().isPluginGUI(e.getInventory())
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 10a7a69..7bf1596 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -284,6 +284,12 @@ hook-headdatabase: true
# prevent ChestSort from moving Slimefun backpacks until they fixed this.
dont-move-slimefun-backpacks: false
+##### AdvancedChests #####
+# When AdvancedChests is installed, ChestSort will not sort
+# the buttons from the bottom row. You should not
+# disable this behaviour unless you know what you are doing!
+hook-advancedchests: true
+
##### Other backpack plugins #####
# ChestSort is able to detect backpacks from most backpack
# plugins like ShulkerPacks or Better Shulker Boxes.
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index bf6d727..020339c 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -10,7 +10,7 @@ website: ${project.url}
prefix: ${spigot.prefix}
database: false
loadbefore: [InvUnload]
-softdepend: [CrackShot,InventoryPages,Minepacks,PlaceholderAPI]
+softdepend: [CrackShot,InventoryPages,Minepacks,PlaceholderAPI,AdvancedChests]
commands:
sort:
description: Toggle automatic chest sorting or change your hotkey settings