Merge pull request #164 from DeadSilenceIV/master

AdvancedChests hook was updated and it now supports outside hotkeys.
This commit is contained in:
mfnalex 2023-01-04 01:23:44 +01:00 committed by GitHub
commit d63d9865da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 11 deletions

View File

@ -269,7 +269,7 @@
<dependency> <dependency>
<groupId>com.github.DeadSilenceIV</groupId> <groupId>com.github.DeadSilenceIV</groupId>
<artifactId>AdvancedChestsAPI</artifactId> <artifactId>AdvancedChestsAPI</artifactId>
<version>2.9-BETA</version> <version>3.1-BETA</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -61,7 +61,7 @@ public class AdvancedChestsHook {
try { try {
AdvancedChest<?, ?> chest = AdvancedChestsAPI.getChestManager().getAdvancedChest(location); AdvancedChest<?, ?> chest = AdvancedChestsAPI.getChestManager().getAdvancedChest(location);
if (chest != null) { if (chest != null) {
for (ChestPage<?> page : chest.getPages()) { for (ChestPage<?> page : chest.getPages().values()) {
Inventory inventory = page.getBukkitInventory(); Inventory inventory = page.getBukkitInventory();
plugin.getOrganizer().sortInventory(inventory, 0, inventory.getSize() - 10); plugin.getOrganizer().sortInventory(inventory, 0, inventory.getSize() - 10);
} }

View File

@ -645,8 +645,14 @@ public class ChestSortListener implements org.bukkit.event.Listener {
if (e.getCursor() != null && e.getCursor().getType() != null && e.getCursor().getType() != Material.AIR) { if (e.getCursor() != null && e.getCursor().getType() != null && e.getCursor().getType() != Material.AIR) {
return; return;
} }
boolean isAdvancedChest = advancedChestsHook.isAnAdvancedChest(e.getClickedInventory())
|| advancedChestsHook.isAnAdvancedChest(e.getInventory());
// Possible fix for #57 // Possible fix for #57
if (e.getInventory().getHolder() == null && !e.getView().getTopInventory().equals(p.getEnderChest())) { if (e.getInventory().getHolder() == null
&& !e.getView().getTopInventory().equals(p.getEnderChest())
&& !isAdvancedChest) {
return; return;
} }
if (e.getInventory().getHolder() == p && e.getInventory() != p.getInventory()) { if (e.getInventory().getHolder() == p && e.getInventory() != p.getInventory()) {
@ -685,12 +691,6 @@ public class ChestSortListener 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())
@ -722,7 +722,10 @@ public class ChestSortListener implements org.bukkit.event.Listener {
chestSortEvent.setLocation(e.getWhoClicked().getLocation()); chestSortEvent.setLocation(e.getWhoClicked().getLocation());
chestSortEvent.setSortableMaps(new HashMap<>()); chestSortEvent.setSortableMaps(new HashMap<>());
for (ItemStack item : e.getInventory().getContents()) { ItemStack[] contents = e.getInventory().getContents();
int contentsLength = (!isAdvancedChest) ? contents.length : contents.length-9;
for (int i = 0; i < contentsLength; i++) {
ItemStack item = contents[i];
chestSortEvent.getSortableMaps().put(item, plugin.getOrganizer().getSortableMap(item)); chestSortEvent.getSortableMaps().put(item, plugin.getOrganizer().getSortableMap(item));
} }
@ -737,7 +740,11 @@ public class ChestSortListener implements org.bukkit.event.Listener {
== PlayerSetting.DoubleClickType.LEFT_CLICK) { == PlayerSetting.DoubleClickType.LEFT_CLICK) {
// Left double click: put everything into destination // Left double click: put everything into destination
plugin.getOrganizer().stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), false, chestSortEvent); plugin.getOrganizer().stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), false, chestSortEvent);
plugin.getOrganizer().sortInventory(e.getInventory()); if(isAdvancedChest){
plugin.getOrganizer().sortInventory(e.getInventory(),0,e.getInventory().getSize()-10);
}else{
plugin.getOrganizer().sortInventory(e.getInventory());
}
} else { } else {
// Left single click: put only matching items into destination // Left single click: put only matching items into destination
plugin.getOrganizer().stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), true, chestSortEvent); plugin.getOrganizer().stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), true, chestSortEvent);