From 17005f2823e00245a621ffae88bd39b8fd8772a9 Mon Sep 17 00:00:00 2001 From: Zrips Date: Fri, 26 Nov 2021 17:36:12 +0200 Subject: [PATCH] Using job display name for signs instead of jobs internal identificator --- .../com/gamingmesh/jobs/Gui/GuiManager.java | 52 +++++++++---------- .../com/gamingmesh/jobs/Signs/SignUtil.java | 4 ++ .../com/gamingmesh/jobs/container/Job.java | 9 +++- .../jobs/listeners/JobsListener.java | 2 +- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java index ae61eec6..2f91ee36 100644 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java @@ -37,7 +37,7 @@ public class GuiManager { for (Job job : Jobs.getJobs()) { if (Jobs.getGCManager().getHideJobsWithoutPermission() && !Jobs.getCommandManager().hasJobPermission(player, job)) - continue; + continue; jobsList.add(job); } @@ -49,9 +49,9 @@ public class GuiManager { gui.setFiller(Jobs.getGCManager().guiFiller); int guiSize = Jobs.getGCManager().getJobsGUIRows() * 9, - neededSlots = jobsListSize + ((jobsListSize / Jobs.getGCManager().getJobsGUIGroupAmount()) - * Jobs.getGCManager().getJobsGUISkipAmount()) + Jobs.getGCManager().getJobsGUIStartPosition(), - neededRows = (int) Math.ceil(neededSlots / 9D); + 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; @@ -261,15 +261,15 @@ public class GuiManager { if (income != 0.0) 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) 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) 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); @@ -307,8 +307,8 @@ public class GuiManager { 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())); @@ -343,20 +343,20 @@ public class GuiManager { }); } - 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(Jobs.getLanguage().getMessage("command.info.gui.next")); - next.setItemMeta(meta); + meta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.next")); + 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(); @@ -408,15 +408,15 @@ public class GuiManager { if (income != 0.0) 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) 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) 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); @@ -457,8 +457,8 @@ public class GuiManager { 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; int backButton = Jobs.getGCManager().getJobsGUIBackButton(); CMIGui gui = new CMIGui(player); diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index 493bcb29..b5598f3f 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -22,6 +22,7 @@ import com.gamingmesh.jobs.container.TopList; import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Version.Version; public class SignUtil { @@ -236,6 +237,9 @@ public class SignUtil { temp.put(signJobName, playerList); } + if (Jobs.getJob(jSign.getJobName()) != null) + signJobName = Jobs.getJob(jSign.getJobName()).getJobDisplayName(); + if (playerList.isEmpty()) continue; diff --git a/src/main/java/com/gamingmesh/jobs/container/Job.java b/src/main/java/com/gamingmesh/jobs/container/Job.java index d2f7a309..76f74c82 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Job.java +++ b/src/main/java/com/gamingmesh/jobs/container/Job.java @@ -349,7 +349,12 @@ public class Job { return fullName; } + @Deprecated public String getJobDisplayName() { + return getDisplayName(); + } + + public String getDisplayName() { return jobDisplayName == null ? jobColour + fullName : jobDisplayName; } @@ -572,8 +577,8 @@ public class Job { if (fDescription != null) { this.fDescription.addAll(fDescription); - this.description = String.join("\n",this.fDescription); - } + this.description = String.join("\n", this.fDescription); + } } public void setMaxLevelCommands(List commands) { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 02a841d8..19424a64 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -346,7 +346,7 @@ public class JobsListener implements Listener { return; String color = Jobs.getGCManager().SignsColorizeJobName ? job.getChatColor().toString() : ""; - event.setLine(2, convert(color + job.getName())); + event.setLine(2, convert(color + job.getDisplayName())); } private final Pattern pattern = Pattern.compile("&([0-9a-fk-or])");