From 72098ca24c3ee7e29c24e5567c2fc6be044cf10e Mon Sep 17 00:00:00 2001 From: Zrips Date: Thu, 15 Aug 2024 13:21:36 +0300 Subject: [PATCH] Updating feedback messages processing in action and boss bar New custom async event JobsInstancePaymentEvent to be fired with final payment amounts for visualization and record purposes --- src/main/java/com/gamingmesh/jobs/Jobs.java | 38 ++--- .../com/gamingmesh/jobs/api/BaseEvent.java | 11 +- .../jobs/api/JobsInstancePaymentEvent.java | 53 +++++++ .../jobs/api/JobsPrePaymentEvent.java | 83 ++++++---- .../gamingmesh/jobs/commands/list/toggle.java | 19 ++- .../jobs/config/BossBarManager.java | 110 ++++++------- .../jobs/config/GeneralConfigManager.java | 38 ++--- .../jobs/config/LanguageManager.java | 9 +- .../com/gamingmesh/jobs/container/Job.java | 1 - .../jobs/economy/BufferedEconomy.java | 45 +----- .../jobs/listeners/JobsListener.java | 2 + .../JobsPaymentVisualizationListener.java | 144 ++++++++++++++++++ .../jobs/stuff/ToggleBarHandling.java | 140 +++++++++-------- src/main/resources/restrictedBlocks.yml | 16 -- 14 files changed, 435 insertions(+), 274 deletions(-) create mode 100644 src/main/java/com/gamingmesh/jobs/api/JobsInstancePaymentEvent.java create mode 100644 src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentVisualizationListener.java diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 5aefd64f..b5b23fa5 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -45,6 +45,7 @@ import com.gamingmesh.jobs.Placeholders.Placeholder; import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook; import com.gamingmesh.jobs.Signs.SignUtil; import com.gamingmesh.jobs.api.JobsExpGainEvent; +import com.gamingmesh.jobs.api.JobsInstancePaymentEvent; import com.gamingmesh.jobs.api.JobsPrePaymentEvent; import com.gamingmesh.jobs.commands.JobsCommands; import com.gamingmesh.jobs.config.BlockProtectionManager; @@ -70,7 +71,6 @@ import com.gamingmesh.jobs.container.Boost; import com.gamingmesh.jobs.container.Convert; import com.gamingmesh.jobs.container.CurrencyLimit; import com.gamingmesh.jobs.container.CurrencyType; -import com.gamingmesh.jobs.container.DBAction; import com.gamingmesh.jobs.container.FastPayment; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobInfo; @@ -101,6 +101,7 @@ import com.gamingmesh.jobs.listeners.JobsPayment1_16Listener; import com.gamingmesh.jobs.listeners.JobsPayment1_20Listener; import com.gamingmesh.jobs.listeners.JobsPayment1_9Listener; import com.gamingmesh.jobs.listeners.JobsPaymentListener; +import com.gamingmesh.jobs.listeners.JobsPaymentVisualizationListener; import com.gamingmesh.jobs.listeners.PistonProtectionListener; import com.gamingmesh.jobs.listeners.PlayerSignEdit1_20Listeners; import com.gamingmesh.jobs.selection.SelectionManager; @@ -115,10 +116,8 @@ import com.gamingmesh.jobs.stuff.complement.JobsChatEvent; import com.gamingmesh.jobs.tasks.BufferedPaymentThread; import com.gamingmesh.jobs.tasks.DatabaseSaveThread; -import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Locale.LC; -import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.Version.Version; @@ -821,6 +820,7 @@ public final class Jobs extends JavaPlugin { pm.registerEvents(new JobsListener(getInstance()), getInstance()); pm.registerEvents(new JobsPaymentListener(getInstance()), getInstance()); + pm.registerEvents(new JobsPaymentVisualizationListener(getInstance()), getInstance()); if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) pm.registerEvents(new JobsPayment1_9Listener(), getInstance()); @@ -842,7 +842,7 @@ public final class Jobs extends JavaPlugin { pm.registerEvents(new JobsChatEvent(getInstance()), getInstance()); - if(HookManager.checkPyroFishingPro()) { + if (HookManager.checkPyroFishingPro()) { HookManager.getPyroFishingProManager().registerListener(); } if (HookManager.getMcMMOManager().CheckmcMMO()) { @@ -1071,8 +1071,7 @@ public final class Jobs extends JavaPlugin { Boost boost = getPlayerManager().getFinalBonus(jPlayer, noneJob); - JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), noneJob, income, - pointAmount, block, ent, victim, info); + JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), noneJob, income, 0, pointAmount, block, ent, victim, info); Bukkit.getServer().getPluginManager().callEvent(jobsPrePaymentEvent); // If event is canceled, don't do anything if (jobsPrePaymentEvent.isCancelled()) { @@ -1145,6 +1144,8 @@ public final class Jobs extends JavaPlugin { if (pointAmount != 0D) payments.put(CurrencyType.POINTS, pointAmount); + // FinalPayment event + CMIScheduler.runTaskAsynchronously(() -> Bukkit.getServer().getPluginManager().callEvent(new JobsInstancePaymentEvent(jPlayer.getPlayer(), payments))); economy.pay(jPlayer, payments); if (gConfigManager.LoggingUse) { @@ -1207,17 +1208,18 @@ public final class Jobs extends JavaPlugin { Boost boost = getPlayerManager().getFinalBonus(jPlayer, prog.getJob(), ent, victim); - JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), prog.getJob(), income, - pointAmount, block, ent, victim, info); + JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), prog.getJob(), income, expAmount, pointAmount, block, ent, victim, info); Bukkit.getServer().getPluginManager().callEvent(jobsPrePaymentEvent); // If event is canceled, don't do anything if (jobsPrePaymentEvent.isCancelled()) { income = 0D; pointAmount = 0D; + expAmount = 0D; } else { income = jobsPrePaymentEvent.getAmount(); pointAmount = jobsPrePaymentEvent.getPoints(); + expAmount = jobsPrePaymentEvent.getExp(); } // Calculate income @@ -1296,23 +1298,11 @@ public final class Jobs extends JavaPlugin { continue; // JobsPayment event - JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount, - block, ent, victim, info); + JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount, block, ent, victim, info); Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent); // If event is canceled, don't do anything expAmount = jobsExpGainEvent.isCancelled() ? 0D : jobsExpGainEvent.getExp(); - try { - if (expAmount != 0D && gConfigManager.BossBarEnabled) - if (gConfigManager.BossBarShowOnEachAction) - bbManager.ShowJobProgression(jPlayer, prog, expAmount); - else - jPlayer.getUpdateBossBarFor().add(prog.getJob().getName()); - } catch (Throwable e) { - e.printStackTrace(); - CMIMessages.consoleMessage("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it."); - } - Map payments = new HashMap<>(); if (income != 0D) payments.put(CurrencyType.MONEY, income); @@ -1321,8 +1311,10 @@ public final class Jobs extends JavaPlugin { if (expAmount != 0D) payments.put(CurrencyType.EXP, expAmount); - FASTPAYMENT.put(jPlayer.getUniqueId(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), payments), prog - .getJob())); + FASTPAYMENT.put(jPlayer.getUniqueId(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), payments), prog.getJob())); + + // FinalPayment event + CMIScheduler.runTaskAsynchronously(() -> Bukkit.getServer().getPluginManager().callEvent(new JobsInstancePaymentEvent(jPlayer.getPlayer(), payments))); economy.pay(jPlayer, payments); int oldLevel = prog.getLevel(); diff --git a/src/main/java/com/gamingmesh/jobs/api/BaseEvent.java b/src/main/java/com/gamingmesh/jobs/api/BaseEvent.java index f7b0fc2b..98ee3d67 100644 --- a/src/main/java/com/gamingmesh/jobs/api/BaseEvent.java +++ b/src/main/java/com/gamingmesh/jobs/api/BaseEvent.java @@ -7,12 +7,19 @@ public class BaseEvent extends Event { private static final HandlerList handlers = new HandlerList(); + public BaseEvent(boolean async) { + super(async); + } + + public BaseEvent() { + } + @Override public HandlerList getHandlers() { - return handlers; + return handlers; } public static HandlerList getHandlerList() { - return handlers; + return handlers; } } diff --git a/src/main/java/com/gamingmesh/jobs/api/JobsInstancePaymentEvent.java b/src/main/java/com/gamingmesh/jobs/api/JobsInstancePaymentEvent.java new file mode 100644 index 00000000..10092995 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/api/JobsInstancePaymentEvent.java @@ -0,0 +1,53 @@ +package com.gamingmesh.jobs.api; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.OfflinePlayer; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.gamingmesh.jobs.container.CurrencyType; + +public final class JobsInstancePaymentEvent extends BaseEvent { + + private OfflinePlayer offlinePlayer; + + private Map payments = new HashMap<>(); + + public JobsInstancePaymentEvent(OfflinePlayer offlinePlayer, Map payments) { + super(true); + this.offlinePlayer = offlinePlayer; + this.payments = payments; + } + + /** + * Returns the player who got payment. + * + * @return {@link OfflinePlayer} + */ + public OfflinePlayer getPlayer() { + return offlinePlayer; + } + + /** + * Returns the primitive type of payment of the given + * currency type if exist, otherwise returns 0. + * + * @param type {@link CurrencyType} + * @return the amount of payment from specific {@link CurrencyType} + */ + public double get(CurrencyType type) { + return payments.getOrDefault(type, 0D); + } + + /** + * Returns all cached payment returned as {@link Map}. + * + * @return {@link Map} + */ + public Map getPayment() { + return payments; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/api/JobsPrePaymentEvent.java b/src/main/java/com/gamingmesh/jobs/api/JobsPrePaymentEvent.java index e88bd95b..2231b8e9 100644 --- a/src/main/java/com/gamingmesh/jobs/api/JobsPrePaymentEvent.java +++ b/src/main/java/com/gamingmesh/jobs/api/JobsPrePaymentEvent.java @@ -1,7 +1,12 @@ package com.gamingmesh.jobs.api; import com.gamingmesh.jobs.container.ActionInfo; +import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; + +import java.util.HashMap; +import java.util.Map; + import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -13,8 +18,7 @@ import org.bukkit.event.Cancellable; */ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable { private OfflinePlayer offlinePlayer; - private double money; - private double points; + Map amounts = new HashMap<>(); private Job job; private Block block; private Entity entity; @@ -24,22 +28,27 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable @Deprecated public JobsPrePaymentEvent(OfflinePlayer offlinePlayer, Job job, double money, double points) { - this.job = job; - this.offlinePlayer = offlinePlayer; - this.money = money; - this.points = points; + this.job = job; + this.offlinePlayer = offlinePlayer; + amounts.put(CurrencyType.MONEY, money); + amounts.put(CurrencyType.POINTS, points); } - public JobsPrePaymentEvent(OfflinePlayer offlinePlayer, Job job, double money, double points, Block block, - Entity entity, LivingEntity living, ActionInfo info) { - this.job = job; - this.offlinePlayer = offlinePlayer; - this.money = money; - this.points = points; - this.block = block; - this.entity = entity; - this.living = living; - this.info = info; + @Deprecated + public JobsPrePaymentEvent(OfflinePlayer offlinePlayer, Job job, double money, double points, Block block, Entity entity, LivingEntity living, ActionInfo info) { + this(offlinePlayer, job, money, 0, points, block, entity, living, info); + } + + public JobsPrePaymentEvent(OfflinePlayer offlinePlayer, Job job, double money, double exp, double points, Block block, Entity entity, LivingEntity living, ActionInfo info) { + this.job = job; + this.offlinePlayer = offlinePlayer; + amounts.put(CurrencyType.MONEY, money); + amounts.put(CurrencyType.EXP, exp); + amounts.put(CurrencyType.POINTS, points); + this.block = block; + this.entity = entity; + this.living = living; + this.info = info; } /** @@ -48,7 +57,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @return {@link OfflinePlayer} */ public OfflinePlayer getPlayer() { - return offlinePlayer; + return offlinePlayer; } /** @@ -57,7 +66,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @return expected income before calculations */ public double getAmount() { - return money; + return amounts.getOrDefault(CurrencyType.MONEY, 0D); } /** @@ -66,7 +75,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @return expected points before calculations */ public double getPoints() { - return points; + return amounts.getOrDefault(CurrencyType.POINTS, 0D); } /** @@ -75,7 +84,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @return {@link Job} */ public Job getJob() { - return job; + return job; } /** @@ -84,7 +93,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @param money new amount */ public void setAmount(double money) { - this.money = money; + amounts.put(CurrencyType.MONEY, money); } /** @@ -93,7 +102,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @param points */ public void setPoints(double points) { - this.points = points; + amounts.put(CurrencyType.POINTS, points); } /** @@ -102,7 +111,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @return {@link Block} */ public Block getBlock() { - return block; + return block; } /** @@ -113,7 +122,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @return {@link Entity} */ public Entity getEntity() { - return entity; + return entity; } /** @@ -122,7 +131,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @return {@link LivingEntity} */ public LivingEntity getLivingEntity() { - return living; + return living; } /** @@ -131,16 +140,34 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable * @return {@link ActionInfo} */ public ActionInfo getActionInfo() { - return info; + return info; } @Override public boolean isCancelled() { - return cancelled; + return cancelled; } @Override public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; + this.cancelled = cancelled; + } + + /** + * Returns the amount of expected exp. + * + * @return expected exp before calculations + */ + public double getExp() { + return amounts.getOrDefault(CurrencyType.EXP, 0D); + } + + /** + * Sets a new exp amount before calculations. + * + * @param exp + */ + public void setExp(double exp) { + amounts.put(CurrencyType.EXP, exp); } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java b/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java index 5fc0647e..99a1b9f8 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/toggle.java @@ -1,6 +1,8 @@ package com.gamingmesh.jobs.commands.list; +import java.util.UUID; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -28,34 +30,31 @@ public class toggle implements Cmd { } Player player = (Player) sender; - String playerUUID = player.getUniqueId().toString(); + UUID playerUUID = player.getUniqueId(); if (isActionbar) { - Boolean ex = ToggleBarHandling.getActionBarToggle().get(playerUUID); + boolean ex = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID, Jobs.getGCManager().ActionBarsMessageByDefault); - if (ex == null || ex.booleanValue()) { - ToggleBarHandling.getActionBarToggle().put(playerUUID, false); + if (ex) { Language.sendMessage(sender, "command.toggle.output.off"); } else { - ToggleBarHandling.getActionBarToggle().put(playerUUID, true); Language.sendMessage(sender, "command.toggle.output.on"); } + ToggleBarHandling.getActionBarToggle().put(playerUUID, !ex); } if (isBossbar) { - Boolean ex = ToggleBarHandling.getBossBarToggle().get(playerUUID); + boolean ex = ToggleBarHandling.getBossBarToggle().getOrDefault(playerUUID, Jobs.getGCManager().BossBarsMessageByDefault); - if (ex == null || ex.booleanValue()) { - ToggleBarHandling.getBossBarToggle().put(playerUUID, false); + if (ex) { Language.sendMessage(sender, "command.toggle.output.off"); - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player.getUniqueId()); if (jPlayer != null) jPlayer.hideBossBars(); } else { - ToggleBarHandling.getBossBarToggle().put(playerUUID, true); Language.sendMessage(sender, "command.toggle.output.on"); } + ToggleBarHandling.getBossBarToggle().put(playerUUID, !ex); } return true; diff --git a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java index 6274810b..be293a54 100644 --- a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java @@ -39,17 +39,13 @@ public class BossBarManager { if (Version.getCurrent().isLower(Version.v1_9_R1) || !Jobs.getGCManager().BossBarsMessageByDefault) return; - if (!ToggleBarHandling.getBossBarToggle().getOrDefault(player.getUniqueId().toString(), true)) + if (!ToggleBarHandling.getBossBarToggle().getOrDefault(player.getUniqueId(), true)) return; - if (Jobs.getGCManager().isBossBarAsync()) { - CMIScheduler.get().runTaskAsynchronously(() -> ShowJobProgressionInTask(player, jobProg, expGain)); - } else { - ShowJobProgressionInTask(player, jobProg, expGain); - } + showJobProgressionInTask(player, jobProg, expGain); } - private synchronized void ShowJobProgressionInTask(final JobsPlayer player, final JobProgression jobProg, double expGain) { + private static synchronized void showJobProgressionInTask(final JobsPlayer player, final JobProgression jobProg, double expGain) { BossBar bar = null; BossBarInfo oldOne = null; for (BossBarInfo one : player.getBossBarInfo()) { @@ -76,54 +72,7 @@ public class BossBarManager { "%gain%", gain); if (bar == null) { - BarColor color = getColor(jobProg.getJob()); - if (color == null) { - switch (player.getBossBarInfo().size()) { - case 1: - color = BarColor.GREEN; - break; - case 2: - color = BarColor.RED; - break; - case 3: - color = BarColor.WHITE; - break; - case 4: - color = BarColor.YELLOW; - break; - case 5: - color = BarColor.PINK; - break; - case 6: - color = BarColor.PURPLE; - break; - default: - color = BarColor.BLUE; - break; - } - } - BarStyle style; - switch (Jobs.getGCManager().SegmentCount) { - case 1: - style = BarStyle.SOLID; - break; - case 6: - style = BarStyle.SEGMENTED_6; - break; - case 10: - style = BarStyle.SEGMENTED_10; - break; - case 12: - style = BarStyle.SEGMENTED_12; - break; - case 20: - style = BarStyle.SEGMENTED_20; - break; - default: - style = BarStyle.SOLID; - break; - } - bar = Bukkit.createBossBar(message, color, style); + bar = initBossBar(player, jobProg, message); } else bar.setTitle(message); @@ -157,6 +106,57 @@ public class BossBarManager { jobProg.setLastExperience(0D); } + private static BossBar initBossBar(final JobsPlayer player, final JobProgression jobProg, String message) { + BarColor color = getColor(jobProg.getJob()); + if (color == null) { + switch (player.getBossBarInfo().size()) { + case 1: + color = BarColor.GREEN; + break; + case 2: + color = BarColor.RED; + break; + case 3: + color = BarColor.WHITE; + break; + case 4: + color = BarColor.YELLOW; + break; + case 5: + color = BarColor.PINK; + break; + case 6: + color = BarColor.PURPLE; + break; + default: + color = BarColor.BLUE; + break; + } + } + BarStyle style; + switch (Jobs.getGCManager().SegmentCount) { + case 1: + style = BarStyle.SOLID; + break; + case 6: + style = BarStyle.SEGMENTED_6; + break; + case 10: + style = BarStyle.SEGMENTED_10; + break; + case 12: + style = BarStyle.SEGMENTED_12; + break; + case 20: + style = BarStyle.SEGMENTED_20; + break; + default: + style = BarStyle.SOLID; + break; + } + return Bukkit.createBossBar(message, color, style); + } + private static BarColor getColor(Job job) { if (job.getBossbar() == null) return null; diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 6db0b67a..c0ecd04b 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -104,15 +104,17 @@ public class GeneralConfigManager { applyToNegativeIncome, useMinimumOveralPayment, useMinimumOveralPoints, useMinimumOveralExp, useBreederFinder, CancelCowMilking, fixAtMaxLevel, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAccountChat, - EmptyServerAccountActionBar, ActionBarsMessageByDefault, aBarSilentMode, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment, + EmptyServerAccountActionBar, ActionBarsMessageByDefault, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment, JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, ShowActionNames, hideItemAttributes, DisableJoiningJobThroughGui, FireworkLevelupUse, UseRandom, UsePerPermissionForLeaving, EnableConfirmation, jobsInfoOpensBrowse, MonsterDamageUse, MonsterDamageIgnoreBosses, useMaxPaymentCurve, blockOwnershipTakeOver, hideJobsInfoWithoutPermission, UseTaxes, TransferToServerAccount, TakeFromPlayersPayment, AutoJobJoinUse, AllowDelevel, RomanNumbers, - BossBarEnabled = false, BossBarShowOnEachAction = false, BossBarsMessageByDefault = false, ExploreCompact, ExploreSaveIntoDatabase = false, DBCleaningJobsUse, DBCleaningUsersUse, + BossBarEnabled = false, BossBarsMessageByDefault = false, ExploreCompact, ExploreSaveIntoDatabase = false, DBCleaningJobsUse, DBCleaningUsersUse, DisabledWorldsUse, UseAsWhiteListWorldList, MythicMobsEnabled, LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, payForAbove = false, - payForEachVTradeItem, allowEnchantingBoostedItems, bossBarAsync = false, preventShopItemEnchanting; + payForEachVTradeItem, allowEnchantingBoostedItems, preventShopItemEnchanting; + + public int ActionBarsMessageKeepFor; public boolean jobsshopenabled; public boolean DailyQuestsEnabled; @@ -410,12 +412,6 @@ public class GeneralConfigManager { c.addComment("Optimizations.RomanNumbers", "Enabling this option some places will indicate players level as XIV instead of 14", "Only or player levels"); RomanNumbers = c.get("Optimizations.RomanNumbers", false); -// c.addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files", -// "This will eliminate small lag spikes when request is being send to mojangs servers for offline players data", -// "Theroticali this should work without issues, but if you havving some, just disable", -// "But then you can feal some small (100-200ms) lag spikes while performings some jobs commands"); -// LocalOfflinePlayersData = c.get("Optimizations.UseLocalOfflinePlayersData", true); - c.addComment("Optimizations.DisabledWorlds.Use", "By setting this to true, Jobs plugin will be disabled in given worlds", "Only commands can be performed from disabled worlds with jobs.disabledworld.commands permission node"); DisabledWorldsUse = c.get("Optimizations.DisabledWorlds.Use", false); @@ -425,9 +421,9 @@ public class GeneralConfigManager { DisabledWorldsList = c.get("Optimizations.DisabledWorlds.List", Arrays.asList("Example", "Worlds")); CMIList.toLowerCase(DisabledWorldsList); - if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) { + if (Version.isCurrentEqualOrHigher(Version.v1_16_R1)) { c.addComment("Optimizations.Explore.NewMethod", - "Do you want to use new exploration tracking method. Only for 1.14+ servers"); + "Do you want to use new exploration tracking method. Only for 1.16+ servers"); useNewExploration = c.get("Optimizations.Explore.NewMethod", true); } @@ -993,8 +989,10 @@ public class GeneralConfigManager { c.addComment("ActionBars.Messages.EnabledByDefault", "When this set to true player will see action bar messages by default", "When false, players will see chat messages instead."); ActionBarsMessageByDefault = c.get("ActionBars.Messages.EnabledByDefault", true); - c.addComment("ActionBars.Messages.SilentMode", "If true, should we mute the payment messages from appearing in chat if actionbar is disabled?"); - aBarSilentMode = c.get("ActionBars.Messages.SilentMode", false); + c.addComment("ActionBars.Messages.KeepFor", "Time in seconds action bar will remain visible if enabled", + "This time is used to define for how long we will accumulate payments to be shown in action bar", + "If no payments are being issued in defined time then it will reset to 0 and remain hidden"); + ActionBarsMessageKeepFor = c.get("ActionBars.Messages.KeepFor", 5); if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) { c.addComment("BossBar.Enabled", "Enables BossBar feature", "Works only from 1.9 mc version"); @@ -1003,16 +1001,10 @@ public class GeneralConfigManager { c.addComment("BossBar.Messages.EnabledByDefault", "When this set to true player will see Bossbar messages by default"); BossBarsMessageByDefault = c.get("BossBar.Messages.EnabledByDefault", true); - c.addComment("BossBar.ShowOnEachAction", "If enabled boss bar will update after each action", - "If disabled, BossBar will update only on each payment. This can save some server resources"); - BossBarShowOnEachAction = c.get("BossBar.ShowOnEachAction", false); c.addComment("BossBar.SegmentCount", "Defines in how many parts bossbar will be split visually", "Valid options: 1, 6, 10, 12, 20"); SegmentCount = c.get("BossBar.SegmentCount", 1); - 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("BossBar.Timer", "How long in sec to show BossBar for player"); + BossBarTimer = c.get("BossBar.Timer", 5); } c.addComment("ShowActionBars", "You can enable/disable message shown for players in action bar"); @@ -1314,10 +1306,6 @@ public class GeneralConfigManager { return InformDuplicates; } - public boolean isBossBarAsync() { - return bossBarAsync; - } - public boolean isDailyQuestsUseGUI() { return DailyQuestsUseGUI; } diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 6ce76cb8..88cc30d0 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -648,10 +648,11 @@ public class LanguageManager { c.get("command.toggle.help.args", "actionbar/bossbar"); Jobs.getGCManager().getCommandArgs().put("toggle", Arrays.asList("actionbar%%bossbar")); c.get("command.toggle.output.turnedoff", "&4This feature is turned off!"); - c.get("command.toggle.output.paid.main", "&aYou got:"); - c.get("command.toggle.output.paid.money", "&e[amount] money"); - c.get("command.toggle.output.paid.exp", "&7[exp] exp"); - c.get("command.toggle.output.paid.points", "&6[points] points"); + + c.get("command.toggle.output.paid.ACmoney", "&e+[amount]$ "); + c.get("command.toggle.output.paid.ACexp", "&7+[exp]XP "); + c.get("command.toggle.output.paid.ACpoints", "&6+[points]pts "); + c.get("command.toggle.output.on", "&aToggled: &aON"); c.get("command.toggle.output.off", "&aToggled: &4OFF"); diff --git a/src/main/java/com/gamingmesh/jobs/container/Job.java b/src/main/java/com/gamingmesh/jobs/container/Job.java index 55fed3c4..c4a788a0 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Job.java +++ b/src/main/java/com/gamingmesh/jobs/container/Job.java @@ -351,7 +351,6 @@ public class Job { if (!info.isInLevelRange(level)) { break; } - return info; } diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index 088be18e..c376c163 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -220,12 +220,6 @@ public class BufferedEconomy { else CMIScheduler.get().runTaskLater(new BufferedPaymentTask(this, economy, payment), i); - // Show players payment stuff - showPayment(payment); - - if (Version.getCurrent().isHigher(Version.v1_8_R3) && payment.getOfflinePlayer().isOnline()) { - Jobs.getBBManager().ShowJobProgression(Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId())); - } } catch (Throwable e) { e.printStackTrace(); } @@ -242,7 +236,6 @@ public class BufferedEconomy { */ @Deprecated public void showActionBar(BufferedPayment payment) { - showPayment(payment); } /** @@ -250,43 +243,7 @@ public class BufferedEconomy { * * @param payment {@link BufferedPayment} */ + @Deprecated public void showPayment(BufferedPayment payment) { - if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline() - || !payment.containsPayment()) - return; - - UUID playerUUID = payment.getOfflinePlayer().getUniqueId(); - Player abp = Bukkit.getPlayer(playerUUID); - if (abp == null) { - return; - } - - String message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main"); - double money = payment.get(CurrencyType.MONEY); - if (money != 0D) { - message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), - money)); - } - - double points = payment.get(CurrencyType.POINTS); - if (points != 0D) { - message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(), - points)); - } - - double exp = payment.get(CurrencyType.EXP); - if (exp != 0D) { - message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(), - exp)); - } - - // Whether or not to show this on player actionbar or on chat - boolean showInActionbar = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID.toString(), - Jobs.getGCManager().ActionBarsMessageByDefault); - if (showInActionbar) { - CMIActionBar.send(abp, message); - } else if (!Jobs.getGCManager().aBarSilentMode) { - abp.sendMessage(message); - } } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 7c7a766a..a6a8e0ad 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -76,6 +76,8 @@ import com.gamingmesh.jobs.Signs.SignUtil; import com.gamingmesh.jobs.Signs.jobsSign; import com.gamingmesh.jobs.api.JobsAreaSelectionEvent; import com.gamingmesh.jobs.api.JobsChunkChangeEvent; +import com.gamingmesh.jobs.api.JobsInstancePaymentEvent; +import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobLimitedItems; import com.gamingmesh.jobs.container.JobProgression; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentVisualizationListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentVisualizationListener.java new file mode 100644 index 00000000..aa996f87 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentVisualizationListener.java @@ -0,0 +1,144 @@ +/** + * Jobs Plugin for Bukkit + * Copyright (C) 2011 Zak Ford + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.gamingmesh.jobs.listeners; + +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.api.JobsInstancePaymentEvent; +import com.gamingmesh.jobs.container.CurrencyType; +import com.gamingmesh.jobs.stuff.ToggleBarHandling; + +import net.Zrips.CMILib.ActionBar.CMIActionBar; +import net.Zrips.CMILib.Version.Version; + +public class JobsPaymentVisualizationListener implements Listener { + + private Jobs plugin; + + public JobsPaymentVisualizationListener(Jobs plugin) { + this.plugin = plugin; + } + + ConcurrentHashMap paymentCaches = new ConcurrentHashMap<>(); + + class paymentCache { + + private long lastAction = 0l; + private ConcurrentHashMap accumulation = new ConcurrentHashMap<>(); + private ConcurrentHashMap lastPayment = new ConcurrentHashMap<>(); + + public long getLastAction() { + return lastAction; + } + + public void setLastAction() { + this.lastAction = System.currentTimeMillis(); + } + + public ConcurrentHashMap getPayments() { + return accumulation; + } + + public void addPayments(Map payments) { + if (lastAction + (Jobs.getGCManager().ActionBarsMessageKeepFor * 1000L) < System.currentTimeMillis()) { + accumulation.clear(); + } + setLastAction(); + payments.forEach((currency, amount) -> accumulation.merge(currency, amount, Double::sum)); + + lastPayment.clear(); + lastPayment.putAll(payments); + } + } + + private paymentCache getPaymentCache(UUID uuid, Map payments) { + paymentCache cache = paymentCaches.computeIfAbsent(uuid, k -> new paymentCache()); + + cache.addPayments(payments); + + return cache; + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerQuit(PlayerQuitEvent event) { + paymentCaches.remove(event.getPlayer().getUniqueId()); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onJobsInstancePaymentBossEvent(JobsInstancePaymentEvent event) { + + if (event.getPlayer() == null || !event.getPlayer().isOnline()) + return; + + if (!Version.getCurrent().isHigher(Version.v1_8_R3)) + return; + + Jobs.getBBManager().ShowJobProgression(Jobs.getPlayerManager().getJobsPlayer(event.getPlayer().getUniqueId())); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onJobsInstancePaymentActionBarEvent(JobsInstancePaymentEvent event) { + + if (event.getPlayer() == null || !event.getPlayer().isOnline()) + return; + + Player player = Bukkit.getPlayer(event.getPlayer().getUniqueId()); + + if (player == null) + return; + + // Whether or not to show this on player actionbar or on chat + boolean showInActionbar = ToggleBarHandling.getActionBarToggle().getOrDefault(player.getUniqueId(), Jobs.getGCManager().ActionBarsMessageByDefault); + + if (!showInActionbar) + return; + + paymentCache cached = getPaymentCache(player.getUniqueId(), event.getPayment()); + + ConcurrentHashMap payment = cached.getPayments(); + + StringBuilder message = new StringBuilder(); + + double money = payment.get(CurrencyType.MONEY); + if (money != 0D) + message.append(Jobs.getLanguage().getMessage("command.toggle.output.paid.ACmoney", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), money))); + + double exp = payment.get(CurrencyType.EXP); + if (exp != 0D) + message.append(Jobs.getLanguage().getMessage("command.toggle.output.paid.ACexp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(), exp))); + + double points = payment.get(CurrencyType.POINTS); + if (points != 0D) + message.append(Jobs.getLanguage().getMessage("command.toggle.output.paid.ACpoints", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points))); + + if (!message.toString().isEmpty()) + CMIActionBar.send(player, message.toString(), Jobs.getGCManager().ActionBarsMessageKeepFor); + + } +} diff --git a/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java b/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java index 7c3054a2..df663b35 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/ToggleBarHandling.java @@ -3,6 +3,7 @@ package com.gamingmesh.jobs.stuff; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -12,96 +13,103 @@ import com.gamingmesh.jobs.config.YmlMaker; public class ToggleBarHandling { - static Map actionBarToggle = new HashMap<>(); - static Map bossBarToggle = new HashMap<>(); + static Map actionBarToggle = new HashMap<>(); + static Map bossBarToggle = new HashMap<>(); public static void load() { - YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml"); - if (!f.exists()) - return; + YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml"); + if (!f.exists()) + return; - FileConfiguration config = f.getConfig(); + FileConfiguration config = f.getConfig(); - if (Jobs.getGCManager().BossBarEnabled) { - ConfigurationSection section = config.getConfigurationSection("bossBar"); + if (Jobs.getGCManager().BossBarEnabled) { + ConfigurationSection section = config.getConfigurationSection("bossBar"); - if (section != null) { - for (String one : section.getKeys(false)) { - boolean boo = section.getBoolean(one); - if (!boo) { - bossBarToggle.put(one, boo); - } - } - } - } + if (section != null) { + for (String one : section.getKeys(false)) { + boolean boo = section.getBoolean(one); + if (boo) + continue; - if (Jobs.getGCManager().ActionBarsMessageByDefault) { - ConfigurationSection section = config.getConfigurationSection("actionBar"); + try { + bossBarToggle.put(UUID.fromString(one), boo); + } catch (Throwable e) { + } + } + } + } - if (section != null) { - for (String one : section.getKeys(false)) { - boolean boo = section.getBoolean(one); - if (!boo) { - actionBarToggle.put(one, boo); - } - } - } - } + if (Jobs.getGCManager().ActionBarsMessageByDefault) { + ConfigurationSection section = config.getConfigurationSection("actionBar"); + + if (section != null) { + for (String one : section.getKeys(false)) { + boolean boo = section.getBoolean(one); + if (boo) + continue; + try { + actionBarToggle.put(UUID.fromString(one), boo); + } catch (Throwable e) { + } + } + } + } } public static void save() { - YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml"); + YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml"); - if (bossBarToggle.isEmpty() && actionBarToggle.isEmpty()) { - if (f.exists() && f.getConfigFile().length() == 0L) { - f.getConfigFile().delete(); - } + if (bossBarToggle.isEmpty() && actionBarToggle.isEmpty()) { + if (f.exists() && f.getConfigFile().length() == 0L) { + f.getConfigFile().delete(); + } - return; - } + return; + } - if (!f.exists()) - f.createNewFile(); + if (!f.exists()) + f.createNewFile(); - f.saveDefaultConfig(); + f.saveDefaultConfig(); - FileConfiguration config = f.getConfig(); + FileConfiguration config = f.getConfig(); - if (Jobs.getGCManager().BossBarEnabled) { - config.set("bossBar", null); + if (Jobs.getGCManager().BossBarEnabled) { + config.set("bossBar", null); - if (!bossBarToggle.isEmpty()) { - for (Entry one : bossBarToggle.entrySet()) { - if (!one.getValue()) { - config.set("bossBar." + one.getKey(), one.getValue()); - } - } - } - } + if (!bossBarToggle.isEmpty()) { + for (Entry one : bossBarToggle.entrySet()) { + if (!one.getValue()) { + config.set("bossBar." + one.getKey().toString(), one.getValue()); + } + } + } + } - if (Jobs.getGCManager().ActionBarsMessageByDefault) { - config.set("actionBar", null); + if (Jobs.getGCManager().ActionBarsMessageByDefault) { + config.set("actionBar", null); - if (!actionBarToggle.isEmpty()) { - for (Entry one : actionBarToggle.entrySet()) { - if (!one.getValue()) { - config.set("actionBar." + one.getKey(), one.getValue()); - } - } - } - } + if (!actionBarToggle.isEmpty()) { + for (Entry one : actionBarToggle.entrySet()) { + if (!one.getValue()) { + config.set("actionBar." + one.getKey().toString(), one.getValue()); + } + } + } + } - bossBarToggle.clear(); - actionBarToggle.clear(); + bossBarToggle.clear(); + actionBarToggle.clear(); - f.saveConfig(); + f.saveConfig(); } - public static Map getActionBarToggle() { - return actionBarToggle; + public static Map getActionBarToggle() { + return actionBarToggle; } - public static Map getBossBarToggle() { - return bossBarToggle; + public static Map getBossBarToggle() { + return bossBarToggle; } } diff --git a/src/main/resources/restrictedBlocks.yml b/src/main/resources/restrictedBlocks.yml index 5b1c7e9e..e9be92cf 100644 --- a/src/main/resources/restrictedBlocks.yml +++ b/src/main/resources/restrictedBlocks.yml @@ -17,8 +17,6 @@ blocksTimer: JUNGLE_LEAVES: 60 GRASS: 60 TALL_GRASS: 60 - GRASS_BLOCK: 60 - GRASS_PATH: 60 SEAGRASS: 60 DEAD_BUSH: 60 RAIL: 60 @@ -37,18 +35,6 @@ blocksTimer: TORCH: 60 REDSTONE_TORCH: 60 LADDER: 5 - LIGHT_BLUE_CARPET: 60 - LIGHT_GRAY_CARPET: 60 - LIME_CARPET: 60 - MAGENTA_CARPET: 60 - ORANGE_CARPET: 60 - PINK_CARPET: 60 - BLACK_CARPET: 60 - BLUE_CARPET: 60 - BROWN_CARPET: 60 - CYAN_CARPET: 60 - GRAY_CARPET: 60 - GREEN_CARPET: 60 OAK_BUTTON: 5 SPRUCE_BUTTON: 5 STONE_BUTTON: 60 @@ -57,8 +43,6 @@ blocksTimer: DARK_OAK_BUTTON: 60 JUNGLE_BUTTON: 60 LEVER: 60 - SNOW: 60 - SNOW_BLOCK: 60 TRIPWIRE_HOOK: 60 REPEATER: 60 COMPARATOR: 60