From 8d65bb7b7e6216a7d8ca9866ce0948cb2eac38a7 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Wed, 26 May 2021 21:45:22 +0200 Subject: [PATCH] Call BlockBreakEvent in any way when cancelled or not Fixes #1194 --- src/main/java/com/gamingmesh/jobs/Jobs.java | 4 +-- .../gamingmesh/jobs/config/ConfigManager.java | 21 ++++++++---- .../jobs/config/RestrictedBlockManager.java | 5 +-- .../jobs/container/BlockProtection.java | 2 +- .../jobs/listeners/JobsPayment14Listener.java | 32 +++++++++---------- .../jobs/listeners/JobsPaymentListener.java | 2 +- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index aa8cd0d0..7da5ca02 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -1306,8 +1306,8 @@ public class Jobs extends JavaPlugin { } if ((time > System.currentTimeMillis() || bp.isPaid()) && bp.getAction() != DBAction.DELETE) { - int sec = Math.round((time - System.currentTimeMillis()) / 1000L); if (inform && player.canGetPaid(info)) { + int sec = Math.round((time - System.currentTimeMillis()) / 1000L); ActionBarManager.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); } @@ -1335,8 +1335,8 @@ public class Jobs extends JavaPlugin { } if ((time > System.currentTimeMillis() || bp.isPaid()) && bp.getAction() != DBAction.DELETE) { - int sec = Math.round((time - System.currentTimeMillis()) / 1000L); if (inform && player.canGetPaid(info)) { + int sec = Math.round((time - System.currentTimeMillis()) / 1000L); ActionBarManager.send(player.getPlayer(), lManager.getMessage("message.blocktimer", "[time]", sec)); } diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 865bc9ed..34485a14 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -1493,20 +1493,29 @@ public class ConfigManager { double income = 0D; if (sep.length >= 2) { - income = Double.parseDouble(sep[1]); - income = updateValue(CurrencyType.MONEY, income); + try { + income = Double.parseDouble(sep[1]); + income = updateValue(CurrencyType.MONEY, income); + } catch (NumberFormatException e) { + } } double points = 0D; if (sep.length >= 3) { - points = Double.parseDouble(sep[2]); - points = updateValue(CurrencyType.POINTS, points); + try { + points = Double.parseDouble(sep[2]); + points = updateValue(CurrencyType.POINTS, points); + } catch (NumberFormatException e) { + } } double experience = 0D; if (sep.length >= 4) { - experience = Double.parseDouble(sep[3]); - experience = updateValue(CurrencyType.EXP, experience); + try { + experience = Double.parseDouble(sep[3]); + experience = updateValue(CurrencyType.EXP, experience); + } catch (NumberFormatException e) { + } } jobInfo.add(new JobInfo(actionType, id, meta, type + subType, income, incomeEquation, experience, expEquation, pointsEquation, points, 1, diff --git a/src/main/java/com/gamingmesh/jobs/config/RestrictedBlockManager.java b/src/main/java/com/gamingmesh/jobs/config/RestrictedBlockManager.java index 3dab3d82..d9ae164c 100644 --- a/src/main/java/com/gamingmesh/jobs/config/RestrictedBlockManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/RestrictedBlockManager.java @@ -67,8 +67,9 @@ public class RestrictedBlockManager { } } - if (restrictedBlocksTimer.size() > 0) - Jobs.consoleMsg("&e[Jobs] Loaded " + restrictedBlocksTimer.size() + " protected blocks timers!"); + int size = restrictedBlocksTimer.size(); + if (size > 0) + Jobs.consoleMsg("&e[Jobs] Loaded " + size + " protected blocks timers!"); cfg.save(); } diff --git a/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java b/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java index d9cb6052..3018767f 100644 --- a/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java +++ b/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java @@ -65,7 +65,7 @@ public class BlockProtection { } public boolean isPaid() { - return paid == null ? true : paid.booleanValue(); + return paid == null || paid.booleanValue(); } public void setPaid(boolean paid) { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java index 4d2802fc..05b4fd62 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPayment14Listener.java @@ -48,7 +48,7 @@ public final class JobsPayment14Listener implements Listener { if (camps.isEmpty()) { campPlayers.remove(map.getKey()); } else { - campPlayers.replace(map.getKey(), camps); + campPlayers.put(map.getKey(), camps); } } @@ -65,25 +65,25 @@ public final class JobsPayment14Listener implements Listener { return; List camps = campPlayers.get(event.getPlayer().getUniqueId()); + if (camps == null) + return; - if (camps != null) { - if (camps.isEmpty()) { - campPlayers.remove(event.getPlayer().getUniqueId()); - return; - } + if (camps.isEmpty()) { + campPlayers.remove(event.getPlayer().getUniqueId()); + return; + } - for (PlayerCamp camp : new ArrayList<>(camps)) { - if (camp.getBlock().getLocation().equals(event.getBlock().getLocation())) { - camps.remove(camp); + for (PlayerCamp camp : new ArrayList<>(camps)) { + if (camp.getBlock().getLocation().equals(event.getBlock().getLocation())) { + camps.remove(camp); - if (camps.isEmpty()) { - campPlayers.remove(event.getPlayer().getUniqueId()); - } else { - campPlayers.replace(event.getPlayer().getUniqueId(), camps); - } - - break; + if (camps.isEmpty()) { + campPlayers.remove(event.getPlayer().getUniqueId()); + } else { + campPlayers.put(event.getPlayer().getUniqueId(), camps); } + + break; } } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index d12208ca..5b017ffa 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -362,7 +362,7 @@ public class JobsPaymentListener implements Listener { Jobs.action(jPlayer, new ItemActionInfo(contents, ActionType.BREW)); } - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR) public void onBlockBreak(BlockBreakEvent event) { final Block block = event.getBlock();