From b2c7d12b609b3b13a10d463a3ebed096d5bf3331 Mon Sep 17 00:00:00 2001 From: ThiagoROX <51332006+SrBedrock@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:39:26 -0300 Subject: [PATCH] feat: added price and date formatters (#401) Co-authored-by: RoinujNosde --- .../phaed/simpleclans/Clan.java | 24 +++++++--- .../phaed/simpleclans/ClanPlayer.java | 6 +-- .../commands/clan/BankCommand.java | 13 ++--- .../commands/clan/ClanCommands.java | 5 +- .../commands/clan/LeaderCommands.java | 3 +- .../commands/general/GeneralCommands.java | 2 +- .../commands/staff/BankCommand.java | 15 +++--- .../simpleclans/managers/ClanManager.java | 47 ++++++++++--------- .../managers/PermissionsManager.java | 3 ++ .../simpleclans/managers/SettingsManager.java | 3 +- .../simpleclans/tasks/CollectFeeTask.java | 3 +- .../simpleclans/tasks/CollectUpkeepTask.java | 3 +- .../ui/frames/ClanDetailsFrame.java | 11 +++-- .../simpleclans/ui/frames/Components.java | 7 +-- .../simpleclans/ui/frames/InviteFrame.java | 3 +- .../simpleclans/ui/frames/MainFrame.java | 4 +- .../ui/frames/staff/ClanDetailsFrame.java | 2 +- .../phaed/simpleclans/utils/ChatUtils.java | 5 +- .../simpleclans/utils/CurrencyFormat.java | 21 +++++++++ .../phaed/simpleclans/utils/DateFormat.java | 29 ++++++++++++ src/main/resources/config.yml | 1 + 21 files changed, 144 insertions(+), 66 deletions(-) create mode 100644 src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/CurrencyFormat.java create mode 100644 src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/DateFormat.java diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/Clan.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/Clan.java index 5b4a5ba0d..4ad79919e 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/Clan.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/Clan.java @@ -10,6 +10,8 @@ import net.sacredlabyrinth.phaed.simpleclans.loggers.BankOperator; import net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager; import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; +import net.sacredlabyrinth.phaed.simpleclans.utils.DateFormat; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -114,12 +116,12 @@ public String toString() { public void deposit(double amount, Player player) { if (SimpleClans.getInstance().getPermissionsManager().playerHasMoney(player, amount)) { if (SimpleClans.getInstance().getPermissionsManager().chargePlayer(player, amount)) { - player.sendMessage(AQUA + lang("player.clan.deposit", player, amount)); - addBb(player.getName(), lang("bb.clan.deposit", amount)); + player.sendMessage(AQUA + lang("player.clan.deposit", player, CurrencyFormat.format(amount))); + addBb(player.getName(), lang("bb.clan.deposit", CurrencyFormat.format(amount))); setBalance(getBalance() + amount); SimpleClans.getInstance().getStorageManager().updateClan(this); } else { - player.sendMessage(AQUA + lang("not.sufficient.money", player, amount)); + player.sendMessage(AQUA + lang("not.sufficient.money", player, CurrencyFormat.format(amount))); } } else { player.sendMessage(AQUA + lang("not.sufficient.money", player, amount)); @@ -151,8 +153,8 @@ public EconomyResponse deposit(@NotNull BankOperator sender, @NotNull Cause caus public void withdraw(double amount, Player player) { if (getBalance() >= amount) { if (SimpleClans.getInstance().getPermissionsManager().grantPlayer(player, amount)) { - player.sendMessage(AQUA + lang("player.clan.withdraw", player, amount)); - addBb(player.getName(), lang("bb.clan.withdraw", amount)); + player.sendMessage(AQUA + lang("player.clan.withdraw", player, CurrencyFormat.format(amount))); + addBb(player.getName(), lang("bb.clan.withdraw", CurrencyFormat.format(amount))); setBalance(getBalance() - amount); } } else { @@ -246,6 +248,16 @@ public double getBalance() { return balance; } + /** + * Returns the clan's balance formatted + * + * @return the balance formatted + */ + @Placeholder("balance_formatted") + public String getBalanceFormatted() { + return CurrencyFormat.format(balance); + } + /** * (used internally) * @@ -453,7 +465,7 @@ public long getFounded() { */ @Placeholder("founded") public String getFoundedString() { - return new java.text.SimpleDateFormat("MMM dd, ''yy h:mm a").format(new Date(this.founded)); + return DateFormat.formatDateTime(founded); } /** diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ClanPlayer.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ClanPlayer.java index f5c2b3e6c..4ece51b8a 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ClanPlayer.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ClanPlayer.java @@ -3,6 +3,7 @@ import net.sacredlabyrinth.phaed.simpleclans.hooks.papi.Placeholder; import net.sacredlabyrinth.phaed.simpleclans.managers.ProtectionManager.Action; import net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager; +import net.sacredlabyrinth.phaed.simpleclans.utils.DateFormat; import net.sacredlabyrinth.phaed.simpleclans.utils.VanishUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -487,8 +488,7 @@ public String getJoinDateString() { if (joinDate == 0) { return ""; } - - return new java.text.SimpleDateFormat("MMM dd, ''yy h:mm a").format(new Date(joinDate)); + return DateFormat.formatDateTime(joinDate); } /** @@ -512,7 +512,7 @@ public String getLastSeenString(@Nullable CommandSender sender) { if (!VanishUtils.isVanished(sender, this)) { return lang("online", sender); } - return new java.text.SimpleDateFormat("MMM dd, ''yy h:mm a").format(new Date(lastSeen)); + return DateFormat.formatDateTime(lastSeen); } /** diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/BankCommand.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/BankCommand.java index 0966ffd0e..2e78dc6df 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/BankCommand.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/BankCommand.java @@ -10,6 +10,7 @@ import net.sacredlabyrinth.phaed.simpleclans.loggers.BankLogger; import net.sacredlabyrinth.phaed.simpleclans.loggers.BankOperator; import net.sacredlabyrinth.phaed.simpleclans.managers.PermissionsManager; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -31,7 +32,7 @@ public class BankCommand extends BaseCommand { @Conditions("rank:name=BANK_BALANCE") @Description("{@@command.description.bank.status}") public void bankStatus(Player player, Clan clan) { - player.sendMessage(AQUA + lang("clan.balance", player, clan.getBalance())); + player.sendMessage(AQUA + lang("clan.balance", player, clan.getBalanceFormatted())); } @Subcommand("%withdraw %all") @@ -73,8 +74,8 @@ private void processWithdraw(Player player, Clan clan, double amount) { switch (clan.withdraw(operator, COMMAND, amount)) { case SUCCESS -> { if (permissions.grantPlayer(player, amount)) { - player.sendMessage(AQUA + lang("player.clan.withdraw", player, amount)); - clan.addBb(player.getName(), lang("bb.clan.withdraw", amount, player.getName())); + player.sendMessage(AQUA + lang("player.clan.withdraw", player, CurrencyFormat.format(amount))); + clan.addBb(player.getName(), lang("bb.clan.withdraw", CurrencyFormat.format(amount), player.getName())); } else { clan.setBalance(operator, REVERT, BankLogger.Operation.WITHDRAW, clan.getBalance() + amount); } @@ -121,15 +122,15 @@ private void processDeposit(Player player, Clan clan, double amount) { */ if (!permissions.playerHasMoney(player, amount)) { - player.sendMessage(AQUA + lang("not.sufficient.money", player, amount)); + player.sendMessage(AQUA + lang("not.sufficient.money", player, CurrencyFormat.format(amount))); return; } BankOperator operator = new BankOperator(player, permissions.playerGetMoney(player)); EconomyResponse response = clan.deposit(operator, COMMAND, amount); if (response == EconomyResponse.SUCCESS) { if (permissions.chargePlayer(player, amount)) { - player.sendMessage(AQUA + lang("player.clan.deposit", player, amount)); - clan.addBb(player.getName(), lang("bb.clan.deposit", amount, player.getName())); + player.sendMessage(AQUA + lang("player.clan.deposit", player, CurrencyFormat.format(amount))); + clan.addBb(player.getName(), lang("bb.clan.deposit", CurrencyFormat.format(amount), player.getName())); } else { //Reverts the deposit if something went wrong with Vault clan.setBalance(operator, REVERT, BankLogger.Operation.DEPOSIT, clan.getBalance() - amount); diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/ClanCommands.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/ClanCommands.java index 4f741a737..40f37ba7f 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/ClanCommands.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/ClanCommands.java @@ -10,6 +10,7 @@ import net.sacredlabyrinth.phaed.simpleclans.events.TagChangeEvent; import net.sacredlabyrinth.phaed.simpleclans.managers.*; import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -188,12 +189,12 @@ public void setFee(Player player, Clan clan, @Name("fee") double fee) { double maxFee = settings.getDouble(ECONOMY_MAX_MEMBER_FEE); if (fee > maxFee) { ChatBlock.sendMessage(player, RED - + lang("max.fee.allowed.is.0", player, maxFee)); + + lang("max.fee.allowed.is.0", player, CurrencyFormat.format(maxFee))); return; } if (cm.purchaseMemberFeeSet(player)) { clan.setMemberFee(fee); - clan.addBb(player.getName(), lang("bb.fee.set", fee)); + clan.addBb(player.getName(), lang("bb.fee.set", CurrencyFormat.format(fee))); ChatBlock.sendMessage(player, AQUA + lang("fee.set", player)); storage.updateClan(clan); } diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/LeaderCommands.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/LeaderCommands.java index 3d383c941..ac9b1fb16 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/LeaderCommands.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/clan/LeaderCommands.java @@ -9,6 +9,7 @@ import net.sacredlabyrinth.phaed.simpleclans.hooks.discord.DiscordHook; import net.sacredlabyrinth.phaed.simpleclans.hooks.discord.exceptions.DiscordHookException; import net.sacredlabyrinth.phaed.simpleclans.managers.*; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -238,7 +239,7 @@ public void discord(Player player, Clan clan) { double amount = settings.getDouble(ECONOMY_DISCORD_CREATION_PRICE); if (settings.is(ECONOMY_PURCHASE_DISCORD_CREATE)) { if (!permissions.playerHasMoney(player, amount)) { - player.sendMessage(AQUA + lang("not.sufficient.money", player, amount)); + player.sendMessage(AQUA + lang("not.sufficient.money", player, CurrencyFormat.format(amount))); return; } diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/general/GeneralCommands.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/general/GeneralCommands.java index 3e0501c68..79152cd79 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/general/GeneralCommands.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/general/GeneralCommands.java @@ -280,7 +280,7 @@ public void listBalance(CommandSender sender) { Clan clan = clans.get(i); String name = " " + (clan.isVerified() ? settings.getColored(PAGE_CLAN_NAME_COLOR) : GRAY) + clan.getName(); String line = MessageFormat.format(lineFormat, i + 1, leftBracket, clan.getColorTag(), - rightBracket, name, clan.getBalance()); + rightBracket, name, clan.getBalanceFormatted()); sender.sendMessage(line); } } diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/staff/BankCommand.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/staff/BankCommand.java index 60f5379c3..d1a713c75 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/staff/BankCommand.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/commands/staff/BankCommand.java @@ -10,6 +10,7 @@ import net.sacredlabyrinth.phaed.simpleclans.loggers.BankLogger; import net.sacredlabyrinth.phaed.simpleclans.loggers.BankOperator; import net.sacredlabyrinth.phaed.simpleclans.managers.PermissionsManager; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,7 +32,7 @@ public class BankCommand extends BaseCommand { @Description("{@@command.description.bank.admin.status}") public void status(CommandSender sender, @Name("clan") ClanInput clanInput) { Clan clan = clanInput.getClan(); - ChatBlock.sendMessage(sender, AQUA + lang("clan.admin.balance", sender, clan.getName(), clan.getBalance())); + ChatBlock.sendMessage(sender, AQUA + lang("clan.admin.balance", sender, clan.getName(), clan.getBalanceFormatted())); } @Subcommand("%take") @@ -46,8 +47,8 @@ public void take(CommandSender sender, @Name("clan") ClanInput clanInput, @Name( EconomyResponse economyResponse = clan.withdraw(operator, ClanBalanceUpdateEvent.Cause.COMMAND, amount); switch (economyResponse) { case SUCCESS: - ChatBlock.sendMessage(sender, AQUA + lang("clan.admin.take", sender, amount, clan.getName())); - clan.addBb(sender.getName(), lang("bb.clan.take", sender, amount, sender.getName())); + ChatBlock.sendMessage(sender, AQUA + lang("clan.admin.take", sender, CurrencyFormat.format(amount), clan.getName())); + clan.addBb(sender.getName(), lang("bb.clan.take", sender, CurrencyFormat.format(amount), sender.getName())); break; case NOT_ENOUGH_BALANCE: sender.sendMessage(RED + lang("clan.admin.bank.not.enough.money", sender, clan.getName())); @@ -66,8 +67,8 @@ public void give(CommandSender sender, @Name("clan") ClanInput clanInput, @Name( EconomyResponse economyResponse = clan.deposit(operator, ClanBalanceUpdateEvent.Cause.COMMAND, amount); if (economyResponse == EconomyResponse.SUCCESS) { - ChatBlock.sendMessage(sender, AQUA + lang("clan.admin.give", sender, amount, clan.getName())); - clan.addBb(sender.getName(), lang("bb.clan.give", sender, amount, sender.getName())); + ChatBlock.sendMessage(sender, AQUA + lang("clan.admin.give", sender, CurrencyFormat.format(amount), clan.getName())); + clan.addBb(sender.getName(), lang("bb.clan.give", sender, CurrencyFormat.format(amount), sender.getName())); } } @@ -82,8 +83,8 @@ public void set(CommandSender sender, @Name("clan") ClanInput clanInput, @Name(" EconomyResponse response = clan.setBalance(operator, ClanBalanceUpdateEvent.Cause.COMMAND, BankLogger.Operation.SET, amount); if (response == EconomyResponse.SUCCESS) { - ChatBlock.sendMessage(sender, AQUA + lang("clan.admin.set", sender, clan.getName(), amount)); - clan.addBb(sender.getName(), lang("bb.clan.set", sender, amount, sender.getName())); + ChatBlock.sendMessage(sender, AQUA + lang("clan.admin.set", sender, clan.getName(), CurrencyFormat.format(amount))); + clan.addBb(sender.getName(), lang("bb.clan.set", sender, CurrencyFormat.format(amount), sender.getName())); } } } diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/ClanManager.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/ClanManager.java index 49aaec678..951af514c 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/ClanManager.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/ClanManager.java @@ -8,6 +8,7 @@ import net.sacredlabyrinth.phaed.simpleclans.events.EconomyTransactionEvent.Cause; import net.sacredlabyrinth.phaed.simpleclans.loggers.BankOperator; import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import net.sacredlabyrinth.phaed.simpleclans.utils.VanishUtils; import net.sacredlabyrinth.phaed.simpleclans.uuid.UUIDMigration; import org.bukkit.Bukkit; @@ -78,7 +79,7 @@ public void addKill(Kill kill) { continue; } - //cleaning + // cleaning final int delay = plugin.getSettingsManager().getInt(KDR_DELAY_BETWEEN_KILLS); long timePassed = oldKill.getTime().until(LocalDateTime.now(), ChronoUnit.MINUTES); if (timePassed >= delay) { @@ -149,7 +150,7 @@ public void createClan(Player player, String colorTag, String name) { importClan(clan); plugin.getStorageManager().updateClanPlayer(cp); - plugin.getRequestManager().deny(cp); //denies any previous invitation + plugin.getRequestManager().deny(cp); // denies any previous invitation SimpleClans.getInstance().getPermissionsManager().updateClanPermissions(clan); SimpleClans.getInstance().getServer().getPluginManager().callEvent(new CreateClanEvent(clan)); } @@ -417,8 +418,10 @@ public void updateDisplayName(@Nullable Player player) { if (plugin.getSettingsManager().is(DISPLAY_CHAT_TAGS)) { String prefix = plugin.getPermissionsManager().getPrefix(player); - //String suffix = plugin.getPermissionsManager().getSuffix(player); - String lastColor = plugin.getSettingsManager().is(COLOR_CODE_FROM_PREFIX_FOR_NAME) ? ChatUtils.getLastColorCode(prefix) : ChatColor.WHITE + ""; + // String suffix = plugin.getPermissionsManager().getSuffix(player); + String lastColor = plugin.getSettingsManager().is(COLOR_CODE_FROM_PREFIX_FOR_NAME) + ? ChatUtils.getLastColorCode(prefix) + : ChatColor.WHITE + ""; String fullName = player.getName(); ClanPlayer cp = plugin.getClanManager().getAnyClanPlayer(player.getUniqueId()); @@ -932,9 +935,9 @@ public boolean purchaseMemberFeeSet(Player player) { if (plugin.getPermissionsManager().hasEconomy()) { if (plugin.getPermissionsManager().playerHasMoney(player, price)) { plugin.getPermissionsManager().chargePlayer(player, price, Cause.MEMBER_FEE_SET); - player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), price)); + player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), CurrencyFormat.format(price))); } else { - player.sendMessage(RED + lang("not.sufficient.money", player, price)); + player.sendMessage(RED + lang("not.sufficient.money", player, CurrencyFormat.format(price))); return false; } } @@ -955,9 +958,9 @@ public boolean purchaseCreation(Player player) { if (plugin.getPermissionsManager().hasEconomy()) { if (plugin.getPermissionsManager().playerHasMoney(player, price)) { plugin.getPermissionsManager().chargePlayer(player, price, Cause.CLAN_CREATION); - player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), price)); + player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), CurrencyFormat.format(price))); } else { - player.sendMessage(RED + lang("not.sufficient.money", player, price)); + player.sendMessage(RED + lang("not.sufficient.money", player, CurrencyFormat.format(price))); return false; } } @@ -978,9 +981,9 @@ public boolean purchaseInvite(Player player) { if (plugin.getPermissionsManager().hasEconomy()) { if (plugin.getPermissionsManager().playerHasMoney(player, price)) { plugin.getPermissionsManager().chargePlayer(player, price, Cause.CLAN_INVITATION); - player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), price)); + player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), CurrencyFormat.format(price))); } else { - player.sendMessage(RED + lang("not.sufficient.money", player, price)); + player.sendMessage(RED + lang("not.sufficient.money", player, CurrencyFormat.format(price))); return false; } } @@ -1001,9 +1004,9 @@ public boolean purchaseHomeTeleport(Player player) { if (plugin.getPermissionsManager().hasEconomy()) { if (plugin.getPermissionsManager().playerHasMoney(player, price)) { plugin.getPermissionsManager().chargePlayer(player, price, Cause.CLAN_HOME_TELEPORT); - player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), price)); + player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), CurrencyFormat.format(price))); } else { - player.sendMessage(RED + lang("not.sufficient.money", player, price)); + player.sendMessage(RED + lang("not.sufficient.money", player, CurrencyFormat.format(price))); return false; } } @@ -1024,9 +1027,9 @@ public boolean purchaseHomeTeleportSet(Player player) { if (plugin.getPermissionsManager().hasEconomy()) { if (plugin.getPermissionsManager().playerHasMoney(player, price)) { plugin.getPermissionsManager().chargePlayer(player, price, Cause.CLAN_HOME_TELEPORT_SET); - player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), price)); + player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), CurrencyFormat.format(price))); } else { - player.sendMessage(RED + lang("not.sufficient.money", player, price)); + player.sendMessage(RED + lang("not.sufficient.money", player, CurrencyFormat.format(price))); return false; } } @@ -1047,9 +1050,9 @@ public boolean purchaseResetKdr(Player player) { if (plugin.getPermissionsManager().hasEconomy()) { if (plugin.getPermissionsManager().playerHasMoney(player, price)) { plugin.getPermissionsManager().chargePlayer(player, price, Cause.RESET_KDR); - player.spigot().sendMessage(new TextComponent(RED + MessageFormat.format(lang("account.has.been.debited", player), price))); + player.spigot().sendMessage(new TextComponent(RED + MessageFormat.format(lang("account.has.been.debited", player), CurrencyFormat.format(price)))); } else { - player.spigot().sendMessage(new TextComponent(RED + MessageFormat.format(lang("not.sufficient.money", player), price))); + player.spigot().sendMessage(new TextComponent(RED + MessageFormat.format(lang("not.sufficient.money", player), CurrencyFormat.format(price)))); return false; } } @@ -1079,9 +1082,9 @@ public boolean purchaseHomeRegroup(Player player) { if (plugin.getSettingsManager().is(ECONOMY_ISSUER_PAYS_REGROUP) && plugin.getPermissionsManager().hasEconomy()) { if (plugin.getPermissionsManager().playerHasMoney(player, price)) { plugin.getPermissionsManager().chargePlayer(player, price, Cause.CLAN_REGROUP); - player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), price)); + player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), CurrencyFormat.format(price))); } else { - player.sendMessage(RED + lang("not.sufficient.money", player, price)); + player.sendMessage(RED + lang("not.sufficient.money", player, CurrencyFormat.format(price))); return false; } } else { @@ -1089,8 +1092,8 @@ public boolean purchaseHomeRegroup(Player player) { switch (clan.withdraw(new BankOperator(player, money), ClanBalanceUpdateEvent.Cause.COMMAND, price)) { case SUCCESS -> { if (plugin.getPermissionsManager().grantPlayer(player, price)) { - player.sendMessage(AQUA + lang("player.clan.withdraw", player, price)); - clan.addBb(player.getName(), lang("bb.clan.withdraw", price)); + player.sendMessage(AQUA + lang("player.clan.withdraw", player, CurrencyFormat.format(price))); + clan.addBb(player.getName(), lang("bb.clan.withdraw", CurrencyFormat.format(price))); return true; } } @@ -1114,9 +1117,9 @@ public boolean purchaseVerification(Player player) { if (plugin.getPermissionsManager().hasEconomy()) { if (plugin.getPermissionsManager().playerHasMoney(player, price)) { plugin.getPermissionsManager().chargePlayer(player, price, Cause.CLAN_VERIFICATION); - player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), price)); + player.sendMessage(RED + MessageFormat.format(lang("account.has.been.debited", player), CurrencyFormat.format(price))); } else { - player.sendMessage(RED + lang("not.sufficient.money", player, price)); + player.sendMessage(RED + lang("not.sufficient.money", player, CurrencyFormat.format(price))); return false; } } diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/PermissionsManager.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/PermissionsManager.java index 398a5fadf..2bb9e972c 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/PermissionsManager.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/PermissionsManager.java @@ -167,6 +167,9 @@ public List getPermissions(Clan clan) { return permissions.get(clan.getTag()); } + public String format(double value) { + return Objects.requireNonNull(economy, "Can't find economy provider").format(value); + } /** * Charge a player some money diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/SettingsManager.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/SettingsManager.java index 875adafbb..b0fae5042 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/SettingsManager.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/managers/SettingsManager.java @@ -150,7 +150,7 @@ public List getItemList() { * Check whether a word is disallowed * * @param word the world - * @return whether its a disallowed word + * @return whether its disallowed word */ public boolean isDisallowedWord(String word) { for (String disallowedTag : getStringList(DISALLOWED_TAGS)) { @@ -312,6 +312,7 @@ public enum ConfigField { USERNAME_REGEX("settings.username-regex", "^\\**[a-zA-Z0-9_$]{1,16}$"), TAG_REGEX("settings.tag-regex", ""), ACCEPT_OTHER_ALPHABETS_LETTERS("settings.accept-other-alphabets-letters-on-tag", false), + DATE_TIME_PATTERN("settings.date-time-pattern", "HH:mm - dd/MM/yyyy"), /* ================ > Tag Settings diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/tasks/CollectFeeTask.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/tasks/CollectFeeTask.java index c8d2407d7..0543e0793 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/tasks/CollectFeeTask.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/tasks/CollectFeeTask.java @@ -4,6 +4,7 @@ import net.sacredlabyrinth.phaed.simpleclans.loggers.BankOperator; import net.sacredlabyrinth.phaed.simpleclans.managers.PermissionsManager; import net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.scheduler.BukkitRunnable; @@ -54,7 +55,7 @@ public void run() { OfflinePlayer player = Bukkit.getOfflinePlayer(cp.getUniqueId()); boolean success = pm.chargePlayer(player, memberFee); if (success) { - ChatBlock.sendMessage(cp, AQUA + lang("fee.collected", cp, memberFee)); + ChatBlock.sendMessage(cp, AQUA + lang("fee.collected", cp, CurrencyFormat.format(memberFee))); clan.deposit(new BankOperator(cp, pm.playerGetMoney(player)), Cause.MEMBER_FEE, memberFee); plugin.getStorageManager().updateClan(clan); diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/tasks/CollectUpkeepTask.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/tasks/CollectUpkeepTask.java index 7396be5af..00c163ce1 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/tasks/CollectUpkeepTask.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/tasks/CollectUpkeepTask.java @@ -6,6 +6,7 @@ import net.sacredlabyrinth.phaed.simpleclans.events.ClanBalanceUpdateEvent; import net.sacredlabyrinth.phaed.simpleclans.loggers.BankOperator; import net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import org.bukkit.scheduler.BukkitRunnable; import java.text.MessageFormat; @@ -59,7 +60,7 @@ public void run() { clan.disband(null, true, false); } if (response == EconomyResponse.SUCCESS) { - clan.addBb(MessageFormat.format(lang("upkeep.collected"), upkeep), false); + clan.addBb(MessageFormat.format(lang("upkeep.collected"), CurrencyFormat.format(upkeep)), false); } }); } diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/ClanDetailsFrame.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/ClanDetailsFrame.java index 430adedcd..f1f7dcf21 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/ClanDetailsFrame.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/ClanDetailsFrame.java @@ -9,6 +9,7 @@ import net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager; import net.sacredlabyrinth.phaed.simpleclans.ui.*; import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import net.sacredlabyrinth.phaed.simpleclans.utils.VanishUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -164,7 +165,7 @@ private void addVerify() { List lore = verified ? null : new ArrayList<>(); if (!verified) { if (purchaseVerification) { - lore.add(lang("gui.clandetails.verify.price.lore", getViewer(), settings.getDouble(ECONOMY_VERIFICATION_PRICE))); + lore.add(lang("gui.clandetails.verify.price.lore", getViewer(), CurrencyFormat.format(settings.getDouble(ECONOMY_VERIFICATION_PRICE)))); } lore.add(lang("gui.clandetails.not.verified.lore", getViewer())); } @@ -180,7 +181,7 @@ private void addBank() { String withdrawStatus = clan.isAllowWithdraw() ? lang("allowed",getViewer()) : lang("blocked",getViewer()); String depositStatus = clan.isAllowDeposit() ? lang("allowed", getViewer()) : lang("blocked", getViewer()); SCComponent bank = new SCComponentImpl(lang("gui.clandetails.bank.title", getViewer()), - Arrays.asList(lang("gui.clandetails.bank.balance.lore", getViewer(), clan.getBalance()), + Arrays.asList(lang("gui.clandetails.bank.balance.lore", getViewer(), clan.getBalanceFormatted()), lang("gui.clandetails.bank.withdraw.status.lore", getViewer(), withdrawStatus), lang("gui.clandetails.bank.deposit.status.lore", getViewer(), depositStatus), lang("gui.clandetails.bank.withdraw.toggle.lore", getViewer()), @@ -245,7 +246,7 @@ private void addRegroup() { } List lore = new ArrayList<>(); - if (price != 0) lore.add(lang("gui.clandetails.regroup.lore.price", getViewer(), price)); + if (price != 0) lore.add(lang("gui.clandetails.regroup.lore.price", getViewer(), CurrencyFormat.format(price))); lore.add(lang("gui.clandetails.regroup.lore.home", getViewer())); lore.add(lang("gui.clandetails.regroup.lore.me", getViewer())); @@ -267,9 +268,9 @@ private void addHome() { double setPrice = settings.is(ECONOMY_PURCHASE_HOME_TELEPORT_SET) ? settings.getDouble(ECONOMY_HOME_TELEPORT_SET_PRICE) : 0; List lore = new ArrayList<>(); - if (homePrice != 0) lore.add(lang("gui.clandetails.home.lore.teleport.price", getViewer(), homePrice)); + if (homePrice != 0) lore.add(lang("gui.clandetails.home.lore.teleport.price", getViewer(), CurrencyFormat.format(homePrice))); lore.add(lang("gui.clandetails.home.lore.teleport", getViewer())); - if (setPrice != 0) lore.add(lang("gui.clandetails.home.lore.set.price", getViewer(), setPrice)); + if (setPrice != 0) lore.add(lang("gui.clandetails.home.lore.set.price", getViewer(), CurrencyFormat.format(setPrice))); lore.add(lang("gui.clandetails.home.lore.set", getViewer())); lore.add(lang("gui.clandetails.home.lore.clear", getViewer())); diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/Components.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/Components.java index a0400126e..af87d592c 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/Components.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/Components.java @@ -6,10 +6,7 @@ import net.sacredlabyrinth.phaed.simpleclans.Helper; import net.sacredlabyrinth.phaed.simpleclans.SimpleClans; import net.sacredlabyrinth.phaed.simpleclans.ui.*; -import net.sacredlabyrinth.phaed.simpleclans.utils.ChatUtils; -import net.sacredlabyrinth.phaed.simpleclans.utils.KDRFormat; -import net.sacredlabyrinth.phaed.simpleclans.utils.Paginator; -import net.sacredlabyrinth.phaed.simpleclans.utils.VanishUtils; +import net.sacredlabyrinth.phaed.simpleclans.utils.*; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -121,7 +118,7 @@ public static SCComponent getClanComponent(@NotNull SCFrame frame, @NotNull Play double price = pl.getSettingsManager().is(ECONOMY_PURCHASE_CLAN_CREATE) ? pl.getSettingsManager().getDouble(ECONOMY_CREATION_PRICE) : 0; lore = new ArrayList<>(); if (price != 0) { - lore.add(lang("gui.clandetails.free.agent.create.clan.price.lore", frame.getViewer(), price)); + lore.add(lang("gui.clandetails.free.agent.create.clan.price.lore", frame.getViewer(), CurrencyFormat.format(price))); } lore.add(lang("gui.clandetails.free.agent.create.clan.lore", frame.getViewer())); } diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/InviteFrame.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/InviteFrame.java index 13a242e60..ee7aa3c2f 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/InviteFrame.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/InviteFrame.java @@ -5,6 +5,7 @@ import net.sacredlabyrinth.phaed.simpleclans.SimpleClans; import net.sacredlabyrinth.phaed.simpleclans.managers.ClanManager; import net.sacredlabyrinth.phaed.simpleclans.ui.*; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import net.sacredlabyrinth.phaed.simpleclans.utils.Paginator; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -54,7 +55,7 @@ public void createComponents() { private SCComponent createPlayerComponent(@NotNull Player player, int slot) { double price = plugin.getSettingsManager().is(ECONOMY_PURCHASE_CLAN_INVITE) ? plugin.getSettingsManager().getDouble(ECONOMY_INVITE_PRICE) : 0; List lore = new ArrayList<>(); - if (price != 0) lore.add(lang("gui.invite.player.price.lore", getViewer(), price)); + if (price != 0) lore.add(lang("gui.invite.player.price.lore", getViewer(), CurrencyFormat.format(price))); lore.add(lang("gui.invite.player.lore", getViewer())); SCComponent c = new SCComponentImpl( diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/MainFrame.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/MainFrame.java index fac059856..0bc86f456 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/MainFrame.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/MainFrame.java @@ -4,6 +4,7 @@ import net.sacredlabyrinth.phaed.simpleclans.SimpleClans; import net.sacredlabyrinth.phaed.simpleclans.ui.*; import net.sacredlabyrinth.phaed.simpleclans.ui.frames.staff.StaffFrame; +import net.sacredlabyrinth.phaed.simpleclans.utils.CurrencyFormat; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.jetbrains.annotations.NotNull; @@ -93,8 +94,9 @@ public void addResetKdr() { List resetKdrLore; if (plugin.getSettingsManager().is(ECONOMY_PURCHASE_RESET_KDR)) { + double price = plugin.getSettingsManager().getDouble(ECONOMY_RESET_KDR_PRICE); resetKdrLore = Arrays.asList( - lang("gui.main.reset.kdr.lore.price", getViewer(), plugin.getSettingsManager().getString(ECONOMY_RESET_KDR_PRICE)), + lang("gui.main.reset.kdr.lore.price", getViewer(), CurrencyFormat.format(price)), lang("gui.main.reset.kdr.lore", getViewer())); } else { resetKdrLore = Collections.singletonList(lang("gui.main.reset.kdr.lore", getViewer())); diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/staff/ClanDetailsFrame.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/staff/ClanDetailsFrame.java index c98822355..49890c3eb 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/staff/ClanDetailsFrame.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/ui/frames/staff/ClanDetailsFrame.java @@ -112,7 +112,7 @@ private void addRoster() { } private void addBank() { - List lore = Collections.singletonList(lang("gui.clandetails.bank.balance.lore", getViewer(), clan.getBalance())); + List lore = Collections.singletonList(lang("gui.clandetails.bank.balance.lore", getViewer(), clan.getBalanceFormatted())); SCComponent bank = new SCComponentImpl(lang("gui.clandetails.bank.title", getViewer()), lore, XMaterial.GOLD_INGOT, 40); add(bank); diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/ChatUtils.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/ChatUtils.java index bc50c33af..0b3a314c4 100644 --- a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/ChatUtils.java +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/ChatUtils.java @@ -47,7 +47,7 @@ public static String parseColors(@NotNull String text) { // https://www.spigotmc.org/threads/hex-color-code-translate.449748/#post-3867795 if (HEX_COLOR_SUPPORT) { Matcher matcher = HEX_COLOR_PATTERN.matcher(text); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); while (matcher.find()) { matcher.appendReplacement(buffer, ChatColor.of("#" + matcher.group(1)).toString()); } @@ -59,7 +59,7 @@ public static String parseColors(@NotNull String text) { public static String stripColors(String text) { Pattern pattern = HEX_COLOR_SUPPORT ? HEX_STRIP_COLOR_PATTERN : STRIP_COLOR_PATTERN; Matcher matcher = pattern.matcher(text); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); while (matcher.find()) { matcher.appendReplacement(buffer, ""); } @@ -162,4 +162,5 @@ public static void applyLastColorToFollowingLines(@NotNull List lines) { } } } + } diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/CurrencyFormat.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/CurrencyFormat.java new file mode 100644 index 000000000..a53cc59f7 --- /dev/null +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/CurrencyFormat.java @@ -0,0 +1,21 @@ +package net.sacredlabyrinth.phaed.simpleclans.utils; + +import net.sacredlabyrinth.phaed.simpleclans.SimpleClans; +import net.sacredlabyrinth.phaed.simpleclans.managers.PermissionsManager; + +import java.text.NumberFormat; + +public class CurrencyFormat { + + private static final SimpleClans plugin = SimpleClans.getInstance(); + private static final NumberFormat fallbackFormat = NumberFormat.getCurrencyInstance(); + + public static String format(double value) { + PermissionsManager permissionsManager = plugin.getPermissionsManager(); + if (permissionsManager.hasEconomy()) { + return permissionsManager.format(value); + } + return fallbackFormat.format(value); + } + +} diff --git a/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/DateFormat.java b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/DateFormat.java new file mode 100644 index 000000000..22bcf654f --- /dev/null +++ b/src/main/java/net/sacredlabyrinth/phaed/simpleclans/utils/DateFormat.java @@ -0,0 +1,29 @@ +package net.sacredlabyrinth.phaed.simpleclans.utils; + +import net.sacredlabyrinth.phaed.simpleclans.SimpleClans; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import static net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager.ConfigField.DATE_TIME_PATTERN; + +public class DateFormat { + + private static final SimpleClans plugin = SimpleClans.getInstance(); + private static SimpleDateFormat format; + + static { + String pattern = plugin.getSettingsManager().getString(DATE_TIME_PATTERN); + try { + format = new SimpleDateFormat(pattern); + } catch (IllegalArgumentException ex) { + plugin.getLogger().warning("%s is not a valid pattern!".formatted(pattern)); + format = new SimpleDateFormat("HH:mm - dd/MM/yyyy"); + } + } + + public static String formatDateTime(long date) { + return format.format(new Date(date)); + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 14c7c8018..41e569833 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -56,6 +56,7 @@ settings: past-clans-limit: 10 username-regex: '(\.|\*){0,1}[a-zA-Z0-9_$]{1,16}' tag-regex: '' + date-time-pattern: 'HH:mm - dd/MM/yyyy' war-and-protection: war-enabled: false land-sharing: true