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

GUI info button

This commit is contained in:
Zrips 2022-11-15 14:47:15 +02:00
parent f1537befde
commit 31fc886b2c
2 changed files with 396 additions and 364 deletions

View File

@ -21,6 +21,7 @@ import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import net.Zrips.CMILib.CMILib;
import net.Zrips.CMILib.Container.CMICommands;
import net.Zrips.CMILib.GUI.CMIGui;
import net.Zrips.CMILib.GUI.CMIGuiButton;
import net.Zrips.CMILib.GUI.GUIManager.GUIClickType;
@ -32,474 +33,493 @@ public class GuiManager {
private Jobs plugin;
public GuiManager(Jobs plugin) {
this.plugin = plugin;
this.plugin = plugin;
}
public void openJobsBrowseGUI(final Player player) {
List<Job> jobsList = new ArrayList<>();
List<Job> jobsList = new ArrayList<>();
for (Job job : Jobs.getJobs()) {
if (Jobs.getGCManager().getHideJobsWithoutPermission() && !Jobs.getCommandManager().hasJobPermission(player, job))
continue;
for (Job job : Jobs.getJobs()) {
if (Jobs.getGCManager().getHideJobsWithoutPermission() && !Jobs.getCommandManager().hasJobPermission(player, job))
continue;
jobsList.add(job);
}
jobsList.add(job);
}
int jobsListSize = jobsList.size();
int jobsListSize = jobsList.size();
CMIGui gui = new CMIGui(player);
gui.setTitle(Jobs.getLanguage().getMessage("command.info.gui.pickjob"));
CMIGui gui = new CMIGui(player);
gui.setTitle(Jobs.getLanguage().getMessage("command.info.gui.pickjob"));
int guiSize = Jobs.getGCManager().getJobsGUIRows() * 9,
neededSlots = jobsListSize + ((jobsListSize / Jobs.getGCManager().getJobsGUIGroupAmount())
* Jobs.getGCManager().getJobsGUISkipAmount()) + Jobs.getGCManager().getJobsGUIStartPosition(),
neededRows = (int) Math.ceil(neededSlots / 9D);
int guiSize = Jobs.getGCManager().getJobsGUIRows() * 9,
neededSlots = jobsListSize + ((jobsListSize / Jobs.getGCManager().getJobsGUIGroupAmount())
* Jobs.getGCManager().getJobsGUISkipAmount()) + Jobs.getGCManager().getJobsGUIStartPosition(),
neededRows = (int) Math.ceil(neededSlots / 9D);
// Resizing GUI in case we have more jobs then we could fit in current setup
guiSize = Jobs.getGCManager().getJobsGUIRows() > neededRows ? guiSize : neededRows * 9;
// Resizing GUI in case we have more jobs then we could fit in current setup
guiSize = Jobs.getGCManager().getJobsGUIRows() > neededRows ? guiSize : neededRows * 9;
// Lets avoid oversized GUI
if (guiSize > 54) {
guiSize = 54;
}
// Lets avoid oversized GUI
if (guiSize > 54) {
guiSize = 54;
}
gui.setInvSize(guiSize);
gui.setInvSize(guiSize);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
int i = 0;
int pos = Jobs.getGCManager().getJobsGUIStartPosition() - 1;
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 = jobsListSize > 28 ? jobsListSize <= 42 ? 0 : -1 : pos;
// Changing start position to 0 in case we have more jobs then we can fit in current setup
pos = jobsListSize > 28 ? jobsListSize <= 42 ? 0 : -1 : pos;
int group = 0;
main: for (int z = 0; z < jobsListSize; z++) {
group++;
int group = 0;
main: for (int z = 0; z < jobsListSize; z++) {
group++;
if (group > Jobs.getGCManager().getJobsGUIGroupAmount()) {
group = 1;
if (group > Jobs.getGCManager().getJobsGUIGroupAmount()) {
group = 1;
// Only add skip if we can fit all of them in max sized Gui
if (jobsListSize <= 42) {
pos += Jobs.getGCManager().getJobsGUISkipAmount();
}
}
// Only add skip if we can fit all of them in max sized Gui
if (jobsListSize <= 42) {
pos += Jobs.getGCManager().getJobsGUISkipAmount();
}
}
pos++;
pos++;
if (i >= jobsListSize)
break main;
if (i >= jobsListSize)
break main;
Job job = jobsList.get(i);
List<String> lore = new ArrayList<>();
Job job = jobsList.get(i);
List<String> lore = new ArrayList<>();
for (JobProgression onePJob : jPlayer.progression) {
if (onePJob.getJob().getName().equalsIgnoreCase(job.getName())) {
lore.add(Jobs.getLanguage().getMessage("command.info.gui.working"));
break;
}
}
for (JobProgression onePJob : jPlayer.progression) {
if (onePJob.getJob().getName().equalsIgnoreCase(job.getName())) {
lore.add(Jobs.getLanguage().getMessage("command.info.gui.working"));
break;
}
}
int maxlevel = job.getMaxLevel(jPlayer);
if (maxlevel > 0)
lore.add(Jobs.getLanguage().getMessage("command.info.gui.max") + maxlevel);
int maxlevel = job.getMaxLevel(jPlayer);
if (maxlevel > 0)
lore.add(Jobs.getLanguage().getMessage("command.info.gui.max") + maxlevel);
if (Jobs.getGCManager().ShowTotalWorkers)
lore.add(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", job.getTotalPlayers()));
if (Jobs.getGCManager().ShowTotalWorkers)
lore.add(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", job.getTotalPlayers()));
if (Jobs.getGCManager().useDynamicPayment && Jobs.getGCManager().ShowPenaltyBonus) {
double bonus = job.getBonus();
if (Jobs.getGCManager().useDynamicPayment && Jobs.getGCManager().ShowPenaltyBonus) {
double bonus = job.getBonus();
if (bonus < 0)
lore.add(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", (int) (bonus * 100) * -1));
else
lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (bonus * 100)));
}
if (bonus < 0)
lore.add(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", (int) (bonus * 100) * -1));
else
lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (bonus * 100)));
}
if (job.getDescription().isEmpty()) {
lore.addAll(job.getFullDescription());
} else
lore.addAll(Arrays.asList(job.getDescription().split("/n|\\n")));
if (job.getDescription().isEmpty()) {
lore.addAll(job.getFullDescription());
} else
lore.addAll(Arrays.asList(job.getDescription().split("/n|\\n")));
if (job.getMaxSlots() != null) {
int usedSlots = Jobs.getUsedSlots(job);
lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - usedSlots) > 0 ? (job.getMaxSlots() - usedSlots) : 0));
}
if (job.getMaxSlots() != null) {
int usedSlots = Jobs.getUsedSlots(job);
lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - usedSlots) > 0 ? (job.getMaxSlots() - usedSlots) : 0));
}
if (Jobs.getGCManager().ShowActionNames) {
lore.add("");
lore.add(Jobs.getLanguage().getMessage("command.info.gui.actions"));
if (Jobs.getGCManager().ShowActionNames) {
lore.add("");
lore.add(Jobs.getLanguage().getMessage("command.info.gui.actions"));
for (ActionType actionType : ActionType.values()) {
List<JobInfo> info = job.getJobInfo(actionType);
for (ActionType actionType : ActionType.values()) {
List<JobInfo> info = job.getJobInfo(actionType);
if (info != null && !info.isEmpty()) {
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
}
}
}
if (info != null && !info.isEmpty()) {
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
}
}
}
lore.add("");
lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftClick"));
if (jPlayer.isInJob(job)) {
if (Version.isCurrentEqualOrHigher(Version.v1_18_R1))
lore.add(Jobs.getLanguage().getMessage("command.info.gui.qClick"));
else
lore.add(Jobs.getLanguage().getMessage("command.info.gui.middleClick"));
}
lore.add(Jobs.getLanguage().getMessage("command.info.gui.rightClick"));
lore.add("");
lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftClick"));
if (jPlayer.isInJob(job)) {
if (Version.isCurrentEqualOrHigher(Version.v1_18_R1))
lore.add(Jobs.getLanguage().getMessage("command.info.gui.qClick"));
else
lore.add(Jobs.getLanguage().getMessage("command.info.gui.middleClick"));
}
lore.add(Jobs.getLanguage().getMessage("command.info.gui.rightClick"));
ItemStack guiItem = job.getGuiItem();
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
ItemStack guiItem = job.getGuiItem();
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
if (Jobs.getGCManager().hideItemAttributes) {
meta.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES, org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS);
}
if (Jobs.getGCManager().hideItemAttributes) {
meta.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES, org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS);
}
guiItem.setItemMeta(meta);
guiItem.setItemMeta(meta);
gui.addButton(new CMIGuiButton(job.getGuiSlot() >= 0 ? job.getGuiSlot() : pos, guiItem) {
gui.addButton(new CMIGuiButton(job.getGuiSlot() >= 0 ? job.getGuiSlot() : pos, guiItem) {
@Override
public void click(GUIClickType type) {
switch (type) {
case Left:
case LeftShift:
if (Jobs.getGCManager().JobsGUISwitcheButtons) {
if (!Jobs.getGCManager().DisableJoiningJobThroughGui) {
Jobs.getCommandManager().onCommand(player, null, "jobs", new String[] { "join", job.getName() });
} else {
player.sendMessage(Jobs.getLanguage().getMessage("command.info.gui.cantJoin"));
}
openJobsBrowseGUI(player);
} else {
openJobsBrowseGUI(player, job);
}
break;
case MiddleMouse:
case Q:
Jobs.getCommandManager().onCommand(player, null, "jobs", new String[] { "leave", job.getName() });
openJobsBrowseGUI(player);
break;
case Right:
case RightShift:
if (Jobs.getGCManager().JobsGUISwitcheButtons) {
openJobsBrowseGUI(player, job);
} else {
if (!Jobs.getGCManager().DisableJoiningJobThroughGui) {
Jobs.getCommandManager().onCommand(player, null, "jobs", new String[] { "join", job.getName() });
} else {
player.sendMessage(Jobs.getLanguage().getMessage("command.info.gui.cantJoin"));
}
openJobsBrowseGUI(player);
}
break;
default:
break;
}
}
});
i++;
}
@Override
public void click(GUIClickType type) {
switch (type) {
case Left:
case LeftShift:
if (Jobs.getGCManager().JobsGUISwitcheButtons) {
if (!Jobs.getGCManager().DisableJoiningJobThroughGui) {
Jobs.getCommandManager().onCommand(player, null, "jobs", new String[] { "join", job.getName() });
} else {
player.sendMessage(Jobs.getLanguage().getMessage("command.info.gui.cantJoin"));
}
openJobsBrowseGUI(player);
} else {
openJobsBrowseGUI(player, job);
}
break;
case MiddleMouse:
case Q:
Jobs.getCommandManager().onCommand(player, null, "jobs", new String[] { "leave", job.getName() });
openJobsBrowseGUI(player);
break;
case Right:
case RightShift:
if (Jobs.getGCManager().JobsGUISwitcheButtons) {
openJobsBrowseGUI(player, job);
} else {
if (!Jobs.getGCManager().DisableJoiningJobThroughGui) {
Jobs.getCommandManager().onCommand(player, null, "jobs", new String[] { "join", job.getName() });
} else {
player.sendMessage(Jobs.getLanguage().getMessage("command.info.gui.cantJoin"));
}
openJobsBrowseGUI(player);
}
break;
default:
break;
}
}
});
i++;
}
gui.fillEmptyButtons();
gui.open();
ItemStack next = Jobs.getGCManager().guiInfoButton;
ItemMeta meta = next.getItemMeta();
meta.setDisplayName(LC.info_nextPageHover.getLocale());
next.setItemMeta(meta);
gui.addButton(new CMIGuiButton(Jobs.getGCManager().InfoButtonSlot - 1, next) {
@Override
public void click(GUIClickType type) {
for (String one : Jobs.getGCManager().InfoButtonCommands) {
if (one.equalsIgnoreCase("closeinv!")) {
player.closeInventory();
continue;
}
CMICommands.performCommand(Bukkit.getConsoleSender(), one.replace("[playerName]", player.getName()));
}
}
});
gui.fillEmptyButtons();
gui.open();
}
public void openJobsBrowseGUI(Player player, Job job) {
openJobsBrowseGUI(player, job, false);
openJobsBrowseGUI(player, job, false);
}
public void openJobsBrowseGUI(Player player, Job job, boolean fromCommand) {
Inventory tempInv = Bukkit.createInventory(player, 54, "");
Inventory tempInv = Bukkit.createInventory(player, 54, "");
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job);
JobProgression prog = jPlayer.getJobProgression(job);
ItemStack guiItem = job.getGuiItem();
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job);
JobProgression prog = jPlayer.getJobProgression(job);
ItemStack guiItem = job.getGuiItem();
int level = prog != null ? prog.getLevel() : 1,
numjobs = jPlayer.progression.size(),
nextButton = Jobs.getGCManager().getJobsGUINextButton(),
backButton = Jobs.getGCManager().getJobsGUIBackButton();
int level = prog != null ? prog.getLevel() : 1;
int numjobs = jPlayer.progression.size();
int nextButton = Jobs.getGCManager().getJobsGUINextButton();
int backButton = Jobs.getGCManager().getJobsGUIBackButton();
final List<ActionType> jobsRemained = new ArrayList<>();
final List<ActionType> jobsRemained = new ArrayList<>();
int i = 0;
for (ActionType actionType : ActionType.values()) {
List<JobInfo> info = job.getJobInfo(actionType);
if (info == null || info.isEmpty())
continue;
int i = 0;
for (ActionType actionType : ActionType.values()) {
List<JobInfo> info = job.getJobInfo(actionType);
if (info == null || info.isEmpty())
continue;
List<String> lore = new ArrayList<>();
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
List<String> lore = new ArrayList<>();
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
int y = 1;
for (int z = 0; z < info.size(); z++) {
if (i > 53) {
break;
}
int y = 1;
for (int z = 0; z < info.size(); z++) {
if (i > 53) {
break;
}
JobInfo jInfo = info.get(z);
if (jInfo == null) {
continue;
}
JobInfo jInfo = info.get(z);
if (jInfo == null) {
continue;
}
double income = jInfo.getIncome(level, numjobs, jPlayer.maxJobsEquation);
income = boost.getFinalAmount(CurrencyType.MONEY, income);
String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString();
double income = jInfo.getIncome(level, numjobs, jPlayer.maxJobsEquation);
income = boost.getFinalAmount(CurrencyType.MONEY, income);
String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString();
double xp = jInfo.getExperience(level, numjobs, jPlayer.maxJobsEquation);
xp = boost.getFinalAmount(CurrencyType.EXP, xp);
String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString();
double xp = jInfo.getExperience(level, numjobs, jPlayer.maxJobsEquation);
xp = boost.getFinalAmount(CurrencyType.EXP, xp);
String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString();
double points = jInfo.getPoints(level, numjobs, jPlayer.maxJobsEquation);
points = boost.getFinalAmount(CurrencyType.POINTS, points);
String pointsColor = points >= 0 ? "" : ChatColor.RED.toString();
double points = jInfo.getPoints(level, numjobs, jPlayer.maxJobsEquation);
points = boost.getFinalAmount(CurrencyType.POINTS, points);
String pointsColor = points >= 0 ? "" : ChatColor.RED.toString();
if (income == 0D && points == 0D && xp == 0D)
continue;
if (income == 0D && points == 0D && xp == 0D)
continue;
String itemName = jInfo.getRealisticName();
String val = "";
String itemName = jInfo.getRealisticName();
String val = "";
if (income != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.money", "%money%", incomeColor
+ String.format(Jobs.getGCManager().getDecimalPlacesMoney(), income));
if (income != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.money", "%money%", incomeColor
+ String.format(Jobs.getGCManager().getDecimalPlacesMoney(), income));
if (points != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.points", "%points%", pointsColor
+ String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points));
if (points != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.points", "%points%", pointsColor
+ String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points));
if (xp != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.exp", "%exp%", xpColor
+ String.format(Jobs.getGCManager().getDecimalPlacesExp(), xp));
if (xp != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.exp", "%exp%", xpColor
+ String.format(Jobs.getGCManager().getDecimalPlacesExp(), xp));
lore.add(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", itemName) + val);
lore.add(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", itemName) + val);
if (y >= 10) {
y = 1;
if (y >= 10) {
y = 1;
if (z == info.size() - 1)
continue;
if (z == info.size() - 1)
continue;
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
guiItem = job.getGuiItem();
lore = new ArrayList<>();
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
i++;
}
guiItem = job.getGuiItem();
lore = new ArrayList<>();
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
i++;
}
y++;
}
y++;
}
if (i > 53) {
jobsRemained.add(actionType);
continue;
}
if (i > 53) {
jobsRemained.add(actionType);
continue;
}
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
i++;
}
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
i++;
}
int guiSize = CMILib.getInstance().getGUIManager().isOpenedGui(player) && CMILib.getInstance().getGUIManager().getGui(player) != null ? CMILib.getInstance().getGUIManager().getGui(player)
.getInvSize().getFields() : Jobs.getGCManager().getJobsGUIRows() * 9;
int guiSize = CMILib.getInstance().getGUIManager().isOpenedGui(player) && CMILib.getInstance().getGUIManager().getGui(player) != null ? CMILib.getInstance().getGUIManager().getGui(player)
.getInvSize().getFields() : Jobs.getGCManager().getJobsGUIRows() * 9;
CMIGui gui = new CMIGui(player);
gui.setTitle(Jobs.getLanguage().getMessage("command.info.gui.jobinfo", "[jobname]", job.getName()));
gui.setInvSize(guiSize);
CMIGui gui = new CMIGui(player);
gui.setTitle(Jobs.getLanguage().getMessage("command.info.gui.jobinfo", "[jobname]", job.getName()));
gui.setInvSize(guiSize);
List<ItemStack> items = new ArrayList<>();
for (ItemStack one : tempInv.getContents()) {
if (one != null)
items.add(one);
}
List<ItemStack> items = new ArrayList<>();
for (ItemStack one : tempInv.getContents()) {
if (one != null)
items.add(one);
}
for (int i1 = 0; i1 < items.size(); i1++) {
if (guiSize == i1 + 1 || i1 == backButton)
continue;
for (int i1 = 0; i1 < items.size(); i1++) {
if (guiSize == i1 + 1 || i1 == backButton)
continue;
gui.addButton(new CMIGuiButton(i1, items.get(i1)));
}
gui.addButton(new CMIGuiButton(i1, items.get(i1)));
}
if (!fromCommand) {
ItemStack back = Jobs.getGCManager().guiBackButton;
ItemMeta meta = back.getItemMeta();
if (!fromCommand) {
ItemStack back = Jobs.getGCManager().guiBackButton;
ItemMeta meta = back.getItemMeta();
meta.setDisplayName(LC.info_prevPageHover.getLocale());
back.setItemMeta(meta);
meta.setDisplayName(LC.info_prevPageHover.getLocale());
back.setItemMeta(meta);
gui.addButton(new CMIGuiButton(backButton, back) {
@Override
public void click(GUIClickType type) {
openJobsBrowseGUI(player);
}
});
}
gui.addButton(new CMIGuiButton(backButton, back) {
@Override
public void click(GUIClickType type) {
openJobsBrowseGUI(player);
}
});
}
if (i >= 53 && !jobsRemained.isEmpty()) {
ItemStack next = Jobs.getGCManager().guiNextButton;
ItemMeta meta = next.getItemMeta();
if (i >= 53 && !jobsRemained.isEmpty()) {
ItemStack next = Jobs.getGCManager().guiNextButton;
ItemMeta meta = next.getItemMeta();
meta.setDisplayName(LC.info_nextPageHover.getLocale());
next.setItemMeta(meta);
meta.setDisplayName(LC.info_nextPageHover.getLocale());
next.setItemMeta(meta);
gui.addButton(new CMIGuiButton(nextButton, next) {
@Override
public void click(GUIClickType type) {
openJobsBrowseGUI(player, job, jobsRemained);
}
});
}
gui.addButton(new CMIGuiButton(nextButton, next) {
@Override
public void click(GUIClickType type) {
openJobsBrowseGUI(player, job, jobsRemained);
}
});
}
gui.fillEmptyButtons();
gui.open();
gui.fillEmptyButtons();
gui.open();
}
private void openJobsBrowseGUI(Player player, Job job, List<ActionType> jobsRemained) {
Inventory tempInv = Bukkit.createInventory(player, 54, "");
Inventory tempInv = Bukkit.createInventory(player, 54, "");
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job);
int numjobs = jPlayer.progression.size();
int level = jPlayer.getJobProgression(job) != null ? jPlayer.getJobProgression(job).getLevel() : 1;
int numjobs = jPlayer.progression.size();
int level = jPlayer.getJobProgression(job) != null ? jPlayer.getJobProgression(job).getLevel() : 1;
ItemStack guiItem = job.getGuiItem();
int i = 0;
for (ActionType actionType : jobsRemained) {
List<JobInfo> info = job.getJobInfo(actionType);
if (info == null || info.isEmpty())
continue;
ItemStack guiItem = job.getGuiItem();
int i = 0;
for (ActionType actionType : jobsRemained) {
List<JobInfo> info = job.getJobInfo(actionType);
if (info == null || info.isEmpty())
continue;
List<String> lore = new ArrayList<>();
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
List<String> lore = new ArrayList<>();
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
int y = 1;
for (int z = 0; z < info.size(); z++) {
JobInfo jInfo = info.get(z);
if (jInfo == null) {
continue;
}
int y = 1;
for (int z = 0; z < info.size(); z++) {
JobInfo jInfo = info.get(z);
if (jInfo == null) {
continue;
}
double income = jInfo.getIncome(level, numjobs, jPlayer.maxJobsEquation);
income = boost.getFinalAmount(CurrencyType.MONEY, income);
String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString();
double income = jInfo.getIncome(level, numjobs, jPlayer.maxJobsEquation);
income = boost.getFinalAmount(CurrencyType.MONEY, income);
String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString();
double xp = jInfo.getExperience(level, numjobs, jPlayer.maxJobsEquation);
xp = boost.getFinalAmount(CurrencyType.EXP, xp);
String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString();
double xp = jInfo.getExperience(level, numjobs, jPlayer.maxJobsEquation);
xp = boost.getFinalAmount(CurrencyType.EXP, xp);
String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString();
double points = jInfo.getPoints(level, numjobs, jPlayer.maxJobsEquation);
points = boost.getFinalAmount(CurrencyType.POINTS, points);
String pointsColor = points >= 0 ? "" : ChatColor.RED.toString();
double points = jInfo.getPoints(level, numjobs, jPlayer.maxJobsEquation);
points = boost.getFinalAmount(CurrencyType.POINTS, points);
String pointsColor = points >= 0 ? "" : ChatColor.RED.toString();
if (income == 0D && points == 0D && xp == 0D)
continue;
if (income == 0D && points == 0D && xp == 0D)
continue;
String itemName = jInfo.getRealisticName();
String val = "";
String itemName = jInfo.getRealisticName();
String val = "";
if (income != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.money", "%money%", incomeColor
+ String.format(Jobs.getGCManager().getDecimalPlacesMoney(), income));
if (income != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.money", "%money%", incomeColor
+ String.format(Jobs.getGCManager().getDecimalPlacesMoney(), income));
if (points != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.points", "%points%", pointsColor
+ String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points));
if (points != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.points", "%points%", pointsColor
+ String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points));
if (xp != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.exp", "%exp%", xpColor
+ String.format(Jobs.getGCManager().getDecimalPlacesExp(), xp));
if (xp != 0.0)
val += Jobs.getLanguage().getMessage("command.info.help.exp", "%exp%", xpColor
+ String.format(Jobs.getGCManager().getDecimalPlacesExp(), xp));
lore.add(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", itemName) + val);
lore.add(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", itemName) + val);
if (y >= 10) {
y = 1;
if (y >= 10) {
y = 1;
if (z == info.size() - 1)
continue;
if (z == info.size() - 1)
continue;
if (i >= 54) {
break;
}
if (i >= 54) {
break;
}
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
guiItem = job.getGuiItem();
lore = new ArrayList<>();
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
i++;
}
guiItem = job.getGuiItem();
lore = new ArrayList<>();
lore.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".info"));
i++;
}
y++;
}
y++;
}
if (i >= 54) {
break;
}
if (i >= 54) {
break;
}
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
i++;
}
ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getDisplayName());
meta.setLore(lore);
guiItem.setItemMeta(meta);
tempInv.setItem(i, guiItem.clone());
i++;
}
int guiSize = CMILib.getInstance().getGUIManager().isOpenedGui(player) && CMILib.getInstance().getGUIManager().getGui(player) != null ? CMILib.getInstance().getGUIManager().getGui(player)
.getInvSize().getFields() : Jobs.getGCManager().getJobsGUIRows() * 9;
int backButton = Jobs.getGCManager().getJobsGUIBackButton();
int guiSize = CMILib.getInstance().getGUIManager().isOpenedGui(player) && CMILib.getInstance().getGUIManager().getGui(player) != null ? CMILib.getInstance().getGUIManager().getGui(player)
.getInvSize().getFields() : Jobs.getGCManager().getJobsGUIRows() * 9;
int backButton = Jobs.getGCManager().getJobsGUIBackButton();
CMIGui gui = new CMIGui(player);
gui.setTitle(Jobs.getLanguage().getMessage("command.info.gui.jobinfo", "[jobname]", job.getName()));
CMIGui gui = new CMIGui(player);
gui.setTitle(Jobs.getLanguage().getMessage("command.info.gui.jobinfo", "[jobname]", job.getName()));
gui.setInvSize(guiSize);
gui.setInvSize(guiSize);
List<ItemStack> items = new ArrayList<>();
for (ItemStack one : tempInv.getContents()) {
if (one != null)
items.add(one);
}
List<ItemStack> items = new ArrayList<>();
for (ItemStack one : tempInv.getContents()) {
if (one != null)
items.add(one);
}
for (int i1 = 0; i1 < items.size(); i1++) {
if (guiSize == i1 + 1 || i1 == backButton)
continue;
for (int i1 = 0; i1 < items.size(); i1++) {
if (guiSize == i1 + 1 || i1 == backButton)
continue;
gui.addButton(new CMIGuiButton(i1, items.get(i1)));
}
gui.addButton(new CMIGuiButton(i1, items.get(i1)));
}
ItemStack skull = Jobs.getGCManager().guiBackButton;
ItemMeta skullMeta = skull.getItemMeta();
ItemStack skull = Jobs.getGCManager().guiBackButton;
ItemMeta skullMeta = skull.getItemMeta();
skullMeta.setDisplayName(LC.info_prevPageHover.getLocale());
skull.setItemMeta(skullMeta);
skullMeta.setDisplayName(LC.info_prevPageHover.getLocale());
skull.setItemMeta(skullMeta);
gui.addButton(new CMIGuiButton(backButton, skull) {
@Override
public void click(GUIClickType type) {
openJobsBrowseGUI(player, job);
}
});
gui.addButton(new CMIGuiButton(backButton, skull) {
@Override
public void click(GUIClickType type) {
openJobsBrowseGUI(player, job);
}
});
gui.fillEmptyButtons();
gui.open();
gui.fillEmptyButtons();
gui.open();
}
}

