From ee21d95a4347316c642029cdfa9a2ce86dedf985 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Thu, 8 Oct 2020 21:02:36 +0200 Subject: [PATCH] Lowercase some method names in paymentData --- .../gamingmesh/jobs/CMILib/CMIMaterial.java | 2 +- .../jobs/Placeholders/Placeholder.java | 4 +- .../com/gamingmesh/jobs/Signs/SignUtil.java | 2 +- .../com/gamingmesh/jobs/Signs/jobsSign.java | 6 +- .../gamingmesh/jobs/commands/list/limit.java | 6 +- .../gamingmesh/jobs/container/JobsPlayer.java | 18 ++-- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 12 +-- .../jobs/economy/BufferedEconomy.java | 24 ++--- .../gamingmesh/jobs/economy/PaymentData.java | 101 ++++++++---------- .../jobs/hooks/McMMO/McMMO1_X_listener.java | 10 +- .../hooks/WorldGuard/WorldGuardManager.java | 30 +++--- .../jobs/listeners/JobsListener.java | 34 ++---- .../jobs/listeners/JobsPaymentListener.java | 60 +++-------- .../java/com/gamingmesh/jobs/stuff/Util.java | 2 +- 14 files changed, 114 insertions(+), 197 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java index 5f1f3993..08188a0e 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java @@ -2657,7 +2657,7 @@ public enum CMIMaterial { } public boolean equals(Material mat) { - return getMaterial() != null && getMaterial() == mat; + return getMaterial() == mat; } public List getLegacyNames() { diff --git a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java index 5baf317a..e104963f 100644 --- a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java +++ b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java @@ -456,10 +456,10 @@ public class Placeholder { return Integer.toString(user.getLimit(t)); case plimit_$1: t = CurrencyType.getByName(vals.get(0)); - return Double.toString(user.getPaymentLimit().GetAmount(t)); + return Double.toString(user.getPaymentLimit().getAmount(t)); case plimit_tleft_$1: t = CurrencyType.getByName(vals.get(0)); - return TimeManage.to24hourShort(user.getPaymentLimit().GetLeftTime(t)); + return TimeManage.to24hourShort(user.getPaymentLimit().getLeftTime(t)); case user_jlevel_$1: return j == null ? "0" : Integer.toString(j.getLevel()); case user_jexp_$1: diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index 32a95813..ba3188ba 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -351,7 +351,7 @@ public class SignUtil { return; Skull skull = (Skull) b.getState(); - if (skull.getOwner() != null && skull.getOwner().equalsIgnoreCase(Playername)) + if (Playername.equalsIgnoreCase(skull.getOwner())) return; skull.setOwner(Playername); diff --git a/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java index b6ded4a4..739bc0d1 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java @@ -81,9 +81,7 @@ public class jobsSign { } public static String locToBlockString(Location loc) { - if (loc == null) - return ""; - return loc.getWorld().getName() + ";" + loc.getBlockX() + ";" + loc.getBlockY() + ";" + loc.getBlockZ(); + return loc == null ? "" : loc.getWorld().getName() + ";" + loc.getBlockX() + ";" + loc.getBlockY() + ";" + loc.getBlockZ(); } public void setLoc(Location loc) { @@ -101,7 +99,7 @@ public class jobsSign { if (!string.contains(";")) return; - String[] split = string.replace(",", ".").split(";"); + String[] split = string.replace(',', '.').split(";"); int x = 0, y = 0, z = 0; 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 24e9a915..2d1122dc 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/limit.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/limit.java @@ -60,10 +60,10 @@ public class limit implements Cmd { "%total%", JPlayer.getLimit(type))); continue; } - if (limit.GetLeftTime(type) > 0) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort(limit.GetLeftTime(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", - "%current%", (int) (limit.GetAmount(type) * 100) / 100D, + "%current%", (int) (limit.getAmount(type) * 100) / 100D, "%total%", JPlayer.getLimit(type))); } } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 536435c4..4669786c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -25,6 +25,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; +import java.util.stream.Collectors; import java.util.UUID; import org.bukkit.Bukkit; @@ -161,7 +162,7 @@ public class JobsPlayer { return true; PaymentData data = getPaymentLimit(); Integer value = limits.get(type); - if (data.IsReachedLimit(type, value == null ? 0 : value)) { + if (data.isReachedLimit(type, value == null ? 0 : value)) { String name = type.getName().toLowerCase(); if (player.isOnline() && !data.isInformed() && !data.isReseted()) { @@ -173,15 +174,15 @@ public class JobsPlayer { player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + name + "limit")); player.sendMessage(Jobs.getLanguage().getMessage("command.limit.output.reached" + name + "limit2")); } - data.setInformed(); + data.setInformed(true); } - if (data.IsAnnounceTime(limit.getAnnouncementDelay()) && player.isOnline()) - ActionBarManager.send(player, Jobs.getLanguage().getMessage("command.limit.output." + name + "time", "%time%", TimeManage.to24hourShort(data.GetLeftTime(type)))); + if (data.isAnnounceTime(limit.getAnnouncementDelay()) && player.isOnline()) + ActionBarManager.send(player, Jobs.getLanguage().getMessage("command.limit.output." + name + "time", "%time%", TimeManage.to24hourShort(data.getLeftTime(type)))); if (data.isReseted()) data.setReseted(false); return false; } - data.AddAmount(type, amount); + data.addAmount(type, amount); return true; } @@ -1067,10 +1068,7 @@ public class JobsPlayer { } } - List pr = new ArrayList<>(); - tmp.values().forEach(pr::add); - - return pr; + return tmp.values().stream().collect(Collectors.toList()); } public String getQuestProgressionString() { @@ -1203,7 +1201,7 @@ public class JobsPlayer { public int getMaxBrewingStandsAllowed() { Double maxV = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxbrewingstands"); - if (maxV == null || maxV == 0) + if (maxV == 0) maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault(); return maxV.intValue(); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index be1ccf92..40a3ee7c 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1281,15 +1281,15 @@ public abstract class JobsDAO { for (CurrencyType type : CurrencyType.values()) { if (limit == null) continue; - if (limit.GetAmount(type) == 0D) + if (limit.getAmount(type) == 0D) continue; - if (limit.GetLeftTime(type) < 0) + if (limit.getLeftTime(type) < 0) continue; prest.setInt(1, jPlayer.getUserId()); prest.setInt(2, type.getId()); - prest.setDouble(3, limit.GetAmount(type)); - prest.setLong(4, limit.GetTime(type)); + prest.setDouble(3, limit.getAmount(type)); + prest.setLong(4, limit.getTime(type)); prest.setString(5, type.toString()); prest.addBatch(); } @@ -1333,7 +1333,7 @@ public abstract class JobsDAO { if (type == null) continue; - data.AddNewAmount(type, res.getDouble(LimitTableFields.collected.getCollumn()), res.getLong(LimitTableFields.started.getCollumn())); + data.addNewAmount(type, res.getDouble(LimitTableFields.collected.getCollumn()), res.getLong(LimitTableFields.started.getCollumn())); } } catch (SQLException e) { e.printStackTrace(); @@ -1372,7 +1372,7 @@ public abstract class JobsDAO { if (type == null) continue; - data.AddNewAmount(type, res.getDouble(LimitTableFields.collected.getCollumn()), res.getLong(LimitTableFields.started.getCollumn())); + data.addNewAmount(type, res.getDouble(LimitTableFields.collected.getCollumn()), res.getLong(LimitTableFields.started.getCollumn())); map.put(id, data); } } catch (SQLException e) { diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index 03eb5110..4f932b76 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -207,31 +207,25 @@ public class BufferedEconomy { } public void ShowActionBar(BufferedPayment payment) { - if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline()) + if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline() + || !Jobs.getGCManager().ActionBarsMessageByDefault || !payment.containsPayment()) return; - if (!Jobs.getGCManager().ActionBarsMessageByDefault) - return; - - if (!payment.containsPayment()) - return; - - String playerUUID = payment.getOfflinePlayer().getUniqueId().toString(); - - Boolean show = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID, true); - Player abp = Bukkit.getPlayer(payment.getOfflinePlayer().getUniqueId()); - if ((abp != null) && (show.booleanValue())) { + UUID playerUUID = payment.getOfflinePlayer().getUniqueId(); + Boolean show = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID.toString(), true); + Player abp = Bukkit.getPlayer(playerUUID); + if (abp != null && show.booleanValue()) { String Message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main"); if (payment.get(CurrencyType.MONEY) != 0D) { - Message = Message + " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), + Message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), payment.get(CurrencyType.MONEY))); } if (payment.get(CurrencyType.POINTS) != 0D) { - Message = Message + " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(), + Message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(), payment.get(CurrencyType.POINTS))); } if (payment.get(CurrencyType.EXP) != 0D) { - Message = Message + " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(), + Message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(), payment.get(CurrencyType.EXP))); } ActionBarManager.send(abp, Message); diff --git a/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java b/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java index 6f3da65d..7a339289 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java +++ b/src/main/java/com/gamingmesh/jobs/economy/PaymentData.java @@ -8,10 +8,12 @@ import com.gamingmesh.jobs.container.CurrencyType; public class PaymentData { private Long lastAnnouced = 0L; - private HashMap payments = new HashMap<>(); - private HashMap paymentsTimes = new HashMap<>(); - private boolean Informed = false; - private boolean Reseted = false; + + private final HashMap payments = new HashMap<>(); + private final HashMap paymentsTimes = new HashMap<>(); + + private boolean informed = false; + private boolean reseted = false; public PaymentData(Long time, Double Payment, Double Points, Double Exp, Long lastAnnouced, boolean Informed) { paymentsTimes.put(CurrencyType.EXP, time); @@ -20,127 +22,114 @@ public class PaymentData { payments.put(CurrencyType.EXP, Exp); payments.put(CurrencyType.MONEY, Payment); payments.put(CurrencyType.POINTS, Points); + this.lastAnnouced = lastAnnouced; - this.Informed = Informed; + this.informed = Informed; } public PaymentData(CurrencyType type, Double amount) { paymentsTimes.put(type, System.currentTimeMillis()); payments.put(type, amount); + this.lastAnnouced = 0L; - this.Informed = false; + this.informed = false; } public PaymentData() { resetLimits(); } - public Long GetTime(CurrencyType type) { + public Long getTime(CurrencyType type) { return paymentsTimes.get(type); } - public void setReseted(boolean Reseted) { - this.Reseted = Reseted; + public void setReseted(boolean reseted) { + this.reseted = reseted; } public boolean isReseted() { - return Reseted; + return reseted; } - public Double GetAmount(CurrencyType type) { - if (!payments.containsKey(type)) - return 0D; - return (int) (payments.get(type) * 100) / 100D; + public Double getAmount(CurrencyType type) { + return !payments.containsKey(type) ? 0D : (int) (payments.get(type) * 100) / 100D; } - public Double GetAmountBylimit(CurrencyType type, int limit) { - if (GetAmount(type) > limit) - return (double) limit; - return (int) (GetAmount(type) * 100) / 100D; + public Double getAmountBylimit(CurrencyType type, int limit) { + return getAmount(type) > limit ? (double) limit : (int) (getAmount(type) * 100) / 100D; } - public Long GetLastAnnounced() { + public Long getLastAnnounced() { return lastAnnouced; } - public boolean IsAnnounceTime(int t) { - if (this.lastAnnouced + (t * 1000) > System.currentTimeMillis()) + public boolean isAnnounceTime(int t) { + if (lastAnnouced + (t * 1000) > System.currentTimeMillis()) return false; - SetAnnouncmentTime(); + + setAnnouncementTime(); return true; } - public void SetAnnouncmentTime() { + public void setAnnouncementTime() { this.lastAnnouced = System.currentTimeMillis(); } - public void AddNewAmount(CurrencyType type, Double Payment) { - AddNewAmount(type, Payment, null); + public void addNewAmount(CurrencyType type, Double Payment) { + addNewAmount(type, Payment, null); } - public void AddNewAmount(CurrencyType type, Double Payment, Long time) { + public void addNewAmount(CurrencyType type, Double Payment, Long time) { paymentsTimes.put(type, time == null ? System.currentTimeMillis() : time); payments.put(type, Payment); } - public void setInformed() { - this.Informed = true; - } - - public void setNotInformed() { - this.Informed = false; - } - - public void AddAmount(CurrencyType type, Double Payment) { + public void addAmount(CurrencyType type, Double Payment) { payments.put(type, payments.get(type) + Payment); } - public long GetLeftTime(CurrencyType type) { + public long getLeftTime(CurrencyType type) { long left = 0; - if (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) - left = (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) - System.currentTimeMillis()); + if (getTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) + left = (getTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) - System.currentTimeMillis()); return left; } - public boolean IsOverLimit(CurrencyType type, int limit) { - if (this.payments.get(type) < limit) + public boolean isOverLimit(CurrencyType type, int limit) { + if (payments.get(type) < limit) return false; return true; } public double percentOverLimit(CurrencyType type, int limit) { - return ((this.payments.get(type) / limit) - 1) * 100; + return ((payments.get(type) / limit) - 1) * 100; } - public boolean IsOverTimeLimit(CurrencyType type) { - if (this.GetTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) + public boolean isOverTimeLimit(CurrencyType type) { + if (getTime(type) + (Jobs.getGCManager().getLimit(type).getTimeLimit() * 1000) > System.currentTimeMillis()) return false; - if (this.Informed) - this.Informed = false; + if (informed) + informed = false; resetLimits(); return true; } public void resetLimits() { for (CurrencyType type : CurrencyType.values()) { - AddNewAmount(type, 0D); + addNewAmount(type, 0D); } - this.Reseted = true; + reseted = true; } - public boolean IsReachedLimit(CurrencyType type, int money) { - if (IsOverTimeLimit(type)) - return true; - if (IsOverLimit(type, money)) - return true; - return false; + public boolean isReachedLimit(CurrencyType type, int money) { + return isOverTimeLimit(type) || isOverLimit(type, money); } public boolean isInformed() { - return Informed; + return informed; } - public void setInformed(boolean Informed) { - this.Informed = Informed; + public void setInformed(boolean informed) { + this.informed = informed; } } diff --git a/src/main/java/com/gamingmesh/jobs/hooks/McMMO/McMMO1_X_listener.java b/src/main/java/com/gamingmesh/jobs/hooks/McMMO/McMMO1_X_listener.java index 426a06bb..f484a32d 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/McMMO/McMMO1_X_listener.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/McMMO/McMMO1_X_listener.java @@ -2,7 +2,6 @@ package com.gamingmesh.jobs.hooks.McMMO; import java.util.HashMap; -import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -50,10 +49,7 @@ public class McMMO1_X_listener implements Listener { if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle()) return; - if (!JobsPaymentListener.payForItemDurabilityLoss(player)) - return; - - if (event.getTreasure() == null) + if (!JobsPaymentListener.payForItemDurabilityLoss(player) || event.getTreasure() == null) return; JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); @@ -71,7 +67,7 @@ public class McMMO1_X_listener implements Listener { Player player = event.getPlayer(); //disabling plugin in world - if (player == null || !Jobs.getGCManager().canPerformActionInWorld(player.getWorld())) + if (!Jobs.getGCManager().canPerformActionInWorld(player.getWorld())) return; ItemStack resultStack = event.getRepairedObject(); @@ -82,7 +78,7 @@ public class McMMO1_X_listener implements Listener { return; // check if in creative - if (player.getGameMode().equals(GameMode.CREATIVE) && !player.hasPermission("jobs.paycreative") && !Jobs.getGCManager().payInCreative()) + if (!JobsPaymentListener.payIfCreative(player)) return; JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); diff --git a/src/main/java/com/gamingmesh/jobs/hooks/WorldGuard/WorldGuardManager.java b/src/main/java/com/gamingmesh/jobs/hooks/WorldGuard/WorldGuardManager.java index bbe64070..c1f9bfc1 100644 --- a/src/main/java/com/gamingmesh/jobs/hooks/WorldGuard/WorldGuardManager.java +++ b/src/main/java/com/gamingmesh/jobs/hooks/WorldGuard/WorldGuardManager.java @@ -3,7 +3,6 @@ package com.gamingmesh.jobs.hooks.WorldGuard; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -38,17 +37,15 @@ public class WorldGuardManager { if (useOld) { ApplicableRegionSet regions = wg.getRegionContainer().get(loc.getWorld()).getApplicableRegions(loc); for (ProtectedRegion one : regions.getRegions()) { - if (!Jobs.getRestrictedAreaManager().isExist(one.getId())) - continue; - return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId()); + if (Jobs.getRestrictedAreaManager().isExist(one.getId())) + return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId()); } } else { RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionManager regions = container.get(BukkitAdapter.adapt(loc.getWorld())); for (ProtectedRegion one : regions.getRegions().values()) { - if (!Jobs.getRestrictedAreaManager().isExist(one.getId())) - continue; - return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId()); + if (Jobs.getRestrictedAreaManager().isExist(one.getId())) + return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId()); } } } catch (Throwable e) { @@ -61,17 +58,15 @@ public class WorldGuardManager { if (useOld) { ApplicableRegionSet regions = wg.getRegionContainer().get(loc.getWorld()).getApplicableRegions(loc); for (ProtectedRegion one : regions.getRegions()) { - if (!one.getId().equalsIgnoreCase(name) || !one.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) - continue; - return true; + if (one.getId().equalsIgnoreCase(name) && one.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) + return true; } } else { RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); RegionManager regions = container.get(BukkitAdapter.adapt(loc.getWorld())); for (ProtectedRegion one : regions.getRegions().values()) { - if (!one.getId().equalsIgnoreCase(name) || !one.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) - continue; - return true; + if (one.getId().equalsIgnoreCase(name) && one.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) + return true; } } return false; @@ -79,17 +74,16 @@ public class WorldGuardManager { public String getNameByName(String name) { for (World one : Bukkit.getWorlds()) { - Map regions = null; + Map regions; if (useOld) { regions = wg.getRegionContainer().get(one).getRegions(); } else { RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); regions = container.get(BukkitAdapter.adapt(one)).getRegions(); } - for (Entry oneR : regions.entrySet()) { - if (!oneR.getKey().equalsIgnoreCase(name)) - continue; - return oneR.getKey(); + for (String oneR : regions.keySet()) { + if (oneR.equalsIgnoreCase(name)) + return oneR; } } return null; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index c52bf696..cf58b851 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -97,10 +97,7 @@ public class JobsListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) public void AsyncPlayerChatEvent(final AsyncPlayerChatEvent event) { - if (event.isCancelled()) - return; - - if (Util.getJobsEditorMap().isEmpty()) + if (event.isCancelled() || Util.getJobsEditorMap().isEmpty()) return; final Player player = event.getPlayer(); @@ -133,10 +130,7 @@ public class JobsListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onSelection(PlayerInteractEvent event) { - if (event.getClickedBlock() == null) - return; - - if (event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_BLOCK) + if (event.getClickedBlock() == null || event.getAction() != Action.LEFT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; Player player = event.getPlayer(); @@ -147,10 +141,7 @@ public class JobsListener implements Listener { if (iih.getType() != CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getMaterial()) return; - if (!Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld())) - return; - - if (!player.hasPermission("jobs.area.select")) + if (!Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld()) || !player.hasPermission("jobs.area.select")) return; if (player.getGameMode() == GameMode.CREATIVE) @@ -218,10 +209,7 @@ public class JobsListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSignInteract(PlayerInteractEvent event) { - if (!Jobs.getGCManager().SignsEnabled) - return; - - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + if (!Jobs.getGCManager().SignsEnabled || event.getAction() != Action.RIGHT_CLICK_BLOCK) return; Block block = event.getClickedBlock(); @@ -396,7 +384,7 @@ public class JobsListener implements Listener { JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; - if (honorific.equalsIgnoreCase(" ")) + if (honorific.equals(" ")) honorific = ""; String format = event.getFormat(); @@ -412,7 +400,7 @@ public class JobsListener implements Listener { JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; - if (honorific.equalsIgnoreCase(" ")) + if (honorific.equals(" ")) honorific = ""; String format = event.getFormat(); @@ -431,7 +419,7 @@ public class JobsListener implements Listener { JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; - if (honorific.equalsIgnoreCase(" ")) + if (honorific.equals(" ")) honorific = ""; String format = event.getFormat(); @@ -489,9 +477,8 @@ public class JobsListener implements Listener { } String meinOk = null; - List prog = JPlayer.getJobProgression(); - mein: for (JobProgression one : prog) { + mein: for (JobProgression one : JPlayer.getJobProgression()) { for (JobLimitedItems oneItem : one.getJob().getLimitedItems().values()) { if (one.getLevel() >= oneItem.getLevel()) continue; @@ -535,10 +522,7 @@ public class JobsListener implements Listener { @EventHandler public void onChunkChangeMove(PlayerMoveEvent event) { - if (event.isCancelled()) - return; - - if (!event.getPlayer().isOnline()) + if (event.isCancelled() || !event.getPlayer().isOnline()) return; //disabling plugin in world diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 522291ab..3e5be6e7 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -232,9 +232,6 @@ public class JobsPaymentListener implements Listener { // pay JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return; - if (!Jobs.isPlayerHaveAction(jPlayer, ActionType.MILK)) { return; } @@ -414,18 +411,14 @@ public class JobsPaymentListener implements Listener { return; } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return; - - Jobs.action(jPlayer, bInfo, block); + Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), bInfo, block); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { // A tool should not trigger a BlockPlaceEvent (fixes stripping logs bug #940) if (CMIMaterial.get(event.getItemInHand().getType()).isTool()) - return; + return; Block block = event.getBlock(); @@ -464,11 +457,7 @@ public class JobsPaymentListener implements Listener { return; } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return; - - Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.PLACE), block); + Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), new BlockActionInfo(block, ActionType.PLACE), block); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -1070,11 +1059,7 @@ public class JobsPaymentListener implements Listener { if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle()) return; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return; - - Jobs.action(jPlayer, new ItemActionInfo(event.getResult(), ActionType.SMELT)); + Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), new ItemActionInfo(event.getResult(), ActionType.SMELT)); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @@ -1297,11 +1282,7 @@ public class JobsPaymentListener implements Listener { if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle()) return; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return; - - Jobs.action(jPlayer, new EntityActionInfo(event.getEntity(), ActionType.PLACE)); + Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), new EntityActionInfo(event.getEntity(), ActionType.PLACE)); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -1328,11 +1309,7 @@ public class JobsPaymentListener implements Listener { if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle()) return; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return; - - Jobs.action(jPlayer, new EntityActionInfo(event.getEntity(), ActionType.BREAK)); + Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), new EntityActionInfo(event.getEntity(), ActionType.BREAK)); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -1380,11 +1357,7 @@ public class JobsPaymentListener implements Listener { if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle()) return; - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return; - - Jobs.action(jPlayer, new EntityActionInfo(ent, ActionType.PLACE)); + Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), new EntityActionInfo(ent, ActionType.PLACE)); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -1419,11 +1392,7 @@ public class JobsPaymentListener implements Listener { return; // pay - JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager); - if (jDamager == null) - return; - - Jobs.action(jDamager, new EntityActionInfo(ent, ActionType.BREAK), e.getDamager()); + Jobs.action(Jobs.getPlayerManager().getJobsPlayer(pDamager), new EntityActionInfo(ent, ActionType.BREAK), e.getDamager()); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -1487,10 +1456,7 @@ public class JobsPaymentListener implements Listener { return; // pay - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) - return; - Jobs.action(jPlayer, new EntityActionInfo(animal, ActionType.BREED)); + Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), new EntityActionInfo(animal, ActionType.BREED)); } } @@ -1698,7 +1664,7 @@ public class JobsPaymentListener implements Listener { } } else if (Version.isCurrentEqualOrHigher(Version.v1_13_R1) && block.getType().toString().startsWith("STRIPPED_") && - event.getAction() == Action.RIGHT_CLICK_BLOCK) { + event.getAction() == Action.RIGHT_CLICK_BLOCK && jPlayer != null) { ItemStack iih = Jobs.getNms().getItemInMainHand(p); if (iih.getType().toString().endsWith("_AXE")) { // check if player is riding @@ -1710,10 +1676,8 @@ public class JobsPaymentListener implements Listener { - Jobs.getNms().getDurability(iih) != iih.getType().getMaxDurability()) return; - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { - if (jPlayer != null) - Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.STRIPLOGS), block); - }, 1); + Bukkit.getScheduler().runTaskLater(plugin, () -> + Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.STRIPLOGS), block), 3); } } } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Util.java b/src/main/java/com/gamingmesh/jobs/stuff/Util.java index c3a0a969..81ee0d0f 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Util.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Util.java @@ -226,7 +226,7 @@ public class Util { JarEntry entry = en.nextElement(); String entryName = entry.getName(); - packageName = packageName.replace(".", "/"); + packageName = packageName.replace('.', '/'); if (entryName != null && entryName.endsWith("." + fileType) && entryName.startsWith(packageName)) { String name = entryName.replace(packageName, "").replace("." + fileType, "").replace("/", "");