From d3d1948fc545d041f9220882fffcd0235cd258f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Tue, 8 Feb 2022 18:07:12 +0100 Subject: [PATCH] Avoid checking limited items if none are configured --- src/main/java/com/gamingmesh/jobs/Jobs.java | 8 ++++++++ .../java/com/gamingmesh/jobs/listeners/JobsListener.java | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index e45e80e1..c2723cf1 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -165,6 +165,8 @@ public final class Jobs extends JavaPlugin { public static LoadStatus status = LoadStatus.Good; + private static boolean hasLimitedItems = false; + private static final int MAX_ENTRIES = 5; public static final LinkedHashMap FASTPAYMENT = new LinkedHashMap(MAX_ENTRIES + 1, .75F, false) { protected boolean removeEldestEntry(Map.Entry eldest) { @@ -834,6 +836,8 @@ public final class Jobs extends JavaPlugin { getLanguage().reload(); getConfigManager().reload(); + hasLimitedItems = Jobs.getJobs().stream().anyMatch(job -> !job.getLimitedItems().isEmpty()); + getDBManager().getDB().loadAllJobsWorlds(); getDBManager().getDB().loadAllJobsNames(); @@ -1506,4 +1510,8 @@ public final class Jobs extends JavaPlugin { if (pageCount != 0) rm.show(sender); } + + public static boolean hasLimitedItems() { + return hasLimitedItems; + } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 2f3ecc68..bc822ba7 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -382,6 +382,12 @@ public class JobsListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onLimitedItemInteract(PlayerInteractEvent event) { + + if(!Jobs.hasLimitedItems()) + { + return; + } + Player player = event.getPlayer(); ItemStack iih = CMIItemStack.getItemInMainHand(player); if (iih.getType() == Material.AIR)