From 5d019fa08b22f53a1517bd84c71533b612c06ffb Mon Sep 17 00:00:00 2001 From: lMartin3 Date: Sun, 2 Apr 2023 11:53:47 -0300 Subject: [PATCH] fixes #55 --- build.gradle | 2 +- .../listeners/InventoryCloseListener.java | 19 ++++++++++++++++--- src/main/resources/plugin.yml | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 18b6457..182fafb 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'dev.martinl' -version '4.1.0' +version '4.1.1' tasks.withType(JavaCompile) { options.encoding = 'UTF-8' diff --git a/src/main/java/dev/martinl/bsbrewritten/listeners/InventoryCloseListener.java b/src/main/java/dev/martinl/bsbrewritten/listeners/InventoryCloseListener.java index 926d3de..7a448a0 100644 --- a/src/main/java/dev/martinl/bsbrewritten/listeners/InventoryCloseListener.java +++ b/src/main/java/dev/martinl/bsbrewritten/listeners/InventoryCloseListener.java @@ -4,6 +4,7 @@ import dev.martinl.bsbrewritten.manager.ShulkerOpenData; import dev.martinl.bsbrewritten.util.MaterialUtil; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -11,6 +12,7 @@ import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.*; import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.inventory.Inventory; @@ -168,14 +170,25 @@ public void onClick(InventoryClickEvent e) { * */ @EventHandler public void onBlockPlace(BlockPlaceEvent e){ - Player player = e.getPlayer(); + cancelIfPlayerHasShulkerOpen(e.getPlayer(), e); + } + + + /* + * This should prevent players from + * */ + @EventHandler + public void onItemFrameInteract(PlayerInteractEntityEvent e){ + cancelIfPlayerHasShulkerOpen(e.getPlayer(), e); + } + + private void cancelIfPlayerHasShulkerOpen(Player player, Cancellable cancellable) { if (player.getOpenInventory().getType() != InventoryType.SHULKER_BOX) return; //check if the open inventory is one from a shulker box if (player.getOpenInventory().getTopInventory().getLocation() != null) return; //check if the shulker is a block if (!instance.getShulkerManager().doesPlayerHaveShulkerOpen(player.getUniqueId())) return; //check if the inventory belongs to BSB - e.setCancelled(true); + cancellable.setCancelled(true); } - } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e261bec..da1a8f2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: 'BetterShulkerBoxes' -version: 4.1.0 +version: 4.1.1 main: dev.martinl.bsbrewritten.BSBRewritten author: 'Rektb (lMartin3#1975)' api-version: '1.13'