1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 23:13:48 +01:00
Jobs/com/gamingmesh/jobs/Gui/GuiManager.java

278 lines
8.2 KiB
Java
Raw Normal View History

2015-11-27 15:34:19 +01:00
package com.gamingmesh.jobs.Gui;
import java.util.ArrayList;
2015-12-10 14:13:57 +01:00
import java.util.Arrays;
2015-11-27 15:34:19 +01:00
import java.util.HashMap;
import java.util.List;
2015-12-17 13:04:34 +01:00
import java.util.Map.Entry;
2015-11-27 15:34:19 +01:00
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BoostType;
2015-11-27 15:34:19 +01:00
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
2016-06-09 17:35:24 +02:00
import com.gamingmesh.jobs.stuff.Perm;
2015-11-27 15:34:19 +01:00
2016-03-30 15:42:36 +02:00
public class GuiManager {
2015-11-27 15:34:19 +01:00
2016-03-30 15:42:36 +02:00
public HashMap<String, GuiInfoList> GuiList = new HashMap<String, GuiInfoList>();
2015-11-27 15:34:19 +01:00
2016-03-30 15:42:36 +02:00
public void CloseInventories() {
2015-12-17 13:04:34 +01:00
for (Entry<String, GuiInfoList> one : GuiList.entrySet()) {
Player player = Bukkit.getPlayer(one.getKey());
if (player != null) {
player.closeInventory();
}
}
}
2016-03-30 15:42:36 +02:00
public Inventory CreateJobsGUI(Player player) {
2015-11-27 15:34:19 +01:00
ArrayList<Job> JobsList = new ArrayList<Job>();
for (Job job : Jobs.getJobs()) {
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().getHideJobsWithoutPermission())
if (!Jobs.getCommandManager().hasJobPermission(player, job))
2015-11-27 15:34:19 +01:00
continue;
JobsList.add(job);
}
GuiInfoList guiInfo = new GuiInfoList(player.getName());
guiInfo.setJobList(JobsList);
2016-03-30 15:42:36 +02:00
Inventory topinv = player.getOpenInventory().getTopInventory();
if (topinv != null)
player.closeInventory();
2015-11-27 15:34:19 +01:00
GuiList.put(player.getName(), guiInfo);
int GuiSize = 9;
if (JobsList.size() > 9)
GuiSize = 18;
if (JobsList.size() > 18)
GuiSize = 27;
if (JobsList.size() > 27)
GuiSize = 36;
if (JobsList.size() > 36)
GuiSize = 45;
if (JobsList.size() > 45)
GuiSize = 54;
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
List<JobProgression> pJobs = JPlayer.getJobProgression();
2016-03-30 15:42:36 +02:00
String title = Jobs.getLanguage().getMessage("command.info.gui.pickjob");
2015-12-17 13:04:34 +01:00
if (title.length() > 32)
title = title.substring(0, 30) + "..";
Inventory GuiInv = Bukkit.createInventory(null, GuiSize, title);
2015-11-27 15:34:19 +01:00
for (int i = 0; i < JobsList.size(); i++) {
Job job = JobsList.get(i);
ArrayList<String> Lore = new ArrayList<String>();
for (JobProgression onePJob : pJobs) {
if (onePJob.getJob().getName().equalsIgnoreCase(job.getName()))
2016-03-30 15:42:36 +02:00
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.working"));
2015-11-27 15:34:19 +01:00
}
int maxlevel = 0;
2016-06-09 17:35:24 +02:00
if (Perm.hasPermission(player, "jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
2015-11-27 15:34:19 +01:00
maxlevel = job.getVipMaxLevel();
else
maxlevel = job.getMaxLevel();
if (maxlevel > 0)
2016-03-30 15:42:36 +02:00
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.max") + maxlevel);
2015-11-27 15:34:19 +01:00
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().ShowTotalWorkers)
Lore.add(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", job.getTotalPlayers()));
2015-11-27 15:34:19 +01:00
2016-03-30 15:42:36 +02:00
if (Jobs.getGCManager().useDynamicPayment && Jobs.getGCManager().ShowPenaltyBonus)
2015-11-27 15:34:19 +01:00
if (job.getBonus() < 0)
2016-03-30 15:42:36 +02:00
Lore.add(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", (int) (job.getBonus() * 100) / 100.0 * -1));
2015-11-27 15:34:19 +01:00
else
2016-03-30 15:42:36 +02:00
Lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (job.getBonus() * 100) / 100.0));
2015-11-27 15:34:19 +01:00
2015-12-10 14:13:57 +01:00
Lore.addAll(Arrays.asList(job.getDescription().split("/n")));
2015-11-27 15:34:19 +01:00
if (job.getMaxSlots() != null)
2016-03-30 15:42:36 +02:00
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - Jobs.getUsedSlots(job)) > 0 ? (job.getMaxSlots() - Jobs
.getUsedSlots(
job)) : 0));
2015-11-27 15:34:19 +01:00
2016-03-30 15:42:36 +02:00
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.actions"));
2015-11-27 15:34:19 +01:00
for (ActionType actionType : ActionType.values()) {
List<JobInfo> info = job.getJobInfo(actionType);
if (info != null && !info.isEmpty()) {
2016-03-30 15:42:36 +02:00
Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase()
2015-12-17 13:04:34 +01:00
+ ".info")));
2015-11-27 15:34:19 +01:00
}
}
Lore.add("");
2016-03-30 15:42:36 +02:00
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftClick"));
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.rightClick"));
2015-11-27 15:34:19 +01:00
ItemStack GuiItem = job.getGuiItem();
ItemMeta meta = GuiItem.getItemMeta();
meta.setDisplayName(job.getName());
meta.setLore(Lore);
GuiItem.setItemMeta(meta);
GuiInv.setItem(i, GuiItem);
}
return GuiInv;
}
2016-03-30 15:42:36 +02:00
public Inventory CreateJobsSubGUI(Player player, Job job) {
2015-11-27 15:34:19 +01:00
Inventory tempInv = Bukkit.createInventory(null, 54, "");
ItemStack GuiItem = job.getGuiItem();
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
// money exp boost
Double MoneyBoost = JPlayer.getBoost(job.getName(), BoostType.MONEY);
Double ExpBoost = JPlayer.getBoost(job.getName(), BoostType.EXP);
2015-11-27 15:34:19 +01:00
int level = 1;
JobProgression prog = JPlayer.getJobProgression(job);
if (prog != null)
level = prog.getLevel();
int numjobs = JPlayer.getJobProgression().size();
List<ItemStack> items = new ArrayList<ItemStack>();
int i = 0;
for (ActionType actionType : ActionType.values()) {
List<JobInfo> info = job.getJobInfo(actionType);
if (info == null || info.isEmpty())
continue;
ArrayList<String> Lore = new ArrayList<String>();
2016-03-30 15:42:36 +02:00
Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase()
2015-12-21 14:11:57 +01:00
+ ".info")));
2015-11-27 15:34:19 +01:00
int y = 1;
for (int z = 0; z < info.size(); z++) {
2016-03-30 15:42:36 +02:00
String itemName = Jobs.getNameTranslatorManager().Translate(info.get(z).getName(), info.get(z));
2015-11-27 15:34:19 +01:00
double income = info.get(z).getIncome(level, numjobs);
income = income + ((income * MoneyBoost) - income) + ((income * job.getMoneyBoost()) - income);
ChatColor incomeColor = income >= 0 ? ChatColor.GREEN : ChatColor.DARK_RED;
double xp = info.get(z).getExperience(level, numjobs);
xp = xp + ((xp * ExpBoost) - xp) + ((xp * job.getExpBoost()) - xp);
ChatColor xpColor = xp >= 0 ? ChatColor.YELLOW : ChatColor.GRAY;
String xpString = String.format("%.2fxp", xp);
Lore.add(ChatColor.translateAlternateColorCodes('&', "&7" + itemName + " " + xpColor + xpString + " " + incomeColor + Jobs.getEconomy().format(income)));
if (y >= 10) {
y = 1;
if (z == info.size() - 1)
continue;
ItemMeta meta = GuiItem.getItemMeta();
meta.setDisplayName(job.getName());
meta.setLore(Lore);
GuiItem.setItemMeta(meta);
//GuiInv.setItem(i, GuiItem);
tempInv.setItem(i, GuiItem);
GuiItem = job.getGuiItem();
Lore = new ArrayList<String>();
2016-03-30 15:42:36 +02:00
Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase()
2015-12-21 14:11:57 +01:00
+ ".info")));
2015-11-27 15:34:19 +01:00
i++;
}
y++;
}
ItemMeta meta = GuiItem.getItemMeta();
meta.setDisplayName(job.getName());
meta.setLore(Lore);
GuiItem.setItemMeta(meta);
//GuiInv.setItem(i, GuiItem);
tempInv.setItem(i, GuiItem);
i++;
}
for (ItemStack one : tempInv.getContents()) {
if (one != null)
items.add(one);
}
int GuiSize = 18;
int backButton = 9;
if (items.size() > 9) {
GuiSize = 27;
backButton = 18;
}
if (items.size() > 18) {
GuiSize = 36;
backButton = 27;
}
if (items.size() > 27) {
GuiSize = 45;
backButton = 36;
}
if (items.size() > 36) {
GuiSize = 54;
backButton = 45;
}
// if (items.size() > 45) {
// GuiSize = 54;
// backButton = 53;
// }
2016-03-30 15:42:36 +02:00
String title = Jobs.getLanguage().getMessage("command.info.gui.jobinfo", "[jobname]", job.getName());
2015-12-17 13:04:34 +01:00
if (title.length() > 32)
title = title.substring(0, 30) + "..";
Inventory GuiInv = Bukkit.createInventory(null, GuiSize, title);
2015-11-27 15:34:19 +01:00
for (int i1 = 0; i1 < items.size(); i1++) {
GuiInv.setItem(i1, items.get(i1));
}
ItemStack skull = new ItemStack(Material.JACK_O_LANTERN, 1, (byte) 0);
ItemMeta skullMeta = skull.getItemMeta();
2016-03-30 15:42:36 +02:00
skullMeta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.back"));
2015-11-27 15:34:19 +01:00
skull.setItemMeta(skullMeta);
GuiInv.setItem(backButton, skull);
GuiInfoList guiInfo = new GuiInfoList(player.getName());
guiInfo.setJobInfo(true);
guiInfo.setbackButton(backButton);
GuiList.put(player.getName(), guiInfo);
return GuiInv;
}
}