From be9af51dc7a6529a39a570999bd031dbe58c9fa0 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Sat, 28 Mar 2020 19:14:18 +0100 Subject: [PATCH] Another fix for total workers --- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 8 +- .../jobs/listeners/JobsPaymentListener.java | 106 ++++++++---------- 2 files changed, 53 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index fb160774..5800ac2f 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1179,8 +1179,8 @@ public abstract class JobsDAO { prest = conn.prepareStatement("SELECT COUNT(*) FROM `" + getJobsTableName() + "` WHERE `" + JobsTableFields.job + "` = ?;"); prest.setString(1, JobName); res = prest.executeQuery(); - while (res.next()) { - count++; + if (res.next()) { + count += res.getInt(1); } if (count == 0) { @@ -1195,8 +1195,8 @@ public abstract class JobsDAO { prest = conn.prepareStatement("SELECT COUNT(*) FROM `" + getJobsTableName() + "` WHERE `" + JobsTableFields.jobid + "` = ?;"); prest.setInt(1, job.getId()); res = prest.executeQuery(); - while (res.next()) { - count++; + if (res.next()) { + count += res.getInt(1); } } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 9c530b1e..060074fe 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -920,78 +920,70 @@ public class JobsPaymentListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryMoveItemEventToFurnace(InventoryMoveItemEvent event) { - try { - if (!plugin.isEnabled()) - return; + if (!plugin.isEnabled()) + return; - if (!Jobs.getGCManager().PreventHopperFillUps) - return; + if (!Jobs.getGCManager().PreventHopperFillUps) + return; - String type = event.getDestination().getType().toString(); - if (!type.equalsIgnoreCase("FURNACE") && !type.equalsIgnoreCase("SMOKER") && !type.equalsIgnoreCase("BLAST_FURNACE")) - return; + String type = event.getDestination().getType().toString(); + if (!type.equalsIgnoreCase("FURNACE") && !type.equalsIgnoreCase("SMOKER") && !type.equalsIgnoreCase("BLAST_FURNACE")) + return; - if (event.getItem().getType() == Material.AIR) - return; + if (event.getItem().getType() == Material.AIR) + return; - Block block = null; + Block block = null; - switch (type.toLowerCase()) { - case "furnace": - block = ((Furnace) event.getDestination().getHolder()).getBlock(); - break; - case "smoker": - // This should be done in this way to have backwards compatibility - block = ((org.bukkit.block.Smoker) event.getDestination().getHolder()).getBlock(); - break; - case "blast_furnace": - // This should be done in this way to have backwards compatibility - block = ((org.bukkit.block.BlastFurnace) event.getDestination().getHolder()).getBlock(); - break; - default: - break; - } - - if (block == null) - return; - - //disabling plugin in world - if (!Jobs.getGCManager().canPerformActionInWorld(block.getWorld())) - return; - - if (block.hasMetadata(furnaceOwnerMetadata)) - FurnaceBrewingHandling.removeFurnace(block); - } catch (Throwable e) { - e.printStackTrace(); + switch (type.toLowerCase()) { + case "furnace": + block = ((Furnace) event.getDestination().getHolder()).getBlock(); + break; + case "smoker": + // This should be done in this way to have backwards compatibility + block = ((org.bukkit.block.Smoker) event.getDestination().getHolder()).getBlock(); + break; + case "blast_furnace": + // This should be done in this way to have backwards compatibility + block = ((org.bukkit.block.BlastFurnace) event.getDestination().getHolder()).getBlock(); + break; + default: + break; } + + if (block == null) + return; + + //disabling plugin in world + if (!Jobs.getGCManager().canPerformActionInWorld(block.getWorld())) + return; + + if (block.hasMetadata(furnaceOwnerMetadata)) + FurnaceBrewingHandling.removeFurnace(block); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryMoveItemEventToBrewingStand(InventoryMoveItemEvent event) { - try { - if (!plugin.isEnabled()) - return; + if (!plugin.isEnabled()) + return; - if (event.getDestination().getType() != InventoryType.BREWING) - return; + if (event.getDestination().getType() != InventoryType.BREWING) + return; - if (!Jobs.getGCManager().PreventBrewingStandFillUps) - return; + if (!Jobs.getGCManager().PreventBrewingStandFillUps) + return; - if (event.getItem().getType() == Material.AIR) - return; + if (event.getItem().getType() == Material.AIR) + return; - BrewingStand stand = (BrewingStand) event.getDestination().getHolder(); - //disabling plugin in world - if (!Jobs.getGCManager().canPerformActionInWorld(stand.getWorld())) - return; + BrewingStand stand = (BrewingStand) event.getDestination().getHolder(); + //disabling plugin in world + if (!Jobs.getGCManager().canPerformActionInWorld(stand.getWorld())) + return; - Block block = stand.getBlock(); - if (block.hasMetadata(brewingOwnerMetadata)) - FurnaceBrewingHandling.removeBrewing(block); - } catch (Throwable e) { - e.printStackTrace(); - } + Block block = stand.getBlock(); + if (block.hasMetadata(brewingOwnerMetadata)) + FurnaceBrewingHandling.removeBrewing(block); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)