1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-04 23:37:49 +01:00

Lets load the job files

- Removed more synchronized methods
- Added slot option to example job to remind users there is sorting
This commit is contained in:
montlikadani 2020-12-07 17:10:04 +01:00
parent d158059759
commit 1daf097f2e
18 changed files with 132 additions and 152 deletions

View File

@ -28,113 +28,112 @@ import com.gamingmesh.jobs.container.JobsPlayer;
public class GuiManager { public class GuiManager {
public void openJobsBrowseGUI(final Player player) { public void openJobsBrowseGUI(final Player player) {
ArrayList<Job> JobsList = new ArrayList<>(); ArrayList<Job> jobsList = new ArrayList<>();
for (Job job : Jobs.getJobs()) { for (Job job : Jobs.getJobs()) {
if (Jobs.getGCManager().getHideJobsWithoutPermission()) if (Jobs.getGCManager().getHideJobsWithoutPermission())
if (!Jobs.getCommandManager().hasJobPermission(player, job)) if (!Jobs.getCommandManager().hasJobPermission(player, job))
continue; continue;
JobsList.add(job); jobsList.add(job);
} }
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"));
gui.setFiller(CMIMaterial.get(Jobs.getGCManager().guiFiller)); gui.setFiller(CMIMaterial.get(Jobs.getGCManager().guiFiller));
int GuiSize = Jobs.getGCManager().getJobsGUIRows() * 9, int guiSize = Jobs.getGCManager().getJobsGUIRows() * 9,
neededSlots = JobsList.size() + ((JobsList.size() / Jobs.getGCManager().getJobsGUIGroupAmount()) neededSlots = jobsList.size() + ((jobsList.size() / 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
GuiSize = GuiSize > 54 ? 54 : GuiSize; 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 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 = JobsList.size() > 28 ? JobsList.size() <= 42 ? 0 : -1 : pos; pos = jobsList.size() > 28 ? jobsList.size() <= 42 ? 0 : -1 : pos;
int group = 0; int group = 0;
main: for (int z = 0; z < JobsList.size(); z++) { main: for (int z = 0; z < jobsList.size(); 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 (JobsList.size() <= 42) { if (jobsList.size() <= 42) {
pos += Jobs.getGCManager().getJobsGUISkipAmount(); pos += Jobs.getGCManager().getJobsGUISkipAmount();
} }
} }
pos++; pos++;
if (i >= JobsList.size()) if (i >= jobsList.size())
break main; break main;
Job job = JobsList.get(i); Job job = jobsList.get(i);
ArrayList<String> Lore = new ArrayList<>(); ArrayList<String> lore = new ArrayList<>();
for (JobProgression onePJob : JPlayer.getJobProgression()) { for (JobProgression onePJob : jPlayer.getJobProgression()) {
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"));
} }
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)
if (job.getBonus() < 0) if (job.getBonus() < 0)
Lore.add(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", (int) (job.getBonus() * 100) * -1)); lore.add(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", (int) (job.getBonus() * 100) * -1));
else else
Lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (job.getBonus() * 100))); lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (job.getBonus() * 100)));
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)
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - Jobs.getUsedSlots(job)) > 0 ? (job.getMaxSlots() - Jobs lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - Jobs.getUsedSlots(job)) > 0 ? (job.getMaxSlots() - Jobs
.getUsedSlots(job)) : 0)); .getUsedSlots(job)) : 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))
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.getNameWithColor()); meta.setDisplayName(job.getNameWithColor());
meta.setLore(Lore); meta.setLore(lore);
GuiItem.setItemMeta(meta); guiItem.setItemMeta(meta);
int lastPos = pos; int lastPos = job.getGuiSlot() >= 0 ? job.getGuiSlot() : pos;
if (job.getGuiSlot() >= 0) gui.addButton(new CMIGuiButton(lastPos, guiItem) {
lastPos = job.getGuiSlot();
gui.addButton(new CMIGuiButton(lastPos, GuiItem) {
@Override @Override
public void click(GUIClickType type) { public void click(GUIClickType type) {
@ -188,14 +187,13 @@ public class GuiManager {
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.getJobProgression().size(), numjobs = jPlayer.getJobProgression().size(),
nextButton = Jobs.getGCManager().getJobsGUINextButton(), nextButton = Jobs.getGCManager().getJobsGUINextButton(),
backButton = Jobs.getGCManager().getJobsGUIBackButton(); backButton = Jobs.getGCManager().getJobsGUIBackButton();
@ -205,8 +203,8 @@ public class GuiManager {
if (info == null || info.isEmpty()) if (info == null || info.isEmpty())
continue; continue;
ArrayList<String> Lore = new ArrayList<>(); ArrayList<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++) {
@ -215,15 +213,15 @@ public class GuiManager {
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();
@ -245,7 +243,7 @@ public class GuiManager {
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;
@ -257,15 +255,15 @@ public class GuiManager {
break; break;
} }
ItemMeta meta = GuiItem.getItemMeta(); ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getNameWithColor()); meta.setDisplayName(job.getNameWithColor());
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++;
} }
@ -276,21 +274,21 @@ public class GuiManager {
break; break;
} }
ItemMeta meta = GuiItem.getItemMeta(); ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getNameWithColor()); meta.setDisplayName(job.getNameWithColor());
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 = GUIManager.isOpenedGui(player) && GUIManager.getGui(player) != null ? int guiSize = GUIManager.isOpenedGui(player) && GUIManager.getGui(player) != null ?
GUIManager.getGui(player).getInvSize().getFields() : Jobs.getGCManager().getJobsGUIRows() * 9; GUIManager.getGui(player).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.setFiller(CMIMaterial.get(Jobs.getGCManager().guiFiller)); gui.setFiller(CMIMaterial.get(Jobs.getGCManager().guiFiller));
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()) {
@ -299,7 +297,7 @@ public class GuiManager {
} }
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)));
@ -330,7 +328,7 @@ public class GuiManager {
List<ActionType> jobsRemained = new ArrayList<>(); List<ActionType> jobsRemained = new ArrayList<>();
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() && info.size() <= GuiSize) if (info != null && !info.isEmpty() && info.size() <= guiSize)
jobsRemained.add(actionType); jobsRemained.add(actionType);
} }
@ -349,21 +347,21 @@ public class GuiManager {
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.getJobProgression().size(); int numjobs = jPlayer.getJobProgression().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;
ArrayList<String> Lore = new ArrayList<>(); ArrayList<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++) {
@ -372,15 +370,15 @@ public class GuiManager {
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();
@ -402,7 +400,7 @@ public class GuiManager {
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;
@ -414,15 +412,15 @@ public class GuiManager {
break; break;
} }
ItemMeta meta = GuiItem.getItemMeta(); ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getNameWithColor()); meta.setDisplayName(job.getNameWithColor());
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++;
} }
@ -433,22 +431,22 @@ public class GuiManager {
break; break;
} }
ItemMeta meta = GuiItem.getItemMeta(); ItemMeta meta = guiItem.getItemMeta();
meta.setDisplayName(job.getNameWithColor()); meta.setDisplayName(job.getNameWithColor());
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 = GUIManager.isOpenedGui(player) && GUIManager.getGui(player) != null ? int guiSize = GUIManager.isOpenedGui(player) && GUIManager.getGui(player) != null ?
GUIManager.getGui(player).getInvSize().getFields() : Jobs.getGCManager().getJobsGUIRows() * 9; GUIManager.getGui(player).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.setFiller(CMIMaterial.get(Jobs.getGCManager().guiFiller)); gui.setFiller(CMIMaterial.get(Jobs.getGCManager().guiFiller));
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()) {
@ -457,7 +455,7 @@ public class GuiManager {
} }
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)));

