From 70ba4ec203a0c6b8ac28397a27b7a36dc2bd9927 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Tue, 1 Jun 2021 21:14:52 +0200 Subject: [PATCH] Misc improvements --- .../gamingmesh/jobs/PermissionManager.java | 9 +++-- .../jobs/Placeholders/Placeholder.java | 14 +++----- .../jobs/commands/list/expboost.java | 14 ++++---- .../jobs/commands/list/explored.java | 9 +++-- .../gamingmesh/jobs/commands/list/info.java | 8 ++--- .../jobs/commands/list/itembonus.java | 17 +++++---- .../jobs/commands/list/iteminfo.java | 11 +++--- .../gamingmesh/jobs/commands/list/join.java | 3 +- .../jobs/commands/list/moneyboost.java | 14 ++++---- .../jobs/commands/list/placeholders.java | 2 -- .../jobs/commands/list/playerinfo.java | 10 ++---- .../jobs/commands/list/pointboost.java | 14 ++++---- .../jobs/commands/list/skipquest.java | 13 +++---- .../gamingmesh/jobs/container/JobsPlayer.java | 2 +- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 11 +++--- .../jobs/listeners/JobsPayment14Listener.java | 1 - .../jobs/listeners/JobsPaymentListener.java | 35 ++++++++----------- 17 files changed, 91 insertions(+), 96 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/PermissionManager.java b/src/main/java/com/gamingmesh/jobs/PermissionManager.java index 1a60d955..358093da 100644 --- a/src/main/java/com/gamingmesh/jobs/PermissionManager.java +++ b/src/main/java/com/gamingmesh/jobs/PermissionManager.java @@ -72,18 +72,23 @@ public class PermissionManager { private static List remade(String perm) { List perms = new ArrayList<>(); + for (Job oneJ : Jobs.getJobs()) { String t = perm; + if (t.contains("%JOBNAME%")) t = t.replace("%JOBNAME%", oneJ.getName().toLowerCase()); - if (t.contains("%AMOUNT%")) - t = t.replace("%AMOUNT%", ""); + + t = t.replace("%AMOUNT%", ""); + perms.add(t); } + if (perm.contains("%WORLDNAME%")) for (World oneJ : Bukkit.getWorlds()) { perms.add(perm.replace("%WORLDNAME%", oneJ.getName().toLowerCase())); } + return perms; } diff --git a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java index e856fe03..d482f7e9 100644 --- a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java +++ b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java @@ -84,13 +84,12 @@ public class Placeholder { user_archived_jobs_exp_$1("jname/number"), maxjobs, + total_workers, limit_$1("money/exp/points"), plimit_$1("money/exp/points"), plimit_tleft_$1("money/exp/points"), - total_workers, - name_$1("jname/number"), shortname_$1("jname/number"), chatcolor_$1("jname/number"), @@ -105,7 +104,6 @@ public class Placeholder { private String[] vars; private List groups = new ArrayList<>(); private ChatFilterRule rule; - private boolean hidden = false; JobsPlaceHolders(String... vars) { Matcher matcher = numericalRule.getMatcher(toString()); @@ -126,7 +124,6 @@ public class Placeholder { } this.vars = vars; - this.hidden = false; } public static JobsPlaceHolders getByName(String name) { @@ -249,7 +246,8 @@ public class Placeholder { public List getComplexValues(String text) { List lsInLs = new ArrayList<>(); - if (!isComplex() || text == null) + + if (text == null || !isComplex()) return lsInLs; Matcher matcher = rule.getMatcher(text); @@ -276,10 +274,6 @@ public class Placeholder { public void setRule(ChatFilterRule rule) { this.rule = rule; } - - public boolean isHidden() { - return hidden; - } } public List updatePlaceHolders(Player player, List messages) { @@ -393,7 +387,7 @@ public class Placeholder { int id = Integer.parseInt(value); if (id > 0) return Jobs.getJobs().get(id - 1); - } catch (Exception e) { + } catch (IndexOutOfBoundsException | NumberFormatException e) { return Jobs.getJob(value); } return null; 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 8a63f51a..5ac5b355 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java @@ -90,9 +90,11 @@ public class expboost implements Cmd { return arr; } - if (time.contains("h") || time.contains("hour")) { + String[] split = time.split("h|hour", 2); + + if (split.length > 0) { try { - arr[2] = Integer.parseInt(time.split("h|hour", 2)[0]); + arr[2] = Integer.parseInt(split[0]); } catch (NumberFormatException e) { arr[2] = 0; } @@ -100,9 +102,9 @@ public class expboost implements Cmd { time = time.replaceAll(arr[2] + "+[h|hour]+", ""); } - if (time.contains("m") || time.contains("minute")) { + if ((split = time.split("m|minute", 2)).length > 0) { try { - arr[1] = Integer.parseInt(time.split("m|minute", 2)[0]); + arr[1] = Integer.parseInt(split[0]); } catch (NumberFormatException e) { arr[1] = 0; } @@ -110,9 +112,9 @@ public class expboost implements Cmd { time = time.replaceAll(arr[1] + "+[m|minute]+", ""); } - if (time.contains("s") || time.contains("second")) { + if ((split = time.split("s|second", 2)).length > 0) { try { - arr[0] = Integer.parseInt(time.split("s|second", 2)[0]); + arr[0] = Integer.parseInt(split[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 efa3edf1..1ad1e493 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java @@ -29,13 +29,16 @@ public class explored implements Cmd { player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); return false; } - if (chunk.isFullyExplored() && Jobs.getGCManager().ExploreCompact) { + + if (Jobs.getGCManager().ExploreCompact && chunk.isFullyExplored()) { player.sendMessage(Jobs.getLanguage().getMessage("command.explored.fullExplore")); return true; } - for (int i = 0; i < chunk.getPlayers().size(); i++) { - PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(chunk.getPlayers().get(i)); + java.util.List players = chunk.getPlayers(); + + for (int i = 0; i < players.size(); i++) { + PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(players.get(i)); if (ji != null) player.sendMessage(Jobs.getLanguage().getMessage("command.explored.list", "%place%", i, "%playername%", ji.getName())); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/info.java b/src/main/java/com/gamingmesh/jobs/commands/list/info.java index 59db4ebe..ce56f781 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/info.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/info.java @@ -46,19 +46,15 @@ public class info implements Cmd { return true; } + int page = 1; String type = ""; if (args.length >= 2) { try { - Integer.parseInt(args[1]); + page = Integer.parseInt(args[1]); } catch (NumberFormatException e) { type = args[1]; } } - int page = 1; - try { - page = Integer.parseInt(args[args.length - 1]); - } catch (NumberFormatException e) { - } Jobs.getCommandManager().jobInfoMessage(pSender, jPlayer, job, type, page); return true; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java index 48049837..f40e1623 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java @@ -14,6 +14,7 @@ import com.gamingmesh.jobs.container.BoostMultiplier; import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobItems; +import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIMaterial; @@ -41,10 +42,9 @@ public class itembonus implements Cmd { if (iih != null && iih.getType() != Material.AIR) items.add(iih); - for (ItemStack OneArmor : player.getInventory().getArmorContents()) { - if (OneArmor == null || OneArmor.getType() == Material.AIR) - continue; - items.add(OneArmor); + for (ItemStack oneArmor : player.getInventory().getArmorContents()) { + if (oneArmor != null && oneArmor.getType() != Material.AIR) + items.add(oneArmor); } sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.topline")); @@ -55,12 +55,15 @@ public class itembonus implements Cmd { continue; for (Job one : jitem.getJobs()) { - BoostMultiplier boost = !jPlayer.isInJob(one) ? jitem.getBoost() : jitem.getBoost(jPlayer.getJobProgression(one)); + JobProgression prog = jPlayer.getJobProgression(one); + BoostMultiplier boost = prog == null ? jitem.getBoost() : jitem.getBoost(prog); boolean any = false; for (CurrencyType oneC : CurrencyType.values()) { - if (boost.get(oneC) != 0D) + if (boost.get(oneC) != 0D) { any = true; + break; + } } if (!any) @@ -71,7 +74,7 @@ public class itembonus implements Cmd { ec = CMIChatColor.YELLOW.toString(), msg = null; - if (jPlayer.isInJob(one)) + if (prog != null) msg = Jobs.getLanguage().getMessage("command.itembonus.output.list", "[jobname]", one.getName(), "%money%", mc + formatText((int) (boost.get(CurrencyType.MONEY) * 100)), diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java b/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java index a6b0aaec..46f4039f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java @@ -20,13 +20,11 @@ public class iteminfo implements Cmd { } if (args.length != 0) { - Jobs.getCommandManager().sendUsage(sender, "blockinfo"); + Jobs.getCommandManager().sendUsage(sender, "iteminfo"); return true; } - Player player = (Player) sender; - - ItemStack iih = Jobs.getNms().getItemInMainHand(player); + ItemStack iih = Jobs.getNms().getItemInMainHand((Player) sender); if (iih == null || iih.getType() == Material.AIR) return true; @@ -39,14 +37,15 @@ public class iteminfo implements Cmd { EnchantmentTarget.FISHING_ROD.includes(iih)) tool = true; - String dataString = iih.getData().getData() == 0 ? "" : "-" + iih.getData().getData(); + byte data = iih.getData().getData(); + String dataString = data == 0 ? "" : "-" + data; sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); sender.sendMessage(Jobs.getLanguage().getMessage("command.iteminfo.output.name", "%itemname%", iih.getType().name())); if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) sender.sendMessage(Jobs.getLanguage().getMessage("command.iteminfo.output.id", "%itemid%", iih.getType().getId())); if (!tool) - sender.sendMessage(Jobs.getLanguage().getMessage("command.iteminfo.output.data", "%itemdata%", iih.getData().getData())); + sender.sendMessage(Jobs.getLanguage().getMessage("command.iteminfo.output.data", "%itemdata%", data)); if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) sender.sendMessage(Jobs.getLanguage().getMessage("command.iteminfo.output.usage", "%first%", "", 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 e08e4ea3..ec0d3535 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/join.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/join.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; @@ -26,7 +25,7 @@ public class join implements Cmd { } if (args.length == 0) { - Bukkit.dispatchCommand(sender, "jobs browse"); + plugin.getServer().dispatchCommand(sender, "jobs browse"); return true; } 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 e23881f4..02aa22f5 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java @@ -90,9 +90,11 @@ public class moneyboost implements Cmd { return arr; } - if (time.contains("h") || time.contains("hour")) { + String[] split = time.split("h|hour", 2); + + if (split.length > 0) { try { - arr[2] = Integer.parseInt(time.split("h|hour", 2)[0]); + arr[2] = Integer.parseInt(split[0]); } catch (NumberFormatException e) { arr[2] = 0; } @@ -100,9 +102,9 @@ public class moneyboost implements Cmd { time = time.replaceAll(arr[2] + "+[h|hour]+", ""); } - if (time.contains("m") || time.contains("minute")) { + if ((split = time.split("m|minute", 2)).length > 0) { try { - arr[1] = Integer.parseInt(time.split("m|minute", 2)[0]); + arr[1] = Integer.parseInt(split[0]); } catch (NumberFormatException e) { arr[1] = 0; } @@ -110,9 +112,9 @@ public class moneyboost implements Cmd { time = time.replaceAll(arr[1] + "+[m|minute]+", ""); } - if (time.contains("s") || time.contains("second")) { + if ((split = time.split("s|second", 2)).length > 0) { try { - arr[0] = Integer.parseInt(time.split("s|second", 2)[0]); + arr[0] = Integer.parseInt(split[0]); } catch (NumberFormatException e) { arr[0] = 0; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/placeholders.java b/src/main/java/com/gamingmesh/jobs/commands/list/placeholders.java index bd393204..aa66e984 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/placeholders.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/placeholders.java @@ -52,8 +52,6 @@ public class placeholders implements Cmd { PageInfo pi = new PageInfo(isPlayer ? Jobs.getGCManager().PlaceholdersPage : values.length, values.length, page); for (JobsPlaceHolders one : values) { - if (one.isHidden()) - continue; if (pi.isBreak()) break; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/playerinfo.java b/src/main/java/com/gamingmesh/jobs/commands/list/playerinfo.java index a4e98c9d..3aed487b 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/playerinfo.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/playerinfo.java @@ -28,21 +28,17 @@ public class playerinfo implements Cmd { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; } + + int page = 1; String type = ""; if (args.length >= 3) { try { - Integer.parseInt(args[2]); + page = Integer.parseInt(args[2]); } catch (NumberFormatException e) { type = args[2]; } } - int page = 1; - try { - page = Integer.parseInt(args[args.length - 1]); - } catch (NumberFormatException e) { - } - Jobs.getCommandManager().jobInfoMessage(sender, jPlayer, job, type, page); return true; } 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 19b3776e..5f4fdc3c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java @@ -90,9 +90,11 @@ public class pointboost implements Cmd { return arr; } - if (time.contains("h") || time.contains("hour")) { + String[] split = time.split("h|hour", 2); + + if (split.length > 0) { try { - arr[2] = Integer.parseInt(time.split("h|hour", 2)[0]); + arr[2] = Integer.parseInt(split[0]); } catch (NumberFormatException e) { arr[2] = 0; } @@ -100,9 +102,9 @@ public class pointboost implements Cmd { time = time.replaceAll(arr[2] + "+[h|hour]+", ""); } - if (time.contains("m") || time.contains("minute")) { + if ((split = time.split("m|minute", 2)).length > 0) { try { - arr[1] = Integer.parseInt(time.split("m|minute", 2)[0]); + arr[1] = Integer.parseInt(split[0]); } catch (NumberFormatException e) { arr[1] = 0; } @@ -110,9 +112,9 @@ public class pointboost implements Cmd { time = time.replaceAll(arr[1] + "+[m|minute]+", ""); } - if (time.contains("s") || time.contains("second")) { + if ((split = time.split("s|second", 2)).length > 0) { try { - arr[0] = Integer.parseInt(time.split("s|second", 2)[0]); + arr[0] = Integer.parseInt(split[0]); } catch (NumberFormatException e) { arr[0] = 0; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java index d079564c..05ac85b0 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/skipquest.java @@ -2,7 +2,6 @@ package com.gamingmesh.jobs.commands.list; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -65,8 +64,10 @@ public class skipquest implements Cmd { Quest old = null; for (QuestProgression one : quests) { - if (one.getQuest().getQuestName().equalsIgnoreCase(questName) || one.getQuest().getConfigName().equalsIgnoreCase(questName)) { - old = one.getQuest(); + Quest q = one.getQuest(); + + if (q.getQuestName().equalsIgnoreCase(questName) || q.getConfigName().equalsIgnoreCase(questName)) { + old = q; break; } } @@ -90,7 +91,7 @@ public class skipquest implements Cmd { BufferedEconomy econ = Jobs.getEconomy(); Player player = jPlayer.getPlayer(); - if (amount > 0) { + if (amount > 0 && player != null) { if (!econ.getEconomy().hasMoney(player, amount)) { sender.sendMessage(Jobs.getLanguage().getMessage("economy.error.nomoney")); return false; @@ -101,8 +102,8 @@ public class skipquest implements Cmd { jPlayer.replaceQuest(old); - if (player.isOnline()) - Bukkit.dispatchCommand(player, "jobs quests"); + if (player != null) + plugin.getServer().dispatchCommand(player, "jobs quests"); if (amount > 0) { sender.sendMessage(Jobs.getLanguage().getMessage("command.skipquest.output.questSkipForCost", "%amount%", amount)); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 857f67e9..15ee94d7 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -328,7 +328,7 @@ public class JobsPlayer { public double getBoost(String jobName, CurrencyType type, boolean force) { double boost = 0D; - if (!isOnline() || type == null) + if (type == null || !isOnline()) return boost; long time = System.currentTimeMillis(); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 128d2428..05a447a2 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1557,7 +1557,6 @@ public abstract class JobsDAO { if (conn == null) return false; PreparedStatement prest = null; - boolean ok = true; try { prest = conn.prepareStatement("DELETE FROM `" + getJobsTableName() + "` WHERE `" + JobsTableFields.userid.getCollumn() + "` = ? AND `" + JobsTableFields.jobid.getCollumn() + "` = ?;"); @@ -1566,11 +1565,11 @@ public abstract class JobsDAO { prest.execute(); } catch (SQLException e) { e.printStackTrace(); - ok = false; + return false; } finally { close(prest); } - return ok; + return true; } /** @@ -1630,13 +1629,15 @@ public abstract class JobsDAO { start = 0; } + int jobsTopAmount = Jobs.getGCManager().JobsTopAmount * 2; + PreparedStatement prest = null; ResultSet res = null; try { prest = conn.prepareStatement("SELECT " + JobsTableFields.userid.getCollumn() + ", COUNT(*) AS amount, sum(" + JobsTableFields.level.getCollumn() + ") AS totallvl FROM `" + getJobsTableName() - + "` GROUP BY userid ORDER BY totallvl DESC LIMIT " + start + "," + (Jobs.getGCManager().JobsTopAmount * 2) + ";"); + + "` GROUP BY userid ORDER BY totallvl DESC LIMIT " + start + "," + jobsTopAmount + ";"); res = prest.executeQuery(); while (res.next()) { @@ -1646,7 +1647,7 @@ public abstract class JobsDAO { names.add(new TopList(info, res.getInt("totallvl"), 0)); - if (names.size() >= Jobs.getGCManager().JobsTopAmount * 2) + if (names.size() >= jobsTopAmount) break; } } catch (SQLException e) { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java index 176c4010..8ad7daa6 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java @@ -84,7 +84,6 @@ public final class JobsPayment14Listener implements Listener { camps.remove(camp); if (camps.isEmpty()) { - campPlayers.remove(event.getPlayer().getUniqueId()); campPlayers.remove(playerUId); } else { campPlayers.put(playerUId, camps); diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 31b7cb2e..8b069c49 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -94,7 +94,9 @@ import java.util.concurrent.TimeUnit; public class JobsPaymentListener implements Listener { - private Jobs plugin; + private final Jobs plugin; + private final String blockMetadata = "BlockOwner"; + private final Cache damageDealtByPlayers = CacheBuilder.newBuilder() .expireAfterWrite(5, TimeUnit.MINUTES) .weakKeys() @@ -105,8 +107,6 @@ public class JobsPaymentListener implements Listener { .build(); private Cache cowMilkingTimer; - private final String blockMetadata = "BlockOwner"; - public JobsPaymentListener(Jobs plugin) { this.plugin = plugin; @@ -131,10 +131,10 @@ public class JobsPaymentListener implements Listener { break; } - if (!Jobs.getGCManager().canPerformActionInWorld(event.getWhoClicked().getWorld())) + if (event.getInventory().getType() != InventoryType.MERCHANT || event.getSlot() != 2 || event.getSlotType() != SlotType.RESULT) return; - if (event.getInventory().getType() != InventoryType.MERCHANT || event.getSlot() != 2 || event.getSlotType() != SlotType.RESULT) + if (!Jobs.getGCManager().canPerformActionInWorld(event.getWhoClicked().getWorld())) return; ItemStack resultStack = event.getClickedInventory().getItem(2); @@ -207,18 +207,13 @@ public class JobsPaymentListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCowMilking(PlayerInteractEntityEvent event) { - Player player = event.getPlayer(); - - if (!player.isOnline() || !Jobs.getGCManager().canPerformActionInWorld(player.getWorld())) - return; - - if (!(event.getRightClicked() instanceof LivingEntity)) - return; - Entity cow = event.getRightClicked(); + if (cow.getType() != EntityType.COW && cow.getType() != EntityType.MUSHROOM_COW) return; + Player player = event.getPlayer(); + ItemStack itemInHand = Jobs.getNms().getItemInMainHand(player); if (itemInHand.getType() != Material.BUCKET && itemInHand.getType() != Material.BOWL) { return; @@ -228,6 +223,9 @@ public class JobsPaymentListener implements Listener { return; } + if (!Jobs.getGCManager().canPerformActionInWorld(player.getWorld())) + return; + // check if in creative if (!payIfCreative(player)) return; @@ -250,7 +248,7 @@ public class JobsPaymentListener implements Listener { if (time != null) { if (System.currentTimeMillis() < time + Jobs.getGCManager().CowMilkingTimer) { long timer = ((Jobs.getGCManager().CowMilkingTimer - (System.currentTimeMillis() - time)) / 1000); - jPlayer.getPlayer().sendMessage(Jobs.getLanguage().getMessage("message.cowtimer", "%time%", timer)); + player.sendMessage(Jobs.getLanguage().getMessage("message.cowtimer", "%time%", timer)); if (Jobs.getGCManager().CancelCowMilking) event.setCancelled(true); @@ -268,10 +266,7 @@ public class JobsPaymentListener implements Listener { public void onEntityShear(PlayerShearEntityEvent event) { Player player = event.getPlayer(); - if (!player.isOnline() || !Jobs.getGCManager().canPerformActionInWorld(player.getWorld())) - return; - - if (!(event.getEntity() instanceof Sheep)) + if (!(event.getEntity() instanceof Sheep) || !Jobs.getGCManager().canPerformActionInWorld(player.getWorld())) return; Sheep sheep = (Sheep) event.getEntity(); @@ -345,12 +340,12 @@ public class JobsPaymentListener implements Listener { } JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(uuid); - if (jPlayer == null || !jPlayer.isOnline()) + if (jPlayer == null) return; Player player = jPlayer.getPlayer(); - if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) + if (!player.isOnline() || !Jobs.getPermissionHandler().hasWorldPermission(player)) return; // check if player is riding