From 4f553aa4fd75e753e7e812957371b81ebd3af5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Mon, 24 Jan 2022 20:59:12 +0100 Subject: [PATCH] Added option to switch bossbar creation and management to async --- .../com/gamingmesh/jobs/config/BossBarManager.java | 14 +++++++++++++- .../jobs/config/GeneralConfigManager.java | 8 +++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java index ea721df2..afccb670 100644 --- a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java @@ -34,7 +34,19 @@ public class BossBarManager { player.getUpdateBossBarFor().clear(); } - public void ShowJobProgression(final JobsPlayer player, final JobProgression jobProg, double expGain) { + public void ShowJobProgression(final JobsPlayer player, final JobProgression jobProg, double expGain) + { + if(Jobs.getGCManager().isBossBarAsync()) + { + Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () -> ShowJobProgressionInTask(player, jobProg, expGain)); + } + else + { + ShowJobProgressionInTask(player, jobProg, expGain); + } + } + + private synchronized void ShowJobProgressionInTask(final JobsPlayer player, final JobProgression jobProg, double expGain) { if (Version.getCurrent().isLower(Version.v1_9_R1) || !Jobs.getGCManager().BossBarsMessageByDefault) return; diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index d870ca90..5cc9a1a7 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -102,7 +102,7 @@ public class GeneralConfigManager { BossBarEnabled = false, BossBarShowOnEachAction = false, BossBarsMessageByDefault = false, ExploreCompact, DBCleaningJobsUse, DBCleaningUsersUse, DisabledWorldsUse, UseAsWhiteListWorldList, PaymentMethodsMoney, PaymentMethodsPoints, PaymentMethodsExp, MythicMobsEnabled, LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, payForAbove = false, - payForEachVTradeItem, allowEnchantingBoostedItems; + payForEachVTradeItem, allowEnchantingBoostedItems, bossBarAsync = false; public ItemStack guiBackButton, guiNextButton; public CMIMaterial guiFiller; @@ -890,6 +890,8 @@ public class GeneralConfigManager { c.addComment("BossBar.Timer", "How long in sec to show BossBar for player", "If you have disabled ShowOnEachAction, then keep this number higher than payment interval for better experience"); BossBarTimer = c.get("BossBar.Timer", economyBatchDelay + 1); + c.addComment("BossBar.Async", "If enabled, bossbar creation and management will be asynchronous.", "This avoids TPS drops when the ShowOnEachAction option is activated."); + bossBarAsync = c.get("BossBar.Async", false); } c.addComment("ShowActionBars", "You can enable/disable message shown for players in action bar"); @@ -1161,4 +1163,8 @@ public class GeneralConfigManager { public boolean isInformDuplicates() { return InformDuplicates; } + + public boolean isBossBarAsync() { + return bossBarAsync; + } }