diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java index 3d36e858..481b4659 100644 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -24,10 +25,10 @@ import com.gamingmesh.jobs.container.JobsPlayer; public class GuiManager { - public HashMap GuiList = new HashMap(); + public HashMap GuiList = new HashMap(); public void CloseInventories() { - for (Entry one : GuiList.entrySet()) { + for (Entry one : GuiList.entrySet()) { Player player = Bukkit.getPlayer(one.getKey()); if (player != null) { player.closeInventory(); @@ -35,8 +36,12 @@ public class GuiManager { } } + public boolean isInGui(Player player) { + return GuiList.containsKey(player.getUniqueId()); + } + public Job getJobBySlot(Player player, int slot) { - GuiInfoList info = GuiList.get(player.getName()); + GuiInfoList info = GuiList.get(player.getUniqueId()); List JobsList = info.getJobList(); int i = 0; int pos = Jobs.getGCManager().getJobsGUIStartPosition() - 1; @@ -74,12 +79,13 @@ public class GuiManager { GuiInfoList guiInfo = new GuiInfoList(player.getName()); guiInfo.setJobList(JobsList); - Inventory topinv = player.getOpenInventory().getTopInventory(); - if (topinv != null && !GuiList.containsKey(player.getName())) { +// Inventory topinv = player.getOpenInventory().getTopInventory(); +// if (topinv != null && !GuiList.containsKey(player.getName())) { + if (!this.isInGui(player)) player.closeInventory(); - } +// } - GuiList.put(player.getName(), guiInfo); + GuiList.put(player.getUniqueId(), guiInfo); int GuiSize = Jobs.getGCManager().getJobsGUIRows() * 9; @@ -295,7 +301,7 @@ public class GuiManager { GuiInfoList guiInfo = new GuiInfoList(player.getName()); guiInfo.setJobInfo(true); guiInfo.setbackButton(backButton); - GuiList.put(player.getName(), guiInfo); + GuiList.put(player.getUniqueId(), guiInfo); ItemStack filler = Jobs.getGCManager().guiFiller; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java index 00ca3196..cd11a2d7 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java @@ -35,12 +35,13 @@ public class browse implements Cmd { inv = Jobs.getGUIManager().CreateJobsGUI((Player) sender); } catch (Exception e) { ((Player) sender).closeInventory(); - Jobs.getGUIManager().GuiList.remove(((Player) sender).getName()); + Jobs.getGUIManager().GuiList.remove(((Player) sender).getUniqueId()); return true; } if (inv == null) return true; - ((Player) sender).openInventory(inv); + if (Jobs.getGUIManager().isInGui((Player) sender)) + ((Player) sender).openInventory(inv); return true; } @@ -199,8 +200,8 @@ public class browse implements Cmd { if (inv == null) return true; - ((Player) sender).openInventory(inv); - + if (Jobs.getGUIManager().isInGui((Player) sender)) + ((Player) sender).openInventory(inv); } if (Jobs.getGCManager().JobsGUIShowChatBrowse) { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 2cb2777f..a6110c05 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -215,9 +215,7 @@ public class JobsListener implements Listener { if (Jobs.getGUIManager().GuiList.isEmpty()) return; Player player = (Player) event.getPlayer(); - if (Jobs.getGUIManager().GuiList.containsKey(player.getName())) { - Jobs.getGUIManager().GuiList.remove(player.getName()); - } + Jobs.getGUIManager().GuiList.remove(player.getUniqueId()); } @EventHandler(priority = EventPriority.LOWEST) @@ -228,12 +226,12 @@ public class JobsListener implements Listener { Player player = (Player) event.getWhoClicked(); - if (!Jobs.getGUIManager().GuiList.containsKey(player.getName())) + if (!Jobs.getGUIManager().GuiList.containsKey(player.getUniqueId())) return; event.setCancelled(true); - GuiInfoList joblist = Jobs.getGUIManager().GuiList.get(player.getName()); + GuiInfoList joblist = Jobs.getGUIManager().GuiList.get(player.getUniqueId()); int slot = event.getRawSlot();