View File

@ -39,10 +39,12 @@ import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.container.CurrencyLimit;
import com.gamingmesh.jobs.container.CurrencyType;
import net.Zrips.CMILib.CMILib;
import net.Zrips.CMILib.Container.CMIArray;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Equations.Parser;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Version.Version;
@ -107,7 +109,9 @@ public class GeneralConfigManager {
LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, payForAbove = false,
payForEachVTradeItem, allowEnchantingBoostedItems, bossBarAsync = false, preventShopItemEnchanting;
public ItemStack guiBackButton, guiNextButton;
public ItemStack guiBackButton, guiNextButton, guiInfoButton;
public int InfoButtonSlot = 9;
public List<String> InfoButtonCommands = new ArrayList<String>();
public Parser DynamicPaymentEquation;
@ -1043,12 +1047,26 @@ public class GeneralConfigManager {
c.addComment("JobsGUI.SkipAmount", "Defines by how many slots we need to skip after group");
JobsGUISkipAmount = c.get("JobsGUI.SkipAmount", 2);
CMIItemStack item = CMILib.getInstance().getItemManager().getItem(c.get("JobsGUI.BackButton.Material", "JACK_O_LANTERN"));
guiBackButton = item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.JACK_O_LANTERN.newItemStack() : item.getItemStack();
item = CMILib.getInstance().getItemManager().getItem(c.get("JobsGUI.NextButton.Material", "ARROW"));
guiNextButton = item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.ARROW.newItemStack() : item.getItemStack();
InfoButtonSlot = c.get("JobsGUI.InfoButton.Slot", 9);
guiInfoButton = item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.ARROW.newItemStack() : item.getItemStack();
item = CMILib.getInstance().getItemManager().getItem(c.get("JobsGUI.InfoButton.Material",
"head:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjcwNWZkOTRhMGM0MzE5MjdmYjRlNjM5YjBmY2ZiNDk3MTdlNDEyMjg1YTAyYjQzOWUwMTEyZGEyMmIyZTJlYyJ9fX0="));
guiInfoButton = item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.ARROW.newItemStack() : item.getItemStack();
c.addComment("JobsGUI.InfoButton.Commands", "closeinv! can be used to close players inventory when you click this icon");
InfoButtonCommands = c.get("JobsGUI.InfoButton.Commands", Arrays.asList("closeinv!"));
c.addComment("Commands.Jobs", "What should happen when performing clean /jobs command", "Options:",
"Default - behaves like before and will open jobs help page with list of commands player can access",
"Browse - will open jobs browse GUI where player can check existing jobs and their actions",
"Last option is to define command you want to perform, use [playerName] variable to replace it with players name who performed it. Multiple commands can be provided too. Commands will be performed from console.");
helpPageBehavior.clear();
if (c.getC().isList("Commands.Jobs")) {
helpPageBehavior.addAll(c.get("Commands.Jobs", Arrays.asList("Default")));
@ -1078,12 +1096,6 @@ public class GeneralConfigManager {
c.addComment("Commands.JobsInfo.open-browse", "Open up the jobs browse action list, when your performed /jobs info command?");
jobsInfoOpensBrowse = c.get("Commands.JobsInfo.open-browse", false);
CMIMaterial tmat = CMIMaterial.get(c.get("JobsGUI.BackButton.Material", "JACK_O_LANTERN"));
guiBackButton = (tmat == CMIMaterial.NONE ? CMIMaterial.JACK_O_LANTERN : tmat).newItemStack();
tmat = CMIMaterial.get(c.get("JobsGUI.NextButton.Material", "ARROW"));
guiNextButton = (tmat == CMIMaterial.NONE ? CMIMaterial.ARROW : tmat).newItemStack();
c.addComment("BlockOwnership.Range", "Set to 0 or lower if you want to disable this. Setting to positive number will mean that player needs to be in this range from owner block to get paid");
blockOwnershipRange = c.get("BlockOwnership.Range", 0);