View File

@ -387,7 +387,7 @@ public class PlayerManager {
Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(job)); Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(job));
jPlayer.setLeftTime(job); jPlayer.setLeftTime(job);
PerformCommands.PerformCommandsOnJoin(jPlayer, job); PerformCommands.performCommandsOnJoin(jPlayer, job);
Jobs.takeSlot(job); Jobs.takeSlot(job);
Jobs.getSignUtil().updateAllSign(job); Jobs.getSignUtil().updateAllSign(job);
@ -418,7 +418,7 @@ public class PlayerManager {
if (!Jobs.getJobsDAO().quitJob(jPlayer, job)) if (!Jobs.getJobsDAO().quitJob(jPlayer, job))
return false; return false;
PerformCommands.PerformCommandsOnLeave(jPlayer, job); PerformCommands.performCommandsOnLeave(jPlayer, job);
Jobs.leaveSlot(job); Jobs.leaveSlot(job);
jPlayer.getLeftTimes().remove(jPlayer.getUniqueId()); jPlayer.getLeftTimes().remove(jPlayer.getUniqueId());

View File

@ -96,9 +96,6 @@ public class JobsCommands implements CommandExecutor {
if (back) if (back)
return true; return true;
if (!(sender instanceof Player))
return help(sender, 1);
return help(sender, 1); return help(sender, 1);
} }
@ -129,7 +126,7 @@ public class JobsCommands implements CommandExecutor {
} }
protected boolean help(CommandSender sender, int page) { protected boolean help(CommandSender sender, int page) {
Map<String, Integer> commands = GetCommands(sender); Map<String, Integer> commands = getCommands(sender);
if (commands.isEmpty()) { if (commands.isEmpty()) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission")); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission"));
return true; return true;
@ -159,7 +156,7 @@ public class JobsCommands implements CommandExecutor {
return true; return true;
} }
public Map<String, Integer> GetCommands(CommandSender sender) { public Map<String, Integer> getCommands(CommandSender sender) {
Map<String, Integer> temp = new HashMap<>(); Map<String, Integer> temp = new HashMap<>();
for (Entry<String, Integer> cmd : commandList.entrySet()) { for (Entry<String, Integer> cmd : commandList.entrySet()) {
if (sender instanceof Player && !hasCommandPermission(sender, cmd.getKey())) if (sender instanceof Player && !hasCommandPermission(sender, cmd.getKey()))

View File

@ -479,6 +479,7 @@ public class ConfigManager {
} }
public void reload() { public void reload() {
jobFiles.clear();
migrateJobs(); migrateJobs();
if (jobFiles.isEmpty()) { if (jobFiles.isEmpty()) {

View File

@ -282,7 +282,7 @@ public class GeneralConfigManager {
* *
* loads from Jobs/generalConfig.yml * loads from Jobs/generalConfig.yml
*/ */
private synchronized void loadGeneralSettings() { private void loadGeneralSettings() {
c = new ConfigReader("generalConfig.yml"); c = new ConfigReader("generalConfig.yml");
c.header(Arrays.asList("General configuration.", c.header(Arrays.asList("General configuration.",

View File

@ -23,7 +23,7 @@ public class LanguageManager {
* *
* loads from Jobs/locale/messages_en.yml * loads from Jobs/locale/messages_en.yml
*/ */
synchronized void load() { void load() {
// This should be present to copy over default locale files into locale folder if file doesn't exist. Grabs all files from plugin file. // This should be present to copy over default locale files into locale folder if file doesn't exist. Grabs all files from plugin file.
languages = new ArrayList<>(); languages = new ArrayList<>();
try { try {

View File

@ -242,7 +242,7 @@ public class NameTranslatorManager {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
synchronized void load() { void load() {
String ls = Jobs.getGCManager().localeString; String ls = Jobs.getGCManager().localeString;
if (ls.isEmpty()) if (ls.isEmpty())
return; return;

View File

@ -179,7 +179,7 @@ public class RestrictedAreaManager {
* *
* loads from Jobs/restrictedAreas.yml * loads from Jobs/restrictedAreas.yml
*/ */
public synchronized void load() { public void load() {
restrictedAreas.clear(); restrictedAreas.clear();
File f = new File(Jobs.getFolder(), "restrictedAreas.yml"); File f = new File(Jobs.getFolder(), "restrictedAreas.yml");
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);

View File

@ -17,7 +17,7 @@ public class RestrictedBlockManager {
* Method to load the restricted blocks configuration * Method to load the restricted blocks configuration
* loads from Jobs/restrictedBlocks.yml * loads from Jobs/restrictedBlocks.yml
*/ */
public synchronized void load() { public void load() {
if (!Jobs.getGCManager().useBlockProtection) if (!Jobs.getGCManager().useBlockProtection)
return; return;

View File

@ -40,7 +40,7 @@ public class TitleManager {
* *
* loads from Jobs/titleConfig.yml * loads from Jobs/titleConfig.yml
*/ */
synchronized void load() { void load() {
titles.clear(); titles.clear();
ConfigReader c = new ConfigReader("titleConfig.yml"); ConfigReader c = new ConfigReader("titleConfig.yml");

View File

@ -46,10 +46,16 @@ public class ExploreRegion {
public int getChunkX(short place) { public int getChunkX(short place) {
int endX = place % 32; int endX = place % 32;
if (x < 0) if (x < 0)
endX = -endX; endX = -endX;
endX = x * 32 + endX; endX = x * 32 + endX;
endX = endX < 0 ? endX + 32 : endX;
if (endX < 0) {
endX += 32;
}
return endX; return endX;
} }
@ -58,7 +64,11 @@ public class ExploreRegion {
if (z < 0) if (z < 0)
endZ = -endZ; endZ = -endZ;
endZ = z * 32 + endZ; endZ = z * 32 + endZ;
endZ = endZ < 0 ? endZ + 32 : endZ;
if (endZ < 0) {
endZ += 32;
}
return endZ; return endZ;
} }
} }

View File

@ -182,8 +182,6 @@ public class BlockOwnerShip {
f = f2; f = f2;
int total = 0;
FileConfiguration config = f.getConfig(); FileConfiguration config = f.getConfig();
String path = (type == BlockTypes.FURNACE ? "Furnace" String path = (type == BlockTypes.FURNACE ? "Furnace"
@ -193,6 +191,7 @@ public class BlockOwnerShip {
if (isReassignDisabled() || !config.isConfigurationSection(path)) if (isReassignDisabled() || !config.isConfigurationSection(path))
return; return;
int total = 0;
ConfigurationSection section = config.getConfigurationSection(path); ConfigurationSection section = config.getConfigurationSection(path);
for (String one : section.getKeys(false)) { for (String one : section.getKeys(false)) {
String value = section.getString(one); String value = section.getString(one);
@ -242,12 +241,12 @@ public class BlockOwnerShip {
f.saveDefaultConfig(); f.saveDefaultConfig();
FileConfiguration config = f.getConfig();
if (isReassignDisabled()) { if (isReassignDisabled()) {
return; return;
} }
FileConfiguration config = f.getConfig();
String path = (type == BlockTypes.FURNACE ? "Furnace" String path = (type == BlockTypes.FURNACE ? "Furnace"
: type == BlockTypes.BLAST_FURNACE ? "BlastFurnace" : type == BlockTypes.BLAST_FURNACE ? "BlastFurnace"
: type == BlockTypes.BREWING_STAND ? "Brewing" : type == BlockTypes.SMOKER ? "Smoker" : ""); : type == BlockTypes.BREWING_STAND ? "Brewing" : type == BlockTypes.SMOKER ? "Smoker" : "");
@ -255,7 +254,6 @@ public class BlockOwnerShip {
for (Entry<UUID, List<blockLoc>> one : blockOwnerShips.entrySet()) { for (Entry<UUID, List<blockLoc>> one : blockOwnerShips.entrySet()) {
String full = ""; String full = "";
for (blockLoc oneL : one.getValue()) { for (blockLoc oneL : one.getValue()) {
if (!full.isEmpty()) if (!full.isEmpty())
full += ";"; full += ";";

View File

@ -27,11 +27,7 @@ public class JobsConnection {
} }
public synchronized boolean isValid(int timeout) throws SQLException { public synchronized boolean isValid(int timeout) throws SQLException {
try { return conn.isValid(timeout);
return conn.isValid(timeout);
} catch (AbstractMethodError e) {
return true;
}
} }
public synchronized void closeConnection() throws SQLException { public synchronized void closeConnection() throws SQLException {

View File

@ -870,11 +870,9 @@ public abstract class JobsDAO {
prestt.execute(); prestt.execute();
res2 = prestt.getGeneratedKeys(); res2 = prestt.getGeneratedKeys();
int id = 0;
if (res2.next())
id = res2.getInt(1);
Jobs.getPlayerManager().addPlayerToMap(new PlayerInfo(playerName, id, uuid, System.currentTimeMillis(), 0)); Jobs.getPlayerManager().addPlayerToMap(new PlayerInfo(playerName, res2.next() ? res2.getInt(1) : 0,
uuid, System.currentTimeMillis(), 0));
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
@ -896,12 +894,7 @@ public abstract class JobsDAO {
prestt.executeUpdate(); prestt.executeUpdate();
res2 = prestt.getGeneratedKeys(); res2 = prestt.getGeneratedKeys();
int id = 0; Util.addJobsWorld(new JobsWorld(worldName, res2.next() ? res2.getInt(1) : 0));
if (res2.next())
id = res2.getInt(1);
Util.addJobsWorld(new JobsWorld(worldName, id));
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {

View File

@ -135,11 +135,7 @@ public class JobsListener implements Listener {
return; return;
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack iih = Jobs.getNms().getItemInMainHand(player); if (Jobs.getNms().getItemInMainHand(player).getType() != CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getMaterial())
if (iih == null || iih.getType() == Material.AIR)
return;
if (iih.getType() != CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getMaterial())
return; return;
if (!Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld()) || !player.hasPermission("jobs.area.select")) if (!Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld()) || !player.hasPermission("jobs.area.select"))
@ -164,8 +160,6 @@ public class JobsListener implements Listener {
JobsAreaSelectionEvent jobsAreaSelectionEvent = new JobsAreaSelectionEvent(player, Jobs.getSelectionManager().getSelectionCuboid(player)); JobsAreaSelectionEvent jobsAreaSelectionEvent = new JobsAreaSelectionEvent(player, Jobs.getSelectionManager().getSelectionCuboid(player));
Bukkit.getServer().getPluginManager().callEvent(jobsAreaSelectionEvent); Bukkit.getServer().getPluginManager().callEvent(jobsAreaSelectionEvent);
} }
return;
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
@ -201,11 +195,9 @@ public class JobsListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerWorldChange(PlayerChangedWorldEvent event) { public void onPlayerWorldChange(PlayerChangedWorldEvent event) {
if (!plugin.isEnabled()) if (plugin.isEnabled()) {
return; Jobs.getPermissionHandler().recalculatePermissions(Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()));
}
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer());
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)

View File

@ -1,7 +1,5 @@
package com.gamingmesh.jobs.stuff; package com.gamingmesh.jobs.stuff;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
@ -9,16 +7,14 @@ import com.gamingmesh.jobs.container.JobsPlayer;
public class PerformCommands { public class PerformCommands {
public static void PerformCommandsOnLeave(JobsPlayer jPlayer, Job job) { public static void performCommandsOnLeave(JobsPlayer jPlayer, Job job) {
List<String> cmds = job.getCmdOnLeave(); for (String one : job.getCmdOnLeave()) {
for (String one : cmds) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", jPlayer.getName()).replace("[jobname]", job.getName())); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", jPlayer.getName()).replace("[jobname]", job.getName()));
} }
} }
public static void PerformCommandsOnJoin(JobsPlayer jPlayer, Job job) { public static void performCommandsOnJoin(JobsPlayer jPlayer, Job job) {
List<String> cmds = job.getCmdOnJoin(); for (String one : job.getCmdOnJoin()) {
for (String one : cmds) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", jPlayer.getName()).replace("[jobname]", job.getName())); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", jPlayer.getName()).replace("[jobname]", job.getName()));
} }
} }

View File

@ -32,22 +32,18 @@ public class TabComplete implements TabCompleter {
String PartOfCommand = args[0]; String PartOfCommand = args[0];
List<String> temp = new ArrayList<>(); List<String> temp = new ArrayList<>();
for (String BCmd : Jobs.getCommandManager().GetCommands(sender).keySet()) { Jobs.getCommandManager().getCommands(sender).keySet().forEach(temp::add);
temp.add(BCmd);
}
StringUtil.copyPartialMatches(PartOfCommand, temp, completionList); StringUtil.copyPartialMatches(PartOfCommand, temp, completionList);
} }
if (args.length > 1) if (args.length > 1)
for (int i = 1; i <= args.length; i++) for (int i = 1; i <= args.length; i++)
if (args.length == i + 1) { if (args.length == i + 1) {
String PartOfCommand = args[i]; String PartOfCommand = args[i];
if (!Jobs.getGCManager().getCommandArgs().containsKey(args[0].toLowerCase())) if (!Jobs.getGCManager().getCommandArgs().containsKey(args[0].toLowerCase()))
break; break;
List<String> ArgsList = Jobs.getGCManager().getCommandArgs().get(args[0].toLowerCase()); List<String> ArgsList = Jobs.getGCManager().getCommandArgs().get(args[0].toLowerCase());
if (ArgsList.size() < i) if (ArgsList.size() < i)
continue; continue;

View File

@ -100,6 +100,9 @@ exampleJob:
Enchantments: Enchantments:
- 'DURABILITY:1' - 'DURABILITY:1'
# The number of slot where to put this material in gui.
slot: 2
# Defines maximum amount of daily quests player can have from THIS job # Defines maximum amount of daily quests player can have from THIS job
# This will not have effect on overall quest amount player will have # This will not have effect on overall quest amount player will have
maxDailyQuests: 3 maxDailyQuests: 3