1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Extra protection for GUI item glitching into inventory

This commit is contained in:
Zrips 2018-03-14 15:40:24 +02:00
parent 1405b5f149
commit 4588ba0892
3 changed files with 22 additions and 17 deletions

View File

@ -5,6 +5,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -24,10 +25,10 @@ import com.gamingmesh.jobs.container.JobsPlayer;
public class GuiManager { public class GuiManager {
public HashMap<String, GuiInfoList> GuiList = new HashMap<String, GuiInfoList>(); public HashMap<UUID, GuiInfoList> GuiList = new HashMap<UUID, GuiInfoList>();
public void CloseInventories() { public void CloseInventories() {
for (Entry<String, GuiInfoList> one : GuiList.entrySet()) { for (Entry<UUID, GuiInfoList> one : GuiList.entrySet()) {
Player player = Bukkit.getPlayer(one.getKey()); Player player = Bukkit.getPlayer(one.getKey());
if (player != null) { if (player != null) {
player.closeInventory(); 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) { public Job getJobBySlot(Player player, int slot) {
GuiInfoList info = GuiList.get(player.getName()); GuiInfoList info = GuiList.get(player.getUniqueId());
List<Job> JobsList = info.getJobList(); List<Job> JobsList = info.getJobList();
int i = 0; int i = 0;
int pos = Jobs.getGCManager().getJobsGUIStartPosition() - 1; int pos = Jobs.getGCManager().getJobsGUIStartPosition() - 1;
@ -74,12 +79,13 @@ public class GuiManager {
GuiInfoList guiInfo = new GuiInfoList(player.getName()); GuiInfoList guiInfo = new GuiInfoList(player.getName());
guiInfo.setJobList(JobsList); guiInfo.setJobList(JobsList);
Inventory topinv = player.getOpenInventory().getTopInventory(); // Inventory topinv = player.getOpenInventory().getTopInventory();
if (topinv != null && !GuiList.containsKey(player.getName())) { // if (topinv != null && !GuiList.containsKey(player.getName())) {
if (!this.isInGui(player))
player.closeInventory(); player.closeInventory();
} // }
GuiList.put(player.getName(), guiInfo); GuiList.put(player.getUniqueId(), guiInfo);
int GuiSize = Jobs.getGCManager().getJobsGUIRows() * 9; int GuiSize = Jobs.getGCManager().getJobsGUIRows() * 9;
@ -295,7 +301,7 @@ public class GuiManager {
GuiInfoList guiInfo = new GuiInfoList(player.getName()); GuiInfoList guiInfo = new GuiInfoList(player.getName());
guiInfo.setJobInfo(true); guiInfo.setJobInfo(true);
guiInfo.setbackButton(backButton); guiInfo.setbackButton(backButton);
GuiList.put(player.getName(), guiInfo); GuiList.put(player.getUniqueId(), guiInfo);
ItemStack filler = Jobs.getGCManager().guiFiller; ItemStack filler = Jobs.getGCManager().guiFiller;

View File

@ -35,11 +35,12 @@ public class browse implements Cmd {
inv = Jobs.getGUIManager().CreateJobsGUI((Player) sender); inv = Jobs.getGUIManager().CreateJobsGUI((Player) sender);
} catch (Exception e) { } catch (Exception e) {
((Player) sender).closeInventory(); ((Player) sender).closeInventory();
Jobs.getGUIManager().GuiList.remove(((Player) sender).getName()); Jobs.getGUIManager().GuiList.remove(((Player) sender).getUniqueId());
return true; return true;
} }
if (inv == null) if (inv == null)
return true; return true;
if (Jobs.getGUIManager().isInGui((Player) sender))
((Player) sender).openInventory(inv); ((Player) sender).openInventory(inv);
return true; return true;
} }
@ -199,8 +200,8 @@ public class browse implements Cmd {
if (inv == null) if (inv == null)
return true; return true;
if (Jobs.getGUIManager().isInGui((Player) sender))
((Player) sender).openInventory(inv); ((Player) sender).openInventory(inv);
} }
if (Jobs.getGCManager().JobsGUIShowChatBrowse) { if (Jobs.getGCManager().JobsGUIShowChatBrowse) {

View File

@ -215,9 +215,7 @@ public class JobsListener implements Listener {
if (Jobs.getGUIManager().GuiList.isEmpty()) if (Jobs.getGUIManager().GuiList.isEmpty())
return; return;
Player player = (Player) event.getPlayer(); Player player = (Player) event.getPlayer();
if (Jobs.getGUIManager().GuiList.containsKey(player.getName())) { Jobs.getGUIManager().GuiList.remove(player.getUniqueId());
Jobs.getGUIManager().GuiList.remove(player.getName());
}
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
@ -228,12 +226,12 @@ public class JobsListener implements Listener {
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
if (!Jobs.getGUIManager().GuiList.containsKey(player.getName())) if (!Jobs.getGUIManager().GuiList.containsKey(player.getUniqueId()))
return; return;
event.setCancelled(true); event.setCancelled(true);
GuiInfoList joblist = Jobs.getGUIManager().GuiList.get(player.getName()); GuiInfoList joblist = Jobs.getGUIManager().GuiList.get(player.getUniqueId());
int slot = event.getRawSlot(); int slot = event.getRawSlot();