From 3a7eb6547226ba5be21cac239bc488c4838204f1 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Sat, 2 Nov 2019 15:32:53 +0100 Subject: [PATCH] Fixed jobs GUI when opened showing the same action names - Optimized the shooting of firework random --- Changelog.txt | 3 + .../gamingmesh/jobs/CMIGUI/GUIListener.java | 7 --- .../gamingmesh/jobs/CMIGUI/GUIManager.java | 16 ++---- .../com/gamingmesh/jobs/Gui/GuiInfoList.java | 56 ------------------- .../com/gamingmesh/jobs/Gui/GuiManager.java | 34 ++++++----- src/main/java/com/gamingmesh/jobs/Jobs.java | 2 +- .../com/gamingmesh/jobs/PlayerManager.java | 25 ++++++--- .../com/gamingmesh/jobs/Signs/SignUtil.java | 3 +- .../jobs/config/BlockProtectionManager.java | 1 - .../jobs/listeners/JobsListener.java | 1 - .../jobs/listeners/JobsPaymentListener.java | 4 +- 11 files changed, 49 insertions(+), 103 deletions(-) delete mode 100644 src/main/java/com/gamingmesh/jobs/Gui/GuiInfoList.java diff --git a/Changelog.txt b/Changelog.txt index cd9c7d15..03e9ebbb 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,6 @@ +# 4.15.0 +- Fixed issue for jobs browse when opened and showing the same actions. + # 4.14.0 - Fixed %titlename% placeholder does not showed anything - Re-added Cat, Cat is ALIVE!! diff --git a/src/main/java/com/gamingmesh/jobs/CMIGUI/GUIListener.java b/src/main/java/com/gamingmesh/jobs/CMIGUI/GUIListener.java index 21ea18ce..813f9e18 100644 --- a/src/main/java/com/gamingmesh/jobs/CMIGUI/GUIListener.java +++ b/src/main/java/com/gamingmesh/jobs/CMIGUI/GUIListener.java @@ -17,16 +17,9 @@ import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; -import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.Reflections; - public class GUIListener implements Listener { - Jobs plugin; - - public GUIListener(Jobs plugin) { - this.plugin = plugin; - } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onNormalInventoryClose(InventoryCloseEvent event) { diff --git a/src/main/java/com/gamingmesh/jobs/CMIGUI/GUIManager.java b/src/main/java/com/gamingmesh/jobs/CMIGUI/GUIManager.java index ade34f85..64e48be9 100644 --- a/src/main/java/com/gamingmesh/jobs/CMIGUI/GUIManager.java +++ b/src/main/java/com/gamingmesh/jobs/CMIGUI/GUIManager.java @@ -30,7 +30,7 @@ public class GUIManager { } public static void registerListener() { - Jobs.getInstance().getServer().getPluginManager().registerEvents(new GUIListener(Jobs.getInstance()), Jobs.getInstance()); + Jobs.getInstance().getServer().getPluginManager().registerEvents(new GUIListener(), Jobs.getInstance()); } public enum GUIButtonLocation { @@ -340,16 +340,12 @@ public class GUIManager { for (Entry one : gui.getButtons().entrySet()) { if (one.getKey() > GuiInv.getSize()) continue; - try { - ItemStack item = one.getValue().getItem(gui.getPlayer()); - item = item == null ? null : item.clone(); - if (item != null && one.getValue().isLocked()) { - item = Reflections.setNbt(item, CMIGUIIcon, LIProtection); - } - GuiInv.setItem(one.getKey(), item); - } catch (ArrayIndexOutOfBoundsException e) { - break; + ItemStack item = one.getValue().getItem(gui.getPlayer()); + item = item == null ? null : item.clone(); + if (item != null && one.getValue().isLocked()) { + item = Reflections.setNbt(item, CMIGUIIcon, LIProtection); } + GuiInv.setItem(one.getKey(), item); } gui.setInv(GuiInv); } diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiInfoList.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiInfoList.java deleted file mode 100644 index 06c1f4e5..00000000 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiInfoList.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.gamingmesh.jobs.Gui; - -import java.util.HashMap; - -import org.bukkit.inventory.Inventory; - -import com.gamingmesh.jobs.container.Job; - -public class GuiInfoList { - - private String name; - private HashMap jobList = new HashMap<>(); - private Boolean jobInfo = false; - private int backButton = 27; - private Inventory inv = null; - - public GuiInfoList(String name) { - this.name = name; - } - - public int getbackButton() { - return backButton; - } - - public void setbackButton(int backButton) { - this.backButton = backButton; - } - - public String getName() { - return name; - } - - public HashMap getJobList() { - return jobList; - } - - public void addJob(int slot, Job job) { - this.jobList.put(slot, job); - } - - public void setJobInfo(Boolean jobInfo) { - this.jobInfo = jobInfo; - } - - public Boolean isJobInfo() { - return jobInfo; - } - - public Inventory getInv() { - return inv; - } - - public void setInv(Inventory inv) { - this.inv = inv; - } -} diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java index bee69158..8d24c53e 100644 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java @@ -166,9 +166,7 @@ public class GuiManager { public void openJobsBrowseGUI(Player player, Job job) { Inventory tempInv = Bukkit.createInventory(player, 54, ""); - ItemStack GuiItem = job.getGuiItem(); JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - Boost boost = Jobs.getPlayerManager().getFinalBonus(JPlayer, job); int level = 1; @@ -176,9 +174,9 @@ public class GuiManager { if (prog != null) level = prog.getLevel(); + ItemStack GuiItem = job.getGuiItem(); int numjobs = JPlayer.getJobProgression().size(); - List items = new ArrayList<>(); int i = 0; for (ActionType actionType : ActionType.values()) { List info = job.getJobInfo(actionType); @@ -188,37 +186,43 @@ public class GuiManager { ArrayList 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; + } - String itemName = info.get(z).getRealisticName(); - - double income = info.get(z).getIncome(level, numjobs); - + double income = jInfo.getIncome(level, numjobs); income = boost.getFinalAmount(CurrencyType.MONEY, income); String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString(); - double xp = info.get(z).getExperience(level, numjobs); + double xp = jInfo.getExperience(level, numjobs); xp = boost.getFinalAmount(CurrencyType.EXP, xp); String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString(); - double points = info.get(z).getPoints(level, numjobs); + double points = jInfo.getPoints(level, numjobs); points = boost.getFinalAmount(CurrencyType.POINTS, points); String pointsColor = xp >= 0 ? "" : ChatColor.RED.toString(); if (income == 0D && points == 0D && xp == 0D) continue; + 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)); + 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)); + 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)); + 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); @@ -227,11 +231,11 @@ public class GuiManager { if (z == info.size() - 1) continue; + ItemMeta meta = GuiItem.getItemMeta(); meta.setDisplayName(job.getChatColor() + job.getName()); meta.setLore(Lore); GuiItem.setItemMeta(meta); - //GuiInv.setItem(i, GuiItem); tempInv.setItem(i, GuiItem.clone()); GuiItem = job.getGuiItem(); @@ -245,11 +249,11 @@ public class GuiManager { meta.setDisplayName(job.getChatColor() + job.getName()); meta.setLore(Lore); GuiItem.setItemMeta(meta); - //GuiInv.setItem(i, GuiItem); tempInv.setItem(i, GuiItem.clone()); i++; } + List items = new ArrayList<>(); for (ItemStack one : tempInv.getContents()) { if (one != null) items.add(one); @@ -264,7 +268,7 @@ public class GuiManager { gui.setInvSize(GuiSize); for (int i1 = 0; i1 < items.size(); i1++) { - gui.addButton(new CMIGuiButton(i1, GuiItem)); + gui.addButton(new CMIGuiButton(i1, items.get(i1))); } ItemStack skull = Jobs.getGCManager().guiBackButton; diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index a64d488d..6907b33d 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -1265,7 +1265,7 @@ public class Jobs extends JavaPlugin { if (expAmount != 0D) payments.put(CurrencyType.EXP, expAmount); - FastPayment.put(jPlayer.getPlayerUUID(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), payments), prog + FastPayment.put(jPlayer.getUniqueId(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), payments), prog .getJob())); economy.pay(jPlayer, payments); diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 8fc9c4a2..fc20f047 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -22,10 +22,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Random; import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ThreadLocalRandom; import java.util.regex.Pattern; import org.bukkit.Bukkit; @@ -244,7 +244,7 @@ public class PlayerManager { if (!jPlayer.isOnline() && jPlayer.isSaved()) iter.remove(); } - + Jobs.getBpManager().saveCache(); } @@ -618,20 +618,29 @@ public class PlayerManager { FireworkMeta fm = f.getFireworkMeta(); if (Jobs.getGCManager().UseRandom) { - Random r = new Random(); + ThreadLocalRandom r = ThreadLocalRandom.current(); int rt = r.nextInt(4) + 1; Type type = Type.BALL; - if (rt == 1) + switch (rt) { + case 1: type = Type.BALL; - if (rt == 2) + break; + case 2: type = Type.BALL_LARGE; - if (rt == 3) + break; + case 3: type = Type.BURST; - if (rt == 4) + break; + case 4: type = Type.CREEPER; - if (rt == 5) + break; + case 5: type = Type.STAR; + break; + default: + break; + } int r1i = r.nextInt(17) + 1; int r2i = r.nextInt(17) + 1; diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index 16c0e281..23cf1edf 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -21,7 +21,6 @@ import com.gamingmesh.jobs.CMILib.VersionChecker.Version; import com.gamingmesh.jobs.config.CommentedYamlConfiguration; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.TopList; -import com.gamingmesh.jobs.stuff.Debug; public class SignUtil { @@ -291,7 +290,7 @@ public class SignUtil { sign.setLine(i, line); } sign.update(); - if (!UpdateHead(sign, ((TopList) PlayerList.get(0)).getPlayerName(), timelapse)) { + if (!UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse)) { timelapse--; } } else { diff --git a/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java b/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java index 374d3b11..a50d083f 100644 --- a/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java @@ -13,7 +13,6 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; import com.gamingmesh.jobs.container.BlockProtection; import com.gamingmesh.jobs.container.DBAction; -import com.gamingmesh.jobs.stuff.Debug; public class BlockProtectionManager { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 8383e164..a01662ec 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -50,7 +50,6 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.player.AsyncPlayerChatEvent; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 45d69d9f..62d6f582 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -982,16 +982,16 @@ public class JobsPaymentListener implements Listener { MetadataValue value = data.get(0); String playerName = value.asString(); - Player player = null; UUID uuid = null; try { uuid = UUID.fromString(playerName); } catch (IllegalArgumentException e) { } + if (uuid == null) return; - player = Bukkit.getPlayer(uuid); + Player player = Bukkit.getPlayer(uuid); if (player == null || !player.isOnline()) return;