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