mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 04:25:15 +01:00
Extra protection for GUI item glitching into inventory
This commit is contained in:
parent
1405b5f149
commit
4588ba0892
@ -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<String, GuiInfoList> GuiList = new HashMap<String, GuiInfoList>();
|
||||
public HashMap<UUID, GuiInfoList> GuiList = new HashMap<UUID, GuiInfoList>();
|
||||
|
||||
public void CloseInventories() {
|
||||
for (Entry<String, GuiInfoList> one : GuiList.entrySet()) {
|
||||
for (Entry<UUID, GuiInfoList> 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<Job> 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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user