From 17a6218b2cd63f2bc551e0a5af744183c9a0d503 Mon Sep 17 00:00:00 2001 From: Fernando Pettinelli Date: Mon, 1 Feb 2021 20:49:27 -0300 Subject: [PATCH 1/2] Fixed dupe bug and fixed normal hoppers. --- .../epichoppers/gui/GUIAutoSellFilter.java | 5 ++++- .../songoda/epichoppers/gui/GUICrafting.java | 5 ++++- .../com/songoda/epichoppers/gui/GUIFilter.java | 5 ++++- .../songoda/epichoppers/gui/GUIOverview.java | 10 ++++++++-- .../songoda/epichoppers/gui/GUISmeltable.java | 2 ++ .../com/songoda/epichoppers/hopper/Hopper.java | 17 +++++++++++++++++ .../levels/modules/ModuleAutoCrafting.java | 1 + .../hopper/levels/modules/ModuleAutoSell.java | 1 + .../levels/modules/ModuleAutoSmelter.java | 5 +++-- .../epichoppers/listeners/BlockListeners.java | 2 ++ .../listeners/InteractListeners.java | 5 +++++ 11 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java b/src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java index d299bd9..6465978 100644 --- a/src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java +++ b/src/main/java/com/songoda/epichoppers/gui/GUIAutoSellFilter.java @@ -36,7 +36,10 @@ public class GUIAutoSellFilter extends CustomizableGui { setDefaultItem(null); setAcceptsItems(true); - setOnClose((event) -> compile()); + setOnClose((event) -> { + hopper.setActivePlayer(null); + compile(); + }); Filter filter = hopper.getFilter(); diff --git a/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java b/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java index afb36c3..454649e 100644 --- a/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java +++ b/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java @@ -18,7 +18,10 @@ public class GUICrafting extends CustomizableGui { super(EpicHoppers.getInstance(), "crafting"); setRows(3); setTitle(Methods.formatName(hopper.getLevel().getLevel()) + TextUtils.formatText(" &8-&f Crafting")); - setOnClose((event) -> setItem(module, hopper, player)); + setOnClose((event) -> { + hopper.setActivePlayer(null); + setItem(module, hopper, player); + }); setAcceptsItems(true); ItemStack glass1 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_1.getMaterial()); diff --git a/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java b/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java index 8d1df1f..520ef17 100644 --- a/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java +++ b/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java @@ -37,7 +37,10 @@ public class GUIFilter extends CustomizableGui { setDefaultItem(null); setAcceptsItems(true); - setOnClose((event) -> compile()); + setOnClose((event) -> { + hopper.setActivePlayer(null); + compile(); + }); Filter filter = hopper.getFilter(); diff --git a/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java b/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java index 4dff7bd..80616b5 100644 --- a/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java +++ b/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java @@ -46,7 +46,10 @@ public class GUIOverview extends CustomizableGui { setTitle(Methods.formatName(hopper.getLevel().getLevel())); runTask(); constructGUI(); - this.setOnClose(action -> Bukkit.getScheduler().cancelTask(task)); + this.setOnClose(action -> { + hopper.setActivePlayer(null); + Bukkit.getScheduler().cancelTask(task); + }); } private void constructGUI() { @@ -212,7 +215,10 @@ public class GUIOverview extends CustomizableGui { }); canTeleport = false; } else if (canFilter) { - setButton("filter", slot, filter, (event) -> guiManager.showGUI(player, new GUIFilter(plugin, hopper, player))); + setButton("filter", slot, filter, (event) -> { + hopper.setActivePlayer(player); + guiManager.showGUI(player, new GUIFilter(plugin, hopper, player)); + }); canFilter = false; } else { if (modules.isEmpty()) break; diff --git a/src/main/java/com/songoda/epichoppers/gui/GUISmeltable.java b/src/main/java/com/songoda/epichoppers/gui/GUISmeltable.java index 1b1ac7f..a6363fa 100644 --- a/src/main/java/com/songoda/epichoppers/gui/GUISmeltable.java +++ b/src/main/java/com/songoda/epichoppers/gui/GUISmeltable.java @@ -41,6 +41,8 @@ public class GUISmeltable extends CustomizableGui { this.setOnPage((event) -> showPage()); showPage(); + + this.setOnClose((event) -> hopper.setActivePlayer(null)); } void showPage() { diff --git a/src/main/java/com/songoda/epichoppers/hopper/Hopper.java b/src/main/java/com/songoda/epichoppers/hopper/Hopper.java index ba54533..f4bb22a 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/Hopper.java +++ b/src/main/java/com/songoda/epichoppers/hopper/Hopper.java @@ -44,6 +44,8 @@ public class Hopper { private int syncId = -1; + private Player activePlayer; + private final Map moduleCache = new HashMap<>(); public Hopper(Location location) { @@ -67,9 +69,16 @@ public class Hopper { EpicHoppers instance = EpicHoppers.getInstance(); if (!player.hasPermission("epichoppers.overview")) return; + + setActivePlayer(player); guiManager.showGUI(player, new GUIOverview(instance, this, player)); } + public void forceClose() { + if (activePlayer != null) + activePlayer.closeInventory(); + } + public void upgrade(Player player, CostType type) { EpicHoppers plugin = EpicHoppers.getInstance(); if (!plugin.getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) return; @@ -327,4 +336,12 @@ public class Hopper { public void setId(int id) { this.id = id; } + + public Player getActivePlayer() { + return activePlayer; + } + + public void setActivePlayer(Player activePlayer) { + this.activePlayer = activePlayer; + } } diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java index 049650e..050a8e1 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java @@ -195,6 +195,7 @@ public class ModuleAutoCrafting extends Module { @Override public void runButtonPress(Player player, Hopper hopper, ClickType type) { + hopper.setActivePlayer(player); EpicHoppers.getInstance().getGuiManager().showGUI(player, new GUICrafting(this, hopper, player)); } diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java index 91047fc..7cde2f3 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java @@ -145,6 +145,7 @@ public class ModuleAutoSell extends Module { setNotifying(hopper, !isNotifying(hopper)); } else if (type == ClickType.SHIFT_LEFT || type == ClickType.SHIFT_RIGHT) { // Any shift click opens AutoSell filter configuration GUI + hopper.setActivePlayer(player); EpicHoppers.getInstance().getGuiManager().showGUI(player, new GUIAutoSellFilter(EpicHoppers.getInstance(), hopper)); } } diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSmelter.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSmelter.java index 45d8f58..6ef58fa 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSmelter.java +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSmelter.java @@ -89,9 +89,10 @@ public class ModuleAutoSmelter extends Module { } public void runButtonPress(Player player, Hopper hopper, ClickType type) { - if (type == ClickType.LEFT) + if (type == ClickType.LEFT) { + hopper.setActivePlayer(player); EpicHoppers.getInstance().getGuiManager().showGUI(player, new GUISmeltable(this, plugin, hopper)); - else if (type == ClickType.RIGHT) + } else if (type == ClickType.RIGHT) toggleEnabled(hopper); } diff --git a/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java b/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java index 7f5daa0..bdac91d 100644 --- a/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java +++ b/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java @@ -105,6 +105,8 @@ public class BlockListeners implements Listener { event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), item); } + hopper.forceClose(); + hopper.getFilter().getWhiteList().stream() .filter(m -> m != null) .forEach(m -> event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), m)); diff --git a/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java b/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java index be6325a..1ad7cdc 100644 --- a/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java +++ b/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java @@ -80,8 +80,13 @@ public class InteractListeners implements Listener { return; } + if (!instance.getHopperManager().isHopper(event.getClickedBlock().getLocation())) { + return; + } + PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player); + if (playerData.getSyncType() == null) { if (event.getClickedBlock().getType() == Material.HOPPER) { if (Settings.ALLOW_NORMAL_HOPPERS.getBoolean() && !instance.getHopperManager().isHopper(event.getClickedBlock().getLocation())) From aff7392d0701564014c06de4853f294dac720c55 Mon Sep 17 00:00:00 2001 From: Fernando Pettinelli Date: Mon, 1 Feb 2021 20:50:17 -0300 Subject: [PATCH 2/2] Fixed dupe bug and fixed normal hoppers. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6818052..fa7f95b 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ com.songoda EpicHoppers 4.0.0 - 4.6.17 + 4.6.18 clean install EpicHoppers-${project.version}