8.17.0-SNAPSHOT (fake event)
This commit is contained in:
parent
f0d7c9ed1e
commit
2ede041488
|
@ -1,5 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
## 8.17.0-SNAPSHOT
|
||||
- Rewrote custom GUI detection completely, now using a fake InventoryClickEvent
|
||||
|
||||
## 8.16.1
|
||||
- Allow middle-click hotkey in creative mode when clicked slot is empty
|
||||
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -9,7 +9,7 @@
|
|||
<name>ChestSort</name>
|
||||
<url>https://www.chestsort.de</url>
|
||||
<description>Automatically sorts your chests!</description>
|
||||
<version>8.16.0</version>
|
||||
<version>8.17.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
|
@ -113,7 +113,7 @@
|
|||
<dependency>
|
||||
<groupId>de.jeff_media</groupId>
|
||||
<artifactId>ChestSortAPI</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -4,6 +4,7 @@ import de.jeff_media.ChestSort.hooks.CrateReloadedHook;
|
|||
import de.jeff_media.ChestSort.hooks.HeadDatabaseHook;
|
||||
import de.jeff_media.ChestSort.hooks.MinepacksHook;
|
||||
import de.jeff_media.ChestSort.utils.LlamaUtils;
|
||||
import de.jeff_media.ChestSortAPI.ChestSortCheckForCustomGUIEvent;
|
||||
import de.jeff_media.ChestSortAPI.ChestSortEvent;
|
||||
import de.jeff_media.ChestSortAPI.ISortable;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -310,6 +311,7 @@ public class ChestSortListener implements Listener {
|
|||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onHotkey(InventoryClickEvent event) {
|
||||
if(event instanceof ChestSortCheckForCustomGUIEvent) return;
|
||||
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
|
@ -341,11 +343,8 @@ public class ChestSortListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
// Possible fix for #57
|
||||
if (!isAPICall && (event.getClickedInventory().getHolder() != null
|
||||
&& event.getClickedInventory().getHolder() == p
|
||||
&& event.getClickedInventory() != p.getInventory())) {
|
||||
if(plugin.debug) System.out.println("10");
|
||||
if(plugin.genericHook.isPluginGUIByEvent(event.getView(),event.getSlotType(),event.getSlot(),event.getClick(),event.getAction())) {
|
||||
plugin.debug("Event cancelled because genericHook#isPluginGUIByEvent");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -458,37 +457,35 @@ public class ChestSortListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onAdditionalHotkeys(InventoryClickEvent e) {
|
||||
if(e instanceof ChestSortCheckForCustomGUIEvent) return;
|
||||
|
||||
if (LlamaUtils.belongsToLlama(e.getInventory()) || LlamaUtils.belongsToLlama(e.getClickedInventory())) {
|
||||
plugin.debug("Cancel AdditionalHotkeys: Belongs to Llama");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!plugin.getConfig().getBoolean("allow-additional-hotkeys")) {
|
||||
plugin.debug("Cancel AdditionalHotkeys: allow-additional-hotkeys false");
|
||||
return;
|
||||
}
|
||||
if (!(e.getWhoClicked() instanceof Player)) {
|
||||
plugin.debug("Cancel AdditionalHotkeys: getWhoClicked !instanceof Player");
|
||||
return;
|
||||
}
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
// Only continue if clicked outside of the chest
|
||||
if (e.getClickedInventory() != null) {
|
||||
plugin.debug("Cancel AdditionalHotkeys: getCLickedInventory != null");
|
||||
return;
|
||||
}
|
||||
// Only continue if hand is empty
|
||||
if (e.getCursor() != null && e.getCursor().getType() != null && e.getCursor().getType() != Material.AIR) {
|
||||
plugin.debug("Cancel AdditionalHotkeys: getCursor != null && getCursor.getType!=null || != AIR");
|
||||
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"))
|
||||
&& !(e.getInventory().getHolder() instanceof ISortable)) {
|
||||
if(plugin.genericHook.isPluginGUIByEvent(e.getView(),e.getSlotType(),e.getSlot(),e.getClick(),e.getAction())) {
|
||||
plugin.debug("Event cancelled because genericHook#isPluginGUIByEvent");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
package de.jeff_media.ChestSort.hooks;
|
||||
|
||||
import de.jeff_media.ChestSort.ChestSortPlugin;
|
||||
import de.jeff_media.ChestSortAPI.ChestSortCheckForCustomGUIEvent;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
|
||||
public class GenericGUIHook {
|
||||
|
||||
|
@ -13,6 +19,13 @@ public class GenericGUIHook {
|
|||
this.enabled=enabled;
|
||||
}
|
||||
|
||||
public boolean isPluginGUIByEvent(InventoryView view, InventoryType.SlotType type, int slot, ClickType click, InventoryAction action) {
|
||||
if(slot==-999) slot= 9;
|
||||
ChestSortCheckForCustomGUIEvent event = new ChestSortCheckForCustomGUIEvent(view, type, slot, click, action);
|
||||
main.getServer().getPluginManager().callEvent(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
public boolean isPluginGUI(Inventory inv) {
|
||||
if(!enabled) return false;
|
||||
if(inv.getHolder()!=null && inv.getHolder().getClass().getName().contains("GUI")) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
main: de.jeff_media.ChestSort.ChestSortPlugin
|
||||
name: ChestSort
|
||||
version: 8.16.0
|
||||
version: 8.17.0-SNAPSHOT
|
||||
api-version: "1.13"
|
||||
description: Allows automatic chest sorting
|
||||
author: mfnalex
|
||||
|
|
Loading…
Reference in New Issue