mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 05:55:27 +01:00
Lets resize jobs browse GUI if jobs can't fit in current one
This commit is contained in:
parent
12232cb9fa
commit
1d3b6fc73f
@ -1,16 +1,18 @@
|
||||
package com.gamingmesh.jobs.Gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
|
||||
public class GuiInfoList {
|
||||
|
||||
private String name;
|
||||
private List<Job> jobList = new ArrayList<>();
|
||||
private HashMap<Integer, Job> jobList = new HashMap<Integer, Job>();
|
||||
private Boolean jobInfo = false;
|
||||
private int backButton = 27;
|
||||
private Inventory inv = null;
|
||||
|
||||
public GuiInfoList(String name) {
|
||||
this.name = name;
|
||||
@ -28,12 +30,12 @@ public class GuiInfoList {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<Job> getJobList() {
|
||||
public HashMap<Integer, Job> getJobList() {
|
||||
return jobList;
|
||||
}
|
||||
|
||||
public void setJobList(List<Job> jobList) {
|
||||
this.jobList = jobList;
|
||||
public void addJob(int slot, Job job) {
|
||||
this.jobList.put(slot, job);
|
||||
}
|
||||
|
||||
public void setJobInfo(Boolean jobInfo) {
|
||||
@ -43,4 +45,12 @@ public class GuiInfoList {
|
||||
public Boolean isJobInfo() {
|
||||
return jobInfo;
|
||||
}
|
||||
|
||||
public Inventory getInv() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
public void setInv(Inventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
}
|
||||
|
@ -22,15 +22,16 @@ import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobInfo;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.stuff.Debug;
|
||||
|
||||
public class GuiManager {
|
||||
|
||||
public HashMap<UUID, GuiInfoList> GuiList = new HashMap<>();
|
||||
|
||||
public GuiManager() {
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseInventories() {
|
||||
public void CloseInventories() {
|
||||
for (Entry<UUID, GuiInfoList> one : GuiList.entrySet()) {
|
||||
Player player = Bukkit.getPlayer(one.getKey());
|
||||
if (player != null) {
|
||||
@ -45,28 +46,7 @@ public class GuiManager {
|
||||
|
||||
public Job getJobBySlot(Player player, int slot) {
|
||||
GuiInfoList info = GuiList.get(player.getUniqueId());
|
||||
List<Job> JobsList = info.getJobList();
|
||||
int i = 0;
|
||||
int pos = Jobs.getGCManager().getJobsGUIStartPosition() - 1;
|
||||
int group = 0;
|
||||
main: for (int z = 0; z < JobsList.size(); z++) {
|
||||
group++;
|
||||
|
||||
if (group > Jobs.getGCManager().getJobsGUIGroupAmount()) {
|
||||
group = 1;
|
||||
pos += Jobs.getGCManager().getJobsGUISkipAmount();
|
||||
}
|
||||
|
||||
pos++;
|
||||
if (i >= JobsList.size())
|
||||
break main;
|
||||
|
||||
if (pos == slot)
|
||||
return JobsList.get(i);
|
||||
i++;
|
||||
}
|
||||
|
||||
return null;
|
||||
return info.getJobList().get(slot);
|
||||
}
|
||||
|
||||
public Inventory CreateJobsGUI(Player player) {
|
||||
@ -80,13 +60,9 @@ public class GuiManager {
|
||||
}
|
||||
|
||||
GuiInfoList guiInfo = new GuiInfoList(player.getName());
|
||||
guiInfo.setJobList(JobsList);
|
||||
|
||||
// Inventory topinv = player.getOpenInventory().getTopInventory();
|
||||
// if (topinv != null && !GuiList.containsKey(player.getName())) {
|
||||
if (!this.isInGui(player))
|
||||
player.closeInventory();
|
||||
// }
|
||||
|
||||
GuiList.put(player.getUniqueId(), guiInfo);
|
||||
|
||||
@ -100,17 +76,30 @@ public class GuiManager {
|
||||
if (title.length() > 32)
|
||||
title = title.substring(0, 30) + "..";
|
||||
|
||||
// Resizing GUI in case we have more jobs then we could fit in current settup
|
||||
GuiSize = GuiSize - 18 - ((Jobs.getGCManager().getJobsGUIRows() - 2) * 2) < JobsList.size() ? 2 * 9 + ((JobsList.size() % 9) * 9) : GuiSize;
|
||||
|
||||
// Lets avoid oversized GUI
|
||||
GuiSize = GuiSize > 54 ? 54 : GuiSize;
|
||||
|
||||
Inventory GuiInv = Bukkit.createInventory(null, GuiSize, title);
|
||||
|
||||
int i = 0;
|
||||
int pos = Jobs.getGCManager().getJobsGUIStartPosition() - 1;
|
||||
|
||||
// Changing start position to 0 in case we have more jobs then we can fit in current setup
|
||||
pos = JobsList.size() > 28 ? JobsList.size() <= 42 ? 0 : -1 : pos;
|
||||
int group = 0;
|
||||
main: for (int z = 0; z < JobsList.size(); z++) {
|
||||
group++;
|
||||
|
||||
if (group > Jobs.getGCManager().getJobsGUIGroupAmount()) {
|
||||
group = 1;
|
||||
pos += Jobs.getGCManager().getJobsGUISkipAmount();
|
||||
// Only add skip if we can fit all of them in max sized Gui
|
||||
if (JobsList.size() <= 42){
|
||||
pos += Jobs.getGCManager().getJobsGUISkipAmount();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// pos += 2;
|
||||
@ -165,6 +154,7 @@ public class GuiManager {
|
||||
meta.setLore(Lore);
|
||||
GuiItem.setItemMeta(meta);
|
||||
|
||||
guiInfo.addJob(pos, job);
|
||||
GuiInv.setItem(pos, GuiItem);
|
||||
i++;
|
||||
// }
|
||||
@ -180,6 +170,7 @@ public class GuiManager {
|
||||
GuiInv.setItem(y, filler);
|
||||
}
|
||||
}
|
||||
guiInfo.setInv(GuiInv);
|
||||
return GuiInv;
|
||||
}
|
||||
|
||||
@ -276,7 +267,13 @@ public class GuiManager {
|
||||
items.add(one);
|
||||
}
|
||||
|
||||
int GuiSize = Jobs.getGCManager().getJobsGUIRows() * 9;
|
||||
GuiInfoList mainGui = GuiList.get(player.getUniqueId());
|
||||
if (mainGui == null) {
|
||||
CreateJobsGUI(player);
|
||||
mainGui = GuiList.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
int GuiSize = mainGui != null && mainGui.getInv() != null ? mainGui.getInv().getSize() : Jobs.getGCManager().getJobsGUIRows() * 9;
|
||||
int backButton = Jobs.getGCManager().getJobsGUIBackButton();
|
||||
|
||||
String title = Jobs.getLanguage().getMessage("command.info.gui.jobinfo", "[jobname]", job.getName());
|
||||
|
@ -248,14 +248,14 @@ public class JobsListener implements Listener {
|
||||
if (job != null) {
|
||||
Inventory inv = Jobs.getGUIManager().CreateJobsSubGUI(player, job);
|
||||
Inventory top = player.getOpenInventory().getTopInventory();
|
||||
if (top.getSize() == Jobs.getGCManager().getJobsGUIRows() * 9)
|
||||
// if (top.getSize() == Jobs.getGCManager().getJobsGUIRows() * 9)
|
||||
top.setContents(inv.getContents());
|
||||
}
|
||||
} else if (joblist.isJobInfo()) {
|
||||
if (slot == joblist.getbackButton()) {
|
||||
Inventory inv = Jobs.getGUIManager().CreateJobsGUI(player);
|
||||
Inventory top = player.getOpenInventory().getTopInventory();
|
||||
if (top.getSize() == Jobs.getGCManager().getJobsGUIRows() * 9)
|
||||
// if (top.getSize() == Jobs.getGCManager().getJobsGUIRows() * 9)
|
||||
top.setContents(inv.getContents());
|
||||
}
|
||||
} else if (!Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.RIGHT ||
|
||||
|
Loading…
Reference in New Issue
Block a user