From a8dd65cb4b2f2329aa5617700eeaba22c193237e Mon Sep 17 00:00:00 2001 From: montlikadani Date: Wed, 23 Dec 2020 20:08:02 +0100 Subject: [PATCH] Make payment messages display in chat if setting is disabled per config Closes #1031 Closes #1023 --- .../jobs/CMILib/VersionChecker.java | 5 -- .../jobs/config/GeneralConfigManager.java | 3 +- .../jobs/economy/BufferedEconomy.java | 64 +++++++++++++------ 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java b/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java index 0f77a102..3e30d2f1 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java @@ -21,11 +21,6 @@ public class VersionChecker { this.plugin = plugin; } - @Deprecated - public Version getVersion() { - return Version.getCurrent(); - } - public Integer convertVersion(String v) { v = v.replaceAll("[^\\d.]", ""); Integer version = 0; diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 35a1b709..f3049a98 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -829,7 +829,8 @@ public class GeneralConfigManager { "Only works when fix-at-max-level is set to false"); levelLossPercentageFromMax = c.get("old-job.level-loss-from-max-level", levelLossPercentage); - c.addComment("ActionBars.Messages.EnabledByDefault", "When this set to true player will see action bar messages by default"); + 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); if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) { diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index 771132d3..1e5c1c26 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -220,8 +220,8 @@ public class BufferedEconomy { else Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i); - // Action bar stuff - showActionBar(payment); + // Show players payment stuff + showPayment(payment); if (payment.getOfflinePlayer().isOnline() && Version.getCurrent().isHigher(Version.v1_8_R3)) { JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId()); @@ -234,29 +234,53 @@ public class BufferedEconomy { } } + /** + * @deprecated use {@link #showPayment(BufferedPayment payment)} + * @param payment + */ + @Deprecated public void showActionBar(BufferedPayment payment) { - if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline() - || !Jobs.getGCManager().ActionBarsMessageByDefault || !payment.containsPayment()) + showPayment(payment); + } + + /** + * Shows the payment in actionbar or chat for the given player if online. + * + * @param payment {@link BufferedPayment} + */ + public void showPayment(BufferedPayment payment) { + if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline() || !payment.containsPayment()) return; UUID playerUUID = payment.getOfflinePlayer().getUniqueId(); - Boolean show = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID.toString(), true); Player abp = Bukkit.getPlayer(playerUUID); - if (abp != null && show.booleanValue()) { - String Message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main"); - if (payment.get(CurrencyType.MONEY) != 0D) { - Message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), - payment.get(CurrencyType.MONEY))); - } - if (payment.get(CurrencyType.POINTS) != 0D) { - Message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(), - payment.get(CurrencyType.POINTS))); - } - if (payment.get(CurrencyType.EXP) != 0D) { - Message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(), - payment.get(CurrencyType.EXP))); - } - ActionBarManager.send(abp, Message); + if (abp == null) { + return; + } + + String message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main"); + if (payment.get(CurrencyType.MONEY) != 0D) { + message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), + payment.get(CurrencyType.MONEY))); + } + + if (payment.get(CurrencyType.POINTS) != 0D) { + message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(), + payment.get(CurrencyType.POINTS))); + } + + if (payment.get(CurrencyType.EXP) != 0D) { + message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(), + payment.get(CurrencyType.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) { + ActionBarManager.send(abp, message); + } else { + abp.sendMessage(message); } } }