diff --git a/CHANGELOG.md b/CHANGELOG.md index a569958..72012d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 12.0.2 +- Replaced PlayerInteractEvent with ChestSortLeftClickHotkeyEvent (fixes problems with other plugins opening GUIs on PlayerInteractEvent) + +## 12.0.1 +- Fixed mistake in gui.yml: The default head for the "enabled rightclick" hotkey was set to show the "disabled" head + - Important: When upgrading from 12.0.0, change the "*base64-disabled" to "*base64-enabled" in your "rightclick-enabled" part in your gui.yml (should be line 207 if you havent changed anything) + ## 12.0.0 - GUI is now 100% customizable! - Supports Custom Model Data to create vanilla-looking GUIs diff --git a/pom.xml b/pom.xml index d11b643..64480cd 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ ChestSort https://www.chestsort.de Allows automatic chest sorting! - 12.0.0 + 12.0.2 jar diff --git a/src/main/java/de/jeff_media/chestsort/events/ChestSortLeftClickHotkeyEvent.java b/src/main/java/de/jeff_media/chestsort/events/ChestSortLeftClickHotkeyEvent.java new file mode 100644 index 0000000..43c5b39 --- /dev/null +++ b/src/main/java/de/jeff_media/chestsort/events/ChestSortLeftClickHotkeyEvent.java @@ -0,0 +1,21 @@ +package de.jeff_media.chestsort.events; + +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ChestSortLeftClickHotkeyEvent extends PlayerInteractEvent { + public ChestSortLeftClickHotkeyEvent(@NotNull Player who, @NotNull Action action, @Nullable ItemStack item, @Nullable Block clickedBlock, @NotNull BlockFace clickedFace) { + super(who, action, item, clickedBlock, clickedFace); + } + + public ChestSortLeftClickHotkeyEvent(@NotNull Player who, @NotNull Action action, @Nullable ItemStack item, @Nullable Block clickedBlock, @NotNull BlockFace clickedFace, @Nullable EquipmentSlot hand) { + super(who, action, item, clickedBlock, clickedFace, hand); + } +} 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 6183d83..7bcf1b4 100644 --- a/src/main/java/de/jeff_media/chestsort/listeners/Listener.java +++ b/src/main/java/de/jeff_media/chestsort/listeners/Listener.java @@ -3,6 +3,7 @@ package de.jeff_media.chestsort.listeners; import de.jeff_media.chestsort.api.ChestSortEvent; import de.jeff_media.chestsort.config.Messages; import de.jeff_media.chestsort.enums.Hotkey; +import de.jeff_media.chestsort.events.ChestSortLeftClickHotkeyEvent; import de.jeff_media.chestsort.handlers.Logger; import de.jeff_media.chestsort.ChestSortPlugin; import de.jeff_media.chestsort.api.*; @@ -10,6 +11,7 @@ import de.jeff_media.chestsort.data.PlayerSetting; import de.jeff_media.chestsort.hooks.*; import de.jeff_media.chestsort.utils.LlamaUtils; import de.jeff_media.jefflib.ProtectionUtils; +import de.jeff_media.jefflib.data.ShadowPlayer; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -18,6 +20,7 @@ import org.bukkit.Material; import org.bukkit.block.*; import org.bukkit.entity.ChestedHorse; import org.bukkit.entity.Player; +import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; @@ -44,6 +47,8 @@ public class Listener implements org.bukkit.event.Listener { final GoldenCratesHook goldenCratesHook; final AdvancedChestsHook advancedChestsHook; + private static Event ignoredEvent; + public Listener(ChestSortPlugin plugin) { this.plugin = plugin; this.minepacksHook = new MinepacksHook(plugin); @@ -54,6 +59,9 @@ public class Listener implements org.bukkit.event.Listener { @EventHandler public void onLeftClickChest(PlayerInteractEvent event) { + if(event instanceof ChestSortLeftClickHotkeyEvent) { + return; + } // checking in lower case for lazy admins if (plugin.getDisabledWorlds().contains(event.getPlayer().getWorld().getName().toLowerCase())) { return; @@ -69,14 +77,24 @@ public class Listener implements org.bukkit.event.Listener { if(CrateReloadedHook.isCrate(clickedBlock)) { return; } - if (!ProtectionUtils.canInteract(event.getPlayer(), clickedBlock, plugin.getConfig().getBoolean("mute-protection-plugins"))) { - //System.out.println("ChestSort: cannot interact!"); - return; - } plugin.registerPlayerIfNeeded(event.getPlayer()); PlayerSetting playerSetting = plugin.getPlayerSetting(event.getPlayer()); if(!playerSetting.leftClickOutside) return; + + if(plugin.getConfig().getBoolean("mute-protection-plugins")) { + if (!ProtectionUtils.canInteract(event.getPlayer(), clickedBlock, plugin.getConfig().getBoolean("mute-protection-plugins"))) { + //System.out.println("ChestSort: cannot interact!"); + return; + } + } else { + ChestSortLeftClickHotkeyEvent testEvent = new ChestSortLeftClickHotkeyEvent(event.getPlayer(), Action.RIGHT_CLICK_BLOCK, event.getPlayer().getInventory().getItemInMainHand(), clickedBlock, BlockFace.UP, EquipmentSlot.HAND); + Bukkit.getPluginManager().callEvent(testEvent); + if(testEvent.isCancelled() || testEvent.useInteractedBlock() == Event.Result.DENY) { + return; + } + } + Container containerState = (Container) clickedBlock.getState(); Inventory inventory = containerState.getInventory(); if(!advancedChestsHook.handleAChestSortingIfPresent(clickedBlock.getLocation())) { diff --git a/src/main/resources/gui.yml b/src/main/resources/gui.yml index 10fd6e1..08c47b1 100644 --- a/src/main/resources/gui.yml +++ b/src/main/resources/gui.yml @@ -204,7 +204,7 @@ items: rightclick-enabled: display-name: &rightclick-name "<#2e86c1>Empty Chest<#/85c1e9>" material: PLAYER_HEAD - base64: *base64-disabled + base64: *base64-enabled lore: - *lore-enabled - &rightclick-lore-1 "<#d5dbdb>Take matching items from a chest by"