mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2024-12-03 08:03:26 +01:00
Merge pull request #133 from DeadSilenceIV/master
AdvancedChests support
This commit is contained in:
commit
da8c215488
7
pom.xml
7
pom.xml
@ -252,6 +252,13 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.DeadSilenceIV</groupId>
|
||||
<artifactId>AdvancedChestsAPI</artifactId>
|
||||
<version>2.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<distributionManagement>
|
||||
|
@ -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<String> 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
|
||||
@ -421,14 +430,17 @@ public class ChestSortPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
setHookCrackShot(getConfig().getBoolean("hook-crackshot")
|
||||
&& Bukkit.getPluginManager().getPlugin("CrackShot") instanceof Plugin);
|
||||
&& Bukkit.getPluginManager().getPlugin("CrackShot") != null);
|
||||
|
||||
setHookInventoryPages(getConfig().getBoolean("hook-inventorypages")
|
||||
&& Bukkit.getPluginManager().getPlugin("InventoryPages") instanceof Plugin);
|
||||
&& Bukkit.getPluginManager().getPlugin("InventoryPages") != null);
|
||||
|
||||
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();
|
||||
|
@ -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()) {
|
||||
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");
|
||||
if(plugin.isHookMinepacks() && bukkitPlugin instanceof MinepacksPlugin) {
|
||||
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 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());
|
||||
|
||||
@ -467,12 +478,9 @@ public class Listener implements org.bukkit.event.Listener {
|
||||
cause = Logger.SortCause.H_MIDDLE;
|
||||
//if(plugin.getConfig().getBoolean("hotkeys.middle-click")) {
|
||||
if (setting.middleClick && p.hasPermission(Hotkey.getPermission(Hotkey.MIDDLE_CLICK))) {
|
||||
if (event.getWhoClicked().getGameMode() != GameMode.CREATIVE) {
|
||||
if (event.getWhoClicked().getGameMode() != GameMode.CREATIVE
|
||||
|| (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR)) {
|
||||
sort = true;
|
||||
} else {
|
||||
if (event.getCurrentItem() != null || (event.getCurrentItem()==null && event.getCurrentItem().getType() != Material.AIR)) {
|
||||
sort = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -528,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) {
|
||||
@ -628,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())
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user