From 7c02e0e37ca40e8fe6af0bef4d00aff5255d8d42 Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Mon, 13 Aug 2018 10:11:10 -0400 Subject: [PATCH] Fixes dupe --- .../com/songoda/epichoppers/api/hopper/Hopper.java | 2 ++ .../epichoppers/api/hopper/HopperManager.java | 3 +++ .../epichoppers/events/InventoryListeners.java | 13 +++++++++++-- .../com/songoda/epichoppers/hopper/EHopper.java | 11 +++++++++++ .../songoda/epichoppers/hopper/EHopperManager.java | 12 ++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java index 2f0187f..77a7ac2 100644 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java +++ b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java @@ -21,6 +21,8 @@ public interface Hopper { UUID getLastPlayer(); + void setLastPlayer(UUID uuid); + boolean isWalkOnTeleport(); void setWalkOnTeleport(boolean walkOnTeleport); diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/HopperManager.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/HopperManager.java index 74b12d8..7c4e3e0 100644 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/HopperManager.java +++ b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/HopperManager.java @@ -2,6 +2,7 @@ package com.songoda.epichoppers.api.hopper; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.entity.Player; import java.util.Map; @@ -18,4 +19,6 @@ public interface HopperManager { boolean isHopper(Location location); Map getHoppers(); + + Hopper getHopperFromPlayer(Player player); } diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/events/InventoryListeners.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/events/InventoryListeners.java index bcccafe..1ba21d1 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/events/InventoryListeners.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/events/InventoryListeners.java @@ -208,10 +208,19 @@ public class InventoryListeners implements Listener { @EventHandler public void onClose(InventoryCloseEvent event) { try { - PlayerData playerData = instance.getPlayerDataManager().getPlayerData((Player)event.getPlayer()); + Player player = (Player)event.getPlayer(); + PlayerData playerData = instance.getPlayerDataManager().getPlayerData(player); + if (playerData.getInMenu() != MenuType.NOT_IN) { + Hopper hopper = instance.getHopperManager().getHopperFromPlayer(player); + hopper.setLastPlayer(null); + } + if (playerData.getInMenu() == MenuType.FILTER) { + Hopper hopper = instance.getHopperManager().getHopperFromPlayer(player); + ((EHopper)hopper).compile(player); + } playerData.setInMenu(MenuType.NOT_IN); if (playerData.getSyncType() == SyncType.FILTERED) { - ((EHopper)playerData.getLastHopper()).compile((Player)event.getPlayer()); + ((EHopper)playerData.getLastHopper()).compile(player); } } catch (Exception e) { Debugger.runReport(e); diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java index 109c525..df5febb 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java @@ -53,6 +53,10 @@ public class EHopper implements Hopper { EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance(); if (!player.hasPermission("epichoppers.overview")) return; + if (lastPlayer != null) { + Bukkit.getPlayer(lastPlayer).closeInventory(); + } + instance.getPlayerDataManager().getPlayerData(player).setLastHopper(this); com.songoda.epichoppers.api.hopper.Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel() + 1) : null; @@ -176,6 +180,7 @@ public class EHopper implements Hopper { player.openInventory(i); instance.getPlayerDataManager().getPlayerData(player).setInMenu(MenuType.OVERVIEW); + lastPlayer = player.getUniqueId(); } catch (Exception e) { Debugger.runReport(e); } @@ -302,6 +307,7 @@ public class EHopper implements Hopper { player.openInventory(i); instance.getPlayerDataManager().getPlayerData(player).setInMenu(MenuType.FILTER); + lastPlayer = player.getUniqueId(); } catch (Exception e) { Debugger.runReport(e); } @@ -490,6 +496,11 @@ public class EHopper implements Hopper { return lastPlayer; } + @Override + public void setLastPlayer(UUID uuid) { + lastPlayer = uuid; + } + @Override public boolean isWalkOnTeleport() { return walkOnTeleport; diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java index 0b63a05..88d6cfc 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java +++ b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java @@ -4,8 +4,10 @@ import com.songoda.epichoppers.EpicHoppersPlugin; import com.songoda.epichoppers.api.hopper.Filter; import com.songoda.epichoppers.api.hopper.Hopper; import com.songoda.epichoppers.api.hopper.HopperManager; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.entity.Player; import java.util.Collections; import java.util.HashMap; @@ -48,6 +50,16 @@ public class EHopperManager implements HopperManager { return Collections.unmodifiableMap(registeredHoppers); } + @Override + public Hopper getHopperFromPlayer(Player player) { + for (Hopper hopper : registeredHoppers.values()) { + if (hopper.getLastPlayer() == player.getUniqueId()) { + return hopper; + } + } + return null; + } + private Location roundLocation(Location location) { location = location.clone(); location.setX(location.getBlockX());