From 21ff1801cdc405354f89b03bf5642c84b1ecb84a Mon Sep 17 00:00:00 2001 From: montlikadani Date: Tue, 4 May 2021 14:50:28 +0200 Subject: [PATCH] Some things --- src/main/java/com/gamingmesh/jobs/Jobs.java | 5 +- .../gamingmesh/jobs/PermissionHandler.java | 3 +- .../com/gamingmesh/jobs/PlayerManager.java | 15 ++++-- .../jobs/commands/JobsCommands.java | 6 ++- .../gamingmesh/jobs/commands/list/area.java | 6 ++- .../jobs/commands/list/blockinfo.java | 5 +- .../gamingmesh/jobs/commands/list/bonus.java | 2 +- .../gamingmesh/jobs/commands/list/browse.java | 42 +++++++++------- .../gamingmesh/jobs/commands/list/demote.java | 11 +++-- .../jobs/commands/list/expboost.java | 11 +++-- .../jobs/commands/list/explored.java | 7 ++- .../jobs/commands/list/fireall.java | 2 +- .../gamingmesh/jobs/commands/list/give.java | 13 +++-- .../gamingmesh/jobs/commands/list/join.java | 2 +- .../gamingmesh/jobs/commands/list/limit.java | 6 ++- .../gamingmesh/jobs/commands/list/log.java | 3 +- .../jobs/commands/list/moneyboost.java | 11 +++-- .../jobs/commands/list/pointboost.java | 11 +++-- .../jobs/commands/list/promote.java | 8 ++- .../gamingmesh/jobs/commands/list/quests.java | 10 ++-- .../gamingmesh/jobs/commands/list/stats.java | 6 +-- .../gamingmesh/jobs/commands/list/toggle.java | 49 +++++++------------ .../gamingmesh/jobs/config/ConfigManager.java | 3 ++ .../jobs/config/GeneralConfigManager.java | 44 +++++++++-------- .../jobs/container/BlockProtection.java | 16 +++--- .../jobs/economy/BufferedEconomy.java | 10 ++-- .../hooks/MythicMobs/MythicMobs4Listener.java | 4 +- .../jobs/listeners/JobsPaymentListener.java | 15 +++--- .../jobs/stuff/ToggleBarHandling.java | 7 ++- .../jobs/tasks/BufferedPaymentTask.java | 8 ++- 30 files changed, 191 insertions(+), 150 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 61faf986..83201cd9 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -1284,7 +1284,7 @@ public class Jobs extends JavaPlugin { BlockProtection bp = getBpManager().getBp(block.getLocation()); if (bp != null) { - Long time = bp.getTime(); + long time = bp.getTime(); Integer cd = getBpManager().getBlockDelayTime(block); if (time == -1L) { @@ -1338,8 +1338,7 @@ public class Jobs extends JavaPlugin { // Lets add protection in any case getBpManager().add(block, cd); - - } else if (bp.isPaid().booleanValue() && bp.getTime() == -1L && cd != null && cd == -1) { + } else if (bp.isPaid() && bp.getTime() == -1L && cd != null && cd == -1) { getBpManager().add(block, cd); return false; } else diff --git a/src/main/java/com/gamingmesh/jobs/PermissionHandler.java b/src/main/java/com/gamingmesh/jobs/PermissionHandler.java index 70683e8d..c97028da 100644 --- a/src/main/java/com/gamingmesh/jobs/PermissionHandler.java +++ b/src/main/java/com/gamingmesh/jobs/PermissionHandler.java @@ -251,7 +251,8 @@ public class PermissionHandler { } public boolean hasWorldPermission(JobsPlayer player) { - return player.getPlayer() != null && hasWorldPermission(player, player.getPlayer().getWorld().getName()); + Player pl = player.getPlayer(); + return pl != null && hasWorldPermission(player, pl.getWorld().getName()); } public boolean hasWorldPermission(JobsPlayer player, String world) { diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 7b83e7c6..19f6bb0a 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -461,7 +461,7 @@ public class PlayerManager { * @param job {@link Job} */ public void joinJob(JobsPlayer jPlayer, Job job) { - if (jPlayer == null || job == null || jPlayer.isInJob(job)) + if (jPlayer == null || jPlayer.isInJob(job)) return; // let the user join the job @@ -494,7 +494,7 @@ public class PlayerManager { * @param job {@link Job} */ public boolean leaveJob(JobsPlayer jPlayer, Job job) { - if (jPlayer == null || job == null || !jPlayer.isInJob(job)) + if (jPlayer == null || !jPlayer.isInJob(job)) return false; JobsLeaveEvent jobsLeaveEvent = new JobsLeaveEvent(jPlayer, job); @@ -587,11 +587,15 @@ public class PlayerManager { * @param experience - experience gained */ public void addExperience(JobsPlayer jPlayer, Job job, double experience) { + if (experience > Double.MAX_VALUE) + return; + JobProgression prog = jPlayer.getJobProgression(job); - if (prog == null || experience > Double.MAX_VALUE) + if (prog == null) return; int oldLevel = prog.getLevel(); + if (prog.addExperience(experience)) { performLevelUp(jPlayer, job, oldLevel); Jobs.getSignUtil().updateAllSign(job); @@ -608,8 +612,11 @@ public class PlayerManager { * @param experience - experience gained */ public void removeExperience(JobsPlayer jPlayer, Job job, double experience) { + if (experience > Double.MAX_VALUE) + return; + JobProgression prog = jPlayer.getJobProgression(job); - if (prog == null || experience > Double.MAX_VALUE) + if (prog == null) return; prog.addExperience(-experience); diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index 0873e432..b6189988 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -145,8 +145,10 @@ public class JobsCommands implements CommandExecutor { public Set getCommands(CommandSender sender) { Set temp = new TreeSet<>(); + boolean senderIsPlayer = sender instanceof Player; + for (String cmd : commandList) { - if (sender instanceof Player && !hasCommandPermission(sender, cmd)) + if (senderIsPlayer && !hasCommandPermission(sender, cmd)) continue; temp.add(cmd); @@ -288,7 +290,7 @@ public class JobsCommands implements CommandExecutor { String t = type.isEmpty() ? "" : " " + type; - if (sender instanceof Player) { + if (isPlayer) { String pName = player.getName(); if (sender.getName().equalsIgnoreCase(pName)) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/area.java b/src/main/java/com/gamingmesh/jobs/commands/list/area.java index 55ca40c6..904d1789 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/area.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/area.java @@ -58,11 +58,13 @@ public class area implements Cmd { return true; } if (wg && HookManager.getWorldGuardManager() != null) { - if (HookManager.getWorldGuardManager().getProtectedRegionByName(name) == null) { + com.sk89q.worldguard.protection.regions.ProtectedRegion protectedRegion = HookManager.getWorldGuardManager().getProtectedRegionByName(name); + + if (protectedRegion == null) { sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.wgDontExist")); return true; } - name = HookManager.getWorldGuardManager().getProtectedRegionByName(name).getId(); + name = protectedRegion.getId(); } if (!wg) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/blockinfo.java b/src/main/java/com/gamingmesh/jobs/commands/list/blockinfo.java index b5a9fb43..e5b086ec 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/blockinfo.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/blockinfo.java @@ -28,13 +28,14 @@ public class blockinfo implements Cmd { if (block == null || CMIMaterial.isAir(block.getType())) return true; - String dataString = CMIMaterial.getBlockData(block) == 0 ? "" : "-" + CMIMaterial.getBlockData(block); + byte blockData = CMIMaterial.getBlockData(block); + String dataString = blockData == 0 ? "" : "-" + blockData; sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); sender.sendMessage(Jobs.getLanguage().getMessage("command.blockinfo.output.name", "%blockname%", block.getType().name())); if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) sender.sendMessage(Jobs.getLanguage().getMessage("command.blockinfo.output.id", "%blockid%", block.getType().getId())); - sender.sendMessage(Jobs.getLanguage().getMessage("command.blockinfo.output.data", "%blockdata%", CMIMaterial.getBlockData(block))); + sender.sendMessage(Jobs.getLanguage().getMessage("command.blockinfo.output.data", "%blockdata%", blockData)); if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) sender.sendMessage(Jobs.getLanguage().getMessage("command.blockinfo.output.usage", "%first%", "", "%second%", block.getType().name() + dataString)); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java index a26daa7b..917d5d01 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java @@ -80,7 +80,7 @@ public class bonus implements Cmd { "%points%", formatText(boost.get(type, CurrencyType.POINTS, true)), "%exp%", formatText(boost.get(type, CurrencyType.EXP, true))); - if (msg.startsWith(" ") && (type == BoostOf.NearSpawner || type == BoostOf.PetPay)) + if ((type == BoostOf.NearSpawner || type == BoostOf.PetPay) && msg.startsWith(" ")) msg = msg.substring(1, msg.length()); sender.sendMessage(prefix + msg); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java index 976ee004..0fd221fc 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java @@ -17,14 +17,16 @@ public class browse implements Cmd { @Override public boolean perform(Jobs plugin, CommandSender sender, final String[] args) { + boolean senderIsPlayer = sender instanceof Player; + if (Jobs.getGCManager().BrowseUseNewLook) { - List jobList = new ArrayList<>(Jobs.getJobs()); - if (jobList.isEmpty()) { + if (Jobs.getJobs().isEmpty()) { sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.error.nojobs")); return true; } - if (sender instanceof Player && Jobs.getGCManager().JobsGUIOpenOnBrowse) { + List jobList = new ArrayList<>(Jobs.getJobs()); + if (senderIsPlayer && Jobs.getGCManager().JobsGUIOpenOnBrowse) { try { plugin.getGUIManager().openJobsBrowseGUI((Player) sender); } catch (Throwable e) { @@ -35,7 +37,7 @@ public class browse implements Cmd { } int page = 1; - if (sender instanceof Player) { + if (senderIsPlayer) { for (String one : args) { if (one.startsWith("-p:")) { try { @@ -54,7 +56,7 @@ public class browse implements Cmd { } } - if (sender instanceof Player) { + if (senderIsPlayer) { if (j == null) { PageInfo pi = new PageInfo(Jobs.getGCManager().getBrowseAmountToShow(), jobList.size(), page); sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.newHeader", "[amount]", jobList.size())); @@ -112,8 +114,9 @@ public class browse implements Cmd { sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.jobHeader", "[jobname]", j.getName())); - if (j.getMaxLevel(sender) > 0) - sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.newMax", "[max]", j.getMaxLevel(sender))); + int maxLevel = j.getMaxLevel(sender); + if (maxLevel > 0) + sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.newMax", "[max]", maxLevel)); if (Jobs.getGCManager().ShowTotalWorkers) sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", j.getTotalPlayers())); @@ -125,10 +128,8 @@ public class browse implements Cmd { sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (j.getBonus() * 100))); } - if (!j.getFullDescription().isEmpty()) { - for (String one : j.getFullDescription()) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.description", "[description]", one)); - } + for (String one : j.getFullDescription()) { + sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.description", "[description]", one)); } RawMessage rm = new RawMessage(); @@ -154,8 +155,9 @@ public class browse implements Cmd { } } - if (one.getMaxLevel(sender) > 0) - msg += Jobs.getLanguage().getMessage("command.browse.output.console.newMax", "[max]", one.getMaxLevel(sender)); + int maxLevel = one.getMaxLevel(sender); + if (maxLevel > 0) + msg += Jobs.getLanguage().getMessage("command.browse.output.console.newMax", "[max]", maxLevel); if (Jobs.getGCManager().ShowTotalWorkers) msg += Jobs.getLanguage().getMessage("command.browse.output.console.totalWorkers", "[amount]", one.getTotalPlayers()); @@ -174,8 +176,9 @@ public class browse implements Cmd { } else { sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.jobHeader", "[jobname]", j.getName())); - if (j.getMaxLevel(sender) > 0) - sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.newMax", "[max]", j.getMaxLevel(sender))); + int maxLevel = j.getMaxLevel(sender); + if (maxLevel > 0) + sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.newMax", "[max]", maxLevel)); if (Jobs.getGCManager().ShowTotalWorkers) sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", j.getTotalPlayers())); @@ -204,10 +207,12 @@ public class browse implements Cmd { builder.append(" "); builder.append(job.getChatColor().toString()); builder.append(job.getName()); - if (job.getMaxLevel(sender) > 0) { + + int maxLevel = job.getMaxLevel(sender); + if (maxLevel > 0) { builder.append(CMIChatColor.WHITE.toString()); builder.append(Jobs.getLanguage().getMessage("command.info.help.max")); - builder.append(job.getMaxLevel(sender)); + builder.append(maxLevel); } if (Jobs.getGCManager().ShowTotalWorkers) @@ -220,6 +225,7 @@ public class browse implements Cmd { builder.append(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (job.getBonus() * 100))); lines.add(builder.toString()); + if (!job.getDescription().isEmpty()) lines.add(" - " + job.getDescription().replaceAll("/n|\n", "")); else { @@ -234,7 +240,7 @@ public class browse implements Cmd { return true; } - if (sender instanceof Player && Jobs.getGCManager().JobsGUIOpenOnBrowse) { + if (senderIsPlayer && Jobs.getGCManager().JobsGUIOpenOnBrowse) { try { plugin.getGUIManager().openJobsBrowseGUI((Player) sender); } catch (Throwable e) { diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/demote.java b/src/main/java/com/gamingmesh/jobs/commands/list/demote.java index 988796c8..51a5e5c5 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/demote.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/demote.java @@ -1,6 +1,5 @@ package com.gamingmesh.jobs.commands.list; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -34,10 +33,16 @@ public class demote implements Cmd { try { // check if player already has the job if (jPlayer.isInJob(job)) { - Integer levelsLost = Integer.parseInt(args[2]); + int levelsLost = 0; + try { + levelsLost = Integer.parseInt(args[2]); + } catch (NumberFormatException ex) { + return true; + } + Jobs.getPlayerManager().demoteJob(jPlayer, job, levelsLost); - Player player = Bukkit.getServer().getPlayer(jPlayer.getUniqueId()); + Player player = jPlayer.getPlayer(); if (player != null) { String message = Jobs.getLanguage().getMessage("command.demote.output.target", "%jobname%", job.getNameWithColor() + CMIChatColor.WHITE, diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java index 2d2e1cd2..8a63f51a 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java @@ -25,8 +25,10 @@ public class expboost implements Cmd { return true; } + int[] times = parseTime(args); + for (Job job : Jobs.getJobs()) { - job.addBoost(CurrencyType.EXP, rate, parseTime(args)); + job.addBoost(CurrencyType.EXP, rate, times); } sender.sendMessage( @@ -78,6 +80,7 @@ public class expboost implements Cmd { private int[] parseTime(String[] args) { int[] arr = new int[3]; + if (args.length < 2) { return arr; } @@ -89,7 +92,7 @@ public class expboost implements Cmd { if (time.contains("h") || time.contains("hour")) { try { - arr[2] = Integer.parseInt(time.split("h|hour")[0]); + arr[2] = Integer.parseInt(time.split("h|hour", 2)[0]); } catch (NumberFormatException e) { arr[2] = 0; } @@ -99,7 +102,7 @@ public class expboost implements Cmd { if (time.contains("m") || time.contains("minute")) { try { - arr[1] = Integer.parseInt(time.split("m|minute")[0]); + arr[1] = Integer.parseInt(time.split("m|minute", 2)[0]); } catch (NumberFormatException e) { arr[1] = 0; } @@ -109,7 +112,7 @@ public class expboost implements Cmd { if (time.contains("s") || time.contains("second")) { try { - arr[0] = Integer.parseInt(time.split("s|second")[0]); + arr[0] = Integer.parseInt(time.split("s|second", 2)[0]); } catch (NumberFormatException e) { arr[0] = 0; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java index 693e1971..efa3edf1 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java @@ -17,15 +17,14 @@ public class explored implements Cmd { return false; Player player = (Player) sender; + ExploreRegion exploreRegion = Jobs.getExplore().getWorlds().get(player.getWorld().getName()); - java.util.Map worlds = Jobs.getExplore().getWorlds(); - - if (!worlds.containsKey(player.getWorld().getName())) { + if (exploreRegion == null) { player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); return true; } - ExploreChunk chunk = worlds.get(player.getWorld().getName()).getChunk(player.getLocation().getChunk()); + ExploreChunk chunk = exploreRegion.getChunk(player.getLocation().getChunk()); if (chunk == null) { player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); return false; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/fireall.java b/src/main/java/com/gamingmesh/jobs/commands/list/fireall.java index e63da512..8cd1c209 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/fireall.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/fireall.java @@ -45,7 +45,7 @@ public class fireall implements Cmd { return true; } - if (jPlayer.getJobProgression().isEmpty()) { + if (jPlayer.progression.isEmpty()) { sender.sendMessage(Jobs.getLanguage().getMessage("command.fireall.error.nojobs")); return true; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/give.java b/src/main/java/com/gamingmesh/jobs/commands/list/give.java index 7f3e11ce..5ef59a05 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/give.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/give.java @@ -3,6 +3,7 @@ package com.gamingmesh.jobs.commands.list; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import com.gamingmesh.jobs.ItemBoostManager; import com.gamingmesh.jobs.Jobs; @@ -72,12 +73,14 @@ public class give implements Cmd { switch (name) { case items: JobItems jItem = ItemBoostManager.getItemByKey(itemName); - if (jItem == null || jItem.getItemStack(player) == null) { + ItemStack item = jItem == null ? null : jItem.getItemStack(player); + + if (item == null) { sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem")); return true; } - GiveItem.giveItemForPlayer(player, jItem.getItemStack(player)); + GiveItem.giveItemForPlayer(player, item); break; case limiteditems: if (job == null) { @@ -86,12 +89,14 @@ public class give implements Cmd { } JobLimitedItems jLItem = job.getLimitedItems().get(itemName.toLowerCase()); - if (jLItem == null || jLItem.getItemStack(player) == null) { + ItemStack limItem = jLItem == null ? null : jLItem.getItemStack(player); + + if (limItem == null) { sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem")); return true; } - GiveItem.giveItemForPlayer(player, jLItem.getItemStack(player)); + GiveItem.giveItemForPlayer(player, limItem); break; default: break; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/join.java b/src/main/java/com/gamingmesh/jobs/commands/list/join.java index 618e527c..6954228e 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/join.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/join.java @@ -65,7 +65,7 @@ public class join implements Cmd { return true; } - if (!Jobs.getPlayerManager().getJobsLimit(jPlayer, (short) jPlayer.getJobProgression().size())) { + if (!Jobs.getPlayerManager().getJobsLimit(jPlayer, (short) jPlayer.progression.size())) { pSender.sendMessage(Jobs.getLanguage().getMessage("command.join.error.maxjobs")); return true; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/limit.java b/src/main/java/com/gamingmesh/jobs/commands/list/limit.java index 369b16a6..b13db3b1 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/limit.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/limit.java @@ -55,8 +55,10 @@ public class limit implements Cmd { limit.resetLimits(type); if (limit.getLeftTime(type) > 0) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort(limit.getLeftTime(type)))); - sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "Limit", + String typeName = type.getName().toLowerCase(); + + sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + typeName + "time", "%time%", TimeManage.to24hourShort(limit.getLeftTime(type)))); + sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + typeName + "Limit", "%current%", (int) (limit.getAmount(type) * 100) / 100D, "%total%", JPlayer.getLimit(type))); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/log.java b/src/main/java/com/gamingmesh/jobs/commands/list/log.java index e874fcd5..1cd6678c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/log.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/log.java @@ -73,11 +73,10 @@ public class log implements Cmd { sender.sendMessage(Jobs.getLanguage().getMessage("command.log.output.topline", "%playername%", JPlayer.getName())); for (Log one : logList.values()) { - Map AmountList = one.getAmountList(); double totalMoney = 0, totalExp = 0, totalPoints = 0; for (String oneSorted : unsortMap.keySet()) { - for (Entry oneMap : AmountList.entrySet()) { + for (Entry oneMap : one.getAmountList().entrySet()) { if (oneMap.getKey().equalsIgnoreCase(oneSorted)) { count++; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java index ad2aad8f..e23881f4 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java @@ -25,8 +25,10 @@ public class moneyboost implements Cmd { return true; } + int[] times = parseTime(args); + for (Job job : Jobs.getJobs()) { - job.addBoost(CurrencyType.MONEY, rate, parseTime(args)); + job.addBoost(CurrencyType.MONEY, rate, times); } sender.sendMessage( @@ -78,6 +80,7 @@ public class moneyboost implements Cmd { private int[] parseTime(String[] args) { int[] arr = new int[3]; + if (args.length < 2) { return arr; } @@ -89,7 +92,7 @@ public class moneyboost implements Cmd { if (time.contains("h") || time.contains("hour")) { try { - arr[2] = Integer.parseInt(time.split("h|hour")[0]); + arr[2] = Integer.parseInt(time.split("h|hour", 2)[0]); } catch (NumberFormatException e) { arr[2] = 0; } @@ -99,7 +102,7 @@ public class moneyboost implements Cmd { if (time.contains("m") || time.contains("minute")) { try { - arr[1] = Integer.parseInt(time.split("m|minute")[0]); + arr[1] = Integer.parseInt(time.split("m|minute", 2)[0]); } catch (NumberFormatException e) { arr[1] = 0; } @@ -109,7 +112,7 @@ public class moneyboost implements Cmd { if (time.contains("s") || time.contains("second")) { try { - arr[0] = Integer.parseInt(time.split("s|second")[0]); + arr[0] = Integer.parseInt(time.split("s|second", 2)[0]); } catch (NumberFormatException e) { arr[0] = 0; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java index 23291b7d..19b3776e 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java @@ -25,8 +25,10 @@ public class pointboost implements Cmd { return true; } + int[] times = parseTime(args); + for (Job job : Jobs.getJobs()) { - job.addBoost(CurrencyType.POINTS, rate, parseTime(args)); + job.addBoost(CurrencyType.POINTS, rate, times); } sender.sendMessage( @@ -78,6 +80,7 @@ public class pointboost implements Cmd { private int[] parseTime(String[] args) { int[] arr = new int[3]; + if (args.length < 2) { return arr; } @@ -89,7 +92,7 @@ public class pointboost implements Cmd { if (time.contains("h") || time.contains("hour")) { try { - arr[2] = Integer.parseInt(time.split("h|hour")[0]); + arr[2] = Integer.parseInt(time.split("h|hour", 2)[0]); } catch (NumberFormatException e) { arr[2] = 0; } @@ -99,7 +102,7 @@ public class pointboost implements Cmd { if (time.contains("m") || time.contains("minute")) { try { - arr[1] = Integer.parseInt(time.split("m|minute")[0]); + arr[1] = Integer.parseInt(time.split("m|minute", 2)[0]); } catch (NumberFormatException e) { arr[1] = 0; } @@ -109,7 +112,7 @@ public class pointboost implements Cmd { if (time.contains("s") || time.contains("second")) { try { - arr[0] = Integer.parseInt(time.split("s|second")[0]); + arr[0] = Integer.parseInt(time.split("s|second", 2)[0]); } catch (NumberFormatException e) { arr[0] = 0; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/promote.java b/src/main/java/com/gamingmesh/jobs/commands/list/promote.java index 17965a1b..fe41846d 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/promote.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/promote.java @@ -31,7 +31,13 @@ public class promote implements Cmd { try { // check if player already has the job if (jPlayer.isInJob(job)) { - Integer levelsGained = Integer.parseInt(args[2]); + int levelsGained = -1; + try { + levelsGained = Integer.parseInt(args[2]); + } catch (NumberFormatException ex) { + return true; + } + Jobs.getPlayerManager().promoteJob(jPlayer, job, levelsGained); Player player = jPlayer.getPlayer(); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java index 18031b4b..00356919 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -44,7 +44,9 @@ public class quests implements Cmd { return true; } - if (jPlayer.getQuestProgressions().isEmpty()) { + List questProgs = jPlayer.getQuestProgressions(); + + if (questProgs.isEmpty()) { sender.sendMessage(Jobs.getLanguage().getMessage("command.quests.error.noquests")); return true; } @@ -60,7 +62,7 @@ public class quests implements Cmd { } if (stopped != null) { - for (QuestProgression q : jPlayer.getQuestProgressions()) { + for (QuestProgression q : questProgs) { q.getQuest().setStopped(stopped); } @@ -77,7 +79,7 @@ public class quests implements Cmd { return true; } - for (JobProgression jobProg : jPlayer.getJobProgression()) { + for (JobProgression jobProg : jPlayer.progression) { List list = jPlayer.getQuestProgressions(jobProg.getJob()); for (QuestProgression q : list) { @@ -97,7 +99,7 @@ public class quests implements Cmd { .replace("[time]", TimeManage.to24hourShort(q.getValidUntil() - System.currentTimeMillis())); if (current.contains("[desc]")) { - q.getQuest().getDescription().forEach(hoverList::add); + hoverList.addAll(q.getQuest().getDescription()); } else { hoverList.add(current); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/stats.java b/src/main/java/com/gamingmesh/jobs/commands/list/stats.java index 6830127c..4fbfb7cf 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/stats.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/stats.java @@ -30,9 +30,7 @@ public class stats implements Cmd { return true; } - java.util.List progressions = jPlayer.getJobProgression(); - - if (progressions.isEmpty()) { + if (jPlayer.progression.isEmpty()) { sender.sendMessage(Jobs.getLanguage().getMessage("command.stats.error.nojob")); return true; } @@ -41,7 +39,7 @@ public class stats implements Cmd { String leftClick = Jobs.getLanguage().getMessage("command.info.gui.leftClick"); - for (JobProgression jobProg : progressions) { + for (JobProgression jobProg : jPlayer.progression) { for (String msg : Jobs.getCommandManager().jobStatsMessage(jobProg).split("\n")) { new RawMessage().addText(msg).addHover(leftClick).addCommand("jobs info " + jobProg.getJob().getName()).show(sender); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java b/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java index 89f98bc0..c95d48ce 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java @@ -18,51 +18,40 @@ public class toggle implements Cmd { return false; } - if (args.length != 1) { + boolean isBossbar = false, isActionbar = false; + if (args.length != 1 || (!(isBossbar = args[0].equalsIgnoreCase("bossbar")) && !(isActionbar = args[0].equalsIgnoreCase("actionbar")))) { Jobs.getCommandManager().sendUsage(sender, "toggle"); return true; } Player player = (Player) sender; - if (!args[0].equalsIgnoreCase("bossbar") && !args[0].equalsIgnoreCase("actionbar")) { - Jobs.getCommandManager().sendUsage(sender, "toggle"); - return true; - } - String playerUUID = player.getUniqueId().toString(); - if (args[0].equalsIgnoreCase("actionbar")) { - if (ToggleBarHandling.getActionBarToggle().containsKey(playerUUID)) { - if (ToggleBarHandling.getActionBarToggle().get(playerUUID)) { - ToggleBarHandling.getActionBarToggle().put(playerUUID, false); - sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.off")); - } else { - ToggleBarHandling.getActionBarToggle().put(playerUUID, true); - sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); - } - } else { + if (isActionbar) { + Boolean ex = ToggleBarHandling.getActionBarToggle().get(playerUUID); + + if (ex == null || ex.booleanValue()) { ToggleBarHandling.getActionBarToggle().put(playerUUID, false); sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.off")); + } else { + ToggleBarHandling.getActionBarToggle().put(playerUUID, true); + sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); } } - if (args[0].equalsIgnoreCase("bossbar")) { - if (ToggleBarHandling.getBossBarToggle().containsKey(playerUUID)) { - if (ToggleBarHandling.getBossBarToggle().get(playerUUID)) { - ToggleBarHandling.getBossBarToggle().put(playerUUID, false); - sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.off")); + if (isBossbar) { + Boolean ex = ToggleBarHandling.getBossBarToggle().get(playerUUID); - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player.getUniqueId()); - if (jPlayer != null) - jPlayer.hideBossBars(); - - } else { - ToggleBarHandling.getBossBarToggle().put(playerUUID, true); - sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); - } - } else { + if (ex == null || ex.booleanValue()) { ToggleBarHandling.getBossBarToggle().put(playerUUID, false); sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.off")); + + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player.getUniqueId()); + if (jPlayer != null) + jPlayer.hideBossBars(); + } else { + ToggleBarHandling.getBossBarToggle().put(playerUUID, true); + sender.sendMessage(Jobs.getLanguage().getMessage("command.toggle.output.on")); } } diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index ec328ff6..c812c21d 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -938,6 +938,9 @@ public class ConfigManager { for (String str4 : guiSection.getStringList("Enchantments")) { String[] id = str4.split(":", 2); + if (id.length < 2) + continue; + Enchantment enchant = CMIEnchantment.getEnchantment(id[0]); if (enchant == null) continue; diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index bb93619f..0f8a920c 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -912,34 +912,36 @@ public class GeneralConfigManager { List fwColors = c.get("Fireworks.LevelUp.colors", Arrays.asList("230,0,0", "0,90,0", "0,0,104")); - Color[] colors = new Color[fwColors.size()]; - Pattern comma = Pattern.compile(",", 16); + if (!UseRandom) { + Color[] colors = new Color[fwColors.size()]; + Pattern comma = Pattern.compile(",", 16); - for (int s = 0; s < colors.length; s++) { - String[] sSplit = comma.split(fwColors.get(s)); - if (sSplit.length < 3) - continue; + for (int s = 0; s < colors.length; s++) { + String[] sSplit = comma.split(fwColors.get(s)); + if (sSplit.length < 3) + continue; - int[] colorRGB = new int[3]; - for (int i = 0; i < 3; i++) { - try { - int parsed = Integer.parseInt(sSplit[i]); - colorRGB[i] = (parsed > 255 || parsed < 0) ? 1 : parsed; - } catch (NumberFormatException e) { + int[] colorRGB = new int[3]; + for (int i = 0; i < 3; i++) { + try { + int parsed = Integer.parseInt(sSplit[i]); + colorRGB[i] = (parsed > 255 || parsed < 0) ? 1 : parsed; + } catch (NumberFormatException e) { + } } + + colors[s] = Color.fromRGB(colorRGB[0], colorRGB[1], colorRGB[2]); } - colors[s] = Color.fromRGB(colorRGB[0], colorRGB[1], colorRGB[2]); + fireworkEffect = FireworkEffect.builder() + .flicker(useFlicker) + .trail(useTrail) + .with(fwType) + .withColor(colors) + .withFade(colors) + .build(); } - fireworkEffect = FireworkEffect.builder() - .flicker(useFlicker) - .trail(useTrail) - .with(fwType) - .withColor(colors) - .withFade(colors) - .build(); - FireworkPower = c.get("Fireworks.LevelUp.power", 1); c.addComment("Fireworks.LevelUp.ShootTime", "Fire shooting time in ticks.", "20 tick = 1 second"); ShootTime = c.get("Fireworks.LevelUp.ShootTime", 20); diff --git a/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java b/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java index 9e01296d..d9cb6052 100644 --- a/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java +++ b/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java @@ -33,7 +33,7 @@ public class BlockProtection { this.z = z; } - public Long getTime() { + public long getTime() { return deconvert(time); } @@ -41,11 +41,11 @@ public class BlockProtection { return time == -1L ? -1 : (int) ((time - pre) / 1000L); } - private static Long deconvert(Integer time) { + private static long deconvert(Integer time) { return time == null ? -1L : ((time.longValue() * 1000L) + pre); } - public void setTime(Long time) { + public void setTime(long time) { this.time = time == -1 ? null : convert(time); this.recorded = convert(System.currentTimeMillis()); } @@ -60,19 +60,19 @@ public class BlockProtection { this.action = action; } - public Long getRecorded() { + public long getRecorded() { return deconvert(recorded); } - public Boolean isPaid() { - return paid == null ? true : paid; + public boolean isPaid() { + return paid == null ? true : paid.booleanValue(); } - public void setPaid(Boolean paid) { + public void setPaid(boolean paid) { this.paid = !paid ? paid : null; } - public void setRecorded(Long recorded) { + public void setRecorded(long recorded) { this.recorded = convert(recorded); } diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index 1e884cd0..41eb367a 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -96,10 +96,12 @@ public class BufferedEconomy { // combine all payments using paymentCache while (!payments.isEmpty()) { BufferedPayment payment = payments.remove(); - totalAmount += payment.get(CurrencyType.MONEY); + double money = payment.get(CurrencyType.MONEY); + + totalAmount += money; if (Jobs.getGCManager().UseTaxes) { - taxesAmount += payment.get(CurrencyType.MONEY) * (Jobs.getGCManager().TaxesAmount / 100.0); + taxesAmount += money * (Jobs.getGCManager().TaxesAmount / 100.0); } OfflinePlayer offPlayer = payment.getOfflinePlayer(); @@ -108,7 +110,6 @@ public class BufferedEconomy { BufferedPayment existing = paymentCache.get(offPlayer.getUniqueId()); if (existing != null) { - double money = payment.get(CurrencyType.MONEY); double points = payment.get(CurrencyType.POINTS); double exp = payment.get(CurrencyType.EXP); @@ -133,7 +134,6 @@ public class BufferedEconomy { existing.set(CurrencyType.POINTS, existing.get(CurrencyType.POINTS) + points); existing.set(CurrencyType.EXP, existing.get(CurrencyType.EXP) + exp); } else { - double money = payment.get(CurrencyType.MONEY); double points = payment.get(CurrencyType.POINTS); if (Jobs.getGCManager().TakeFromPlayersPayment && Jobs.getGCManager().UseTaxes && @@ -213,7 +213,7 @@ public class BufferedEconomy { // Show players payment stuff showPayment(payment); - if (payment.getOfflinePlayer().isOnline() && Version.getCurrent().isHigher(Version.v1_8_R3)) { + if (Version.getCurrent().isHigher(Version.v1_8_R3) && payment.getOfflinePlayer().isOnline()) { Jobs.getBBManager().ShowJobProgression(Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId())); } } diff --git a/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4Listener.java b/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4Listener.java index 30ca0495..c7ebe594 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4Listener.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/MythicMobs/MythicMobs4Listener.java @@ -15,10 +15,10 @@ import com.gamingmesh.jobs.listeners.JobsPaymentListener; import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent; import io.lumine.xikage.mythicmobs.mobs.MythicMob; -public class MythicMobs4Listener implements Listener { +public final class MythicMobs4Listener implements Listener { @EventHandler - public void OnMythicMobDeath(MythicMobDeathEvent event) { + public void onMythicMobDeath(MythicMobDeathEvent event) { // Entity that died must be living if (!(event.getEntity() instanceof LivingEntity)) return; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index b62cd4bb..8188694b 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -984,10 +984,7 @@ public class JobsPaymentListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryMoveItemEventToFurnace(InventoryMoveItemEvent event) { - if (!Jobs.getGCManager().PreventHopperFillUps) - return; - - if (event.getItem().getType() == Material.AIR) + if (!Jobs.getGCManager().PreventHopperFillUps || event.getItem().getType() == Material.AIR) return; String type = event.getDestination().getType().toString(); @@ -1075,10 +1072,10 @@ public class JobsPaymentListener implements Listener { return; Entity ent = event.getEntity(); - if (ent instanceof Player || !(event instanceof EntityDamageByEntityEvent)) + if (ent instanceof Player || !(ent instanceof Damageable) || !(event instanceof EntityDamageByEntityEvent)) return; - if (!(((EntityDamageByEntityEvent) event).getDamager() instanceof Player) || !(ent instanceof Damageable)) + if (!(((EntityDamageByEntityEvent) event).getDamager() instanceof Player)) return; double damage = event.getFinalDamage(); @@ -1272,13 +1269,13 @@ public class JobsPaymentListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onHangingPlaceEvent(HangingPlaceEvent event) { - if (!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) - return; - Player player = event.getPlayer(); if (player == null || !player.isOnline()) return; + if (!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) + return; + // check if in creative if (!payIfCreative(player)) return; diff --git a/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java b/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java index 33260200..7c3054a2 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java @@ -52,8 +52,11 @@ public class ToggleBarHandling { public static void save() { YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml"); - if (f.exists() && f.getConfigFile().length() == 0L && bossBarToggle.isEmpty() && actionBarToggle.isEmpty()) { - f.getConfigFile().delete(); + if (bossBarToggle.isEmpty() && actionBarToggle.isEmpty()) { + if (f.exists() && f.getConfigFile().length() == 0L) { + f.getConfigFile().delete(); + } + return; } diff --git a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java index 3c1feb35..f8819a30 100644 --- a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java +++ b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java @@ -40,8 +40,12 @@ public class BufferedPaymentTask implements Runnable { public void run() { double money = payment.get(CurrencyType.MONEY); if (money > 0) { - org.bukkit.Bukkit.getScheduler().runTaskLater(bufferedEconomy.getPlugin(), () -> - economy.depositPlayer(payment.getOfflinePlayer(), money), 1L); + if (Jobs.getGCManager().isEconomyAsync()) { + org.bukkit.Bukkit.getScheduler().runTaskLater(bufferedEconomy.getPlugin(), () -> + economy.depositPlayer(payment.getOfflinePlayer(), money), 1L); + } else { + economy.depositPlayer(payment.getOfflinePlayer(), money); + } } else if (!economy.withdrawPlayer(payment.getOfflinePlayer(), -money)) { bufferedEconomy.pay(payment); }