mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2024-12-04 16:44:00 +01:00
AdvancedChests support was added
This commit is contained in:
parent
8e6a0fca4d
commit
d71f505368
7
pom.xml
7
pom.xml
@ -252,6 +252,13 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.DeadSilenceIV</groupId>
|
||||||
|
<artifactId>AdvancedChestsAPI</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
|
@ -76,6 +76,7 @@ public class ChestSortPlugin extends JavaPlugin {
|
|||||||
private boolean hookCrackShot = false;
|
private boolean hookCrackShot = false;
|
||||||
private boolean hookInventoryPages = false;
|
private boolean hookInventoryPages = false;
|
||||||
private boolean hookMinepacks = false;
|
private boolean hookMinepacks = false;
|
||||||
|
private boolean hookAdvancedChests = false;
|
||||||
private PlayerVaultsHook playerVaultsHook;
|
private PlayerVaultsHook playerVaultsHook;
|
||||||
private boolean debug = false;
|
private boolean debug = false;
|
||||||
private ArrayList<String> disabledWorlds;
|
private ArrayList<String> disabledWorlds;
|
||||||
@ -359,6 +360,14 @@ public class ChestSortPlugin extends JavaPlugin {
|
|||||||
this.hookMinepacks = hookMinepacks;
|
this.hookMinepacks = hookMinepacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isHookAdvancedChests() {
|
||||||
|
return hookAdvancedChests;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHookAdvancedChests(boolean hookAdvancedChests) {
|
||||||
|
this.hookAdvancedChests = hookAdvancedChests;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
public boolean isHotkeyGUI() {
|
public boolean isHotkeyGUI() {
|
||||||
// TODO: Remove, it's unused
|
// TODO: Remove, it's unused
|
||||||
@ -429,6 +438,9 @@ public class ChestSortPlugin extends JavaPlugin {
|
|||||||
setHookMinepacks(getConfig().getBoolean("hook-minepacks")
|
setHookMinepacks(getConfig().getBoolean("hook-minepacks")
|
||||||
&& Bukkit.getPluginManager().getPlugin("Minepacks") instanceof MinepacksPlugin);
|
&& Bukkit.getPluginManager().getPlugin("Minepacks") instanceof MinepacksPlugin);
|
||||||
|
|
||||||
|
setHookAdvancedChests(getConfig().getBoolean("hook-advancedchests")
|
||||||
|
&& Bukkit.getPluginManager().getPlugin("AdvancedChests") != null);
|
||||||
|
|
||||||
setGenericHook(new GenericGUIHook(this, getConfig().getBoolean("hook-generic")));
|
setGenericHook(new GenericGUIHook(this, getConfig().getBoolean("hook-generic")));
|
||||||
|
|
||||||
saveDefaultCategories();
|
saveDefaultCategories();
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ public class CrackShotHook {
|
|||||||
|
|
||||||
if(plugin.isHookCrackShot()) {
|
if(plugin.isHookCrackShot()) {
|
||||||
crackShotUtility = new CSUtility();
|
crackShotUtility = new CSUtility();
|
||||||
plugin.getLogger().info("Succesfully hooked into CrackShot");
|
plugin.getLogger().info("Successfully hooked into CrackShot");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public class MinepacksHook {
|
|||||||
Plugin bukkitPlugin = Bukkit.getPluginManager().getPlugin("Minepacks");
|
Plugin bukkitPlugin = Bukkit.getPluginManager().getPlugin("Minepacks");
|
||||||
if(plugin.isHookMinepacks() && bukkitPlugin instanceof MinepacksPlugin) {
|
if(plugin.isHookMinepacks() && bukkitPlugin instanceof MinepacksPlugin) {
|
||||||
minepacks = (MinepacksPlugin) bukkitPlugin;
|
minepacks = (MinepacksPlugin) bukkitPlugin;
|
||||||
plugin.getLogger().info("Succesfully hooked into Minepacks");
|
plugin.getLogger().info("Successfully hooked into Minepacks");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
final HeadDatabaseHook headDatabaseHook;
|
final HeadDatabaseHook headDatabaseHook;
|
||||||
final CrateReloadedHook crateReloadedHook;
|
final CrateReloadedHook crateReloadedHook;
|
||||||
final GoldenCratesHook goldenCratesHook;
|
final GoldenCratesHook goldenCratesHook;
|
||||||
|
final AdvancedChestsHook advancedChestsHook;
|
||||||
|
|
||||||
public Listener(ChestSortPlugin plugin) {
|
public Listener(ChestSortPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -49,6 +50,7 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
this.headDatabaseHook = new HeadDatabaseHook(plugin);
|
this.headDatabaseHook = new HeadDatabaseHook(plugin);
|
||||||
this.crateReloadedHook = new CrateReloadedHook(plugin);
|
this.crateReloadedHook = new CrateReloadedHook(plugin);
|
||||||
this.goldenCratesHook = new GoldenCratesHook(plugin);
|
this.goldenCratesHook = new GoldenCratesHook(plugin);
|
||||||
|
this.advancedChestsHook = new AdvancedChestsHook(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -65,7 +67,9 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
if(!playerSetting.leftClickOutside) return;
|
if(!playerSetting.leftClickOutside) return;
|
||||||
Container containerState = (Container) clickedBlock.getState();
|
Container containerState = (Container) clickedBlock.getState();
|
||||||
Inventory inventory = containerState.getInventory();
|
Inventory inventory = containerState.getInventory();
|
||||||
|
if(!advancedChestsHook.handleAChestSortingIfPresent(clickedBlock.getLocation())) {
|
||||||
plugin.getOrganizer().sortInventory(inventory);
|
plugin.getOrganizer().sortInventory(inventory);
|
||||||
|
}
|
||||||
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(Messages.MSG_CONTAINER_SORTED));
|
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
|
// 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
|
// and then call the Organizer to sort the inventory (if the player has
|
||||||
// the chestsort.use permission and has /chestsort enabled)
|
// the chestsort.use permission and has /chestsort enabled)
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -190,6 +194,7 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
&& !belongsToChestLikeBlock(inventory)
|
&& !belongsToChestLikeBlock(inventory)
|
||||||
&& !plugin.getEnderContainersHook().isEnderchest(inventory)
|
&& !plugin.getEnderContainersHook().isEnderchest(inventory)
|
||||||
&& !LlamaUtils.belongsToLlama(inventory)
|
&& !LlamaUtils.belongsToLlama(inventory)
|
||||||
|
&& !advancedChestsHook.isAnAdvancedChest(inventory)
|
||||||
&& !plugin.getOrganizer().isMarkedAsSortable(inventory)) {
|
&& !plugin.getOrganizer().isMarkedAsSortable(inventory)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -209,9 +214,11 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
return;
|
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
|
// Normal container inventories can be sorted completely
|
||||||
plugin.getOrganizer().sortInventory(event.getInventory());
|
plugin.getOrganizer().sortInventory(event.getInventory());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
@ -243,6 +250,7 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
&& !belongsToChestLikeBlock(inventory)
|
&& !belongsToChestLikeBlock(inventory)
|
||||||
&& !plugin.getEnderContainersHook().isEnderchest(inventory)
|
&& !plugin.getEnderContainersHook().isEnderchest(inventory)
|
||||||
&& !LlamaUtils.belongsToLlama(inventory)
|
&& !LlamaUtils.belongsToLlama(inventory)
|
||||||
|
&& !advancedChestsHook.isAnAdvancedChest(inventory)
|
||||||
&& !plugin.getOrganizer().isMarkedAsSortable(inventory)) {
|
&& !plugin.getOrganizer().isMarkedAsSortable(inventory)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -263,6 +271,9 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
return;
|
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
|
// Normal container inventories can be sorted completely
|
||||||
plugin.getOrganizer().sortInventory(event.getInventory());
|
plugin.getOrganizer().sortInventory(event.getInventory());
|
||||||
|
|
||||||
@ -525,23 +536,28 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
|| LlamaUtils.belongsToLlama(event.getClickedInventory())
|
|| LlamaUtils.belongsToLlama(event.getClickedInventory())
|
||||||
|| minepacksHook.isMinepacksBackpack(event.getClickedInventory())
|
|| minepacksHook.isMinepacksBackpack(event.getClickedInventory())
|
||||||
|| plugin.getPlayerVaultsHook().isPlayerVault(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")) {
|
if (!p.hasPermission("chestsort.use")) {
|
||||||
return;
|
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();
|
ChestedHorse llama = (ChestedHorse) event.getInventory().getHolder();
|
||||||
plugin.getOrganizer().sortInventory(event.getClickedInventory(), 2, LlamaUtils.getLlamaChestSize(llama) + 1);
|
plugin.getOrganizer().sortInventory(event.getClickedInventory(), 2, LlamaUtils.getLlamaChestSize(llama) + 1);
|
||||||
plugin.getOrganizer().updateInventoryView(event);
|
plugin.getOrganizer().updateInventoryView(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getLgr().logSort(p,cause);
|
if(advancedChestsHook.handleAChestSortingIfPresent(event.getInventory())){
|
||||||
|
plugin.getOrganizer().updateInventoryView(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getOrganizer().sortInventory(event.getClickedInventory());
|
plugin.getOrganizer().sortInventory(event.getClickedInventory());
|
||||||
plugin.getOrganizer().updateInventoryView(event);
|
plugin.getOrganizer().updateInventoryView(event);
|
||||||
} else if (holder instanceof Player) {
|
} else if (holder instanceof Player) {
|
||||||
@ -625,6 +641,12 @@ public class Listener implements org.bukkit.event.Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdvancedChests hook
|
||||||
|
if(advancedChestsHook.isAnAdvancedChest(e.getClickedInventory())
|
||||||
|
|| advancedChestsHook.isAnAdvancedChest(e.getInventory())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Detect generic GUIs
|
// Detect generic GUIs
|
||||||
if(!isAPICall(e.getInventory()) && !isAPICall(e.getClickedInventory()) &&
|
if(!isAPICall(e.getInventory()) && !isAPICall(e.getClickedInventory()) &&
|
||||||
(plugin.getGenericHook().isPluginGUI(e.getInventory())
|
(plugin.getGenericHook().isPluginGUI(e.getInventory())
|
||||||
|
@ -284,6 +284,12 @@ hook-headdatabase: true
|
|||||||
# prevent ChestSort from moving Slimefun backpacks until they fixed this.
|
# prevent ChestSort from moving Slimefun backpacks until they fixed this.
|
||||||
dont-move-slimefun-backpacks: false
|
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 #####
|
##### Other backpack plugins #####
|
||||||
# ChestSort is able to detect backpacks from most backpack
|
# ChestSort is able to detect backpacks from most backpack
|
||||||
# plugins like ShulkerPacks or Better Shulker Boxes.
|
# plugins like ShulkerPacks or Better Shulker Boxes.
|
||||||
|
@ -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]
|
softdepend: [CrackShot,InventoryPages,Minepacks,PlaceholderAPI,AdvancedChests]
|
||||||
commands:
|
commands:
|
||||||
sort:
|
sort:
|
||||||
description: Toggle automatic chest sorting or change your hotkey settings
|
description: Toggle automatic chest sorting or change your hotkey settings
|
||||||
|
Loading…
Reference in New Issue
Block a user