Uses Economy.format to display costs

This commit is contained in:
2022-11-14 00:36:23 +00:00
parent 8e3a71a489
commit 7355b7fc60
4 changed files with 13 additions and 19 deletions

View File

@ -170,9 +170,8 @@ public class SignListener implements Listener {
* @return <p>The message with the cost instead of the cost placeholder</p>
*/
private String replaceCost(double cost, TranslatableMessage message) {
String unit = EconomyManager.getCurrency(cost != 1);
return String.format(PaidSigns.getStringFormatter().replacePlaceholders(message,
new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), cost, unit);
return PaidSigns.getStringFormatter().replacePlaceholder(message,
"{cost}", EconomyManager.format(cost));
}
}

View File

@ -35,17 +35,13 @@ public final class EconomyManager {
}
/**
* Gets the name of the used currency
* Formats the given amount of currency according to the economy plugin's format
*
* @param plural <p>Whether to get the plural name or the singular name</p>
* @return <p>The name of the used currency</p>
* @param amount <p>The amount of currency to format</p>
* @return <p>The formatted string</p>
*/
public static String getCurrency(boolean plural) {
if (plural) {
return economy.currencyNamePlural();
} else {
return economy.currencyNameSingular();
}
public static String format(double amount) {
return economy.format(amount);
}
/**

View File

@ -162,10 +162,9 @@ public final class TrackedSignManager {
}
EconomyManager.deposit(offlinePlayer, refundSum);
if (offlinePlayer instanceof Player player) {
PaidSigns.getStringFormatter().displaySuccessMessage(player, String.format(
PaidSigns.getStringFormatter().replacePlaceholders(PaidSignsTranslatableMessage.SUCCESS_REFUNDED,
new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), refundSum,
EconomyManager.getCurrency(refundSum != 1)));
PaidSigns.getStringFormatter().displaySuccessMessage(player,
PaidSigns.getStringFormatter().replacePlaceholder(PaidSignsTranslatableMessage.SUCCESS_REFUNDED,
"{cost}", EconomyManager.format(refundSum)));
}
}