mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-22 10:05:16 +01:00
Merge pull request #46 from MegaNarwhal/master
Allow custom balance format string
This commit is contained in:
commit
dc6909af0f
@ -1,6 +1,7 @@
|
||||
package org.appledash.saneeconomy.economy;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.appledash.saneeconomy.utils.MessageUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
@ -16,11 +17,20 @@ public class Currency {
|
||||
private final String nameSingular;
|
||||
private final String namePlural;
|
||||
private final DecimalFormat format;
|
||||
private final String formatBalance;
|
||||
|
||||
public Currency(String nameSingular, String namePlural, DecimalFormat format) {
|
||||
this.nameSingular = nameSingular;
|
||||
this.namePlural = namePlural;
|
||||
this.format = format;
|
||||
this.formatBalance = "{1} {2}";
|
||||
}
|
||||
|
||||
public Currency(String nameSingular,String namePlural,DecimalFormat format,String formatBalance){
|
||||
this.nameSingular = nameSingular;
|
||||
this.namePlural = namePlural;
|
||||
this.format = format;
|
||||
this.formatBalance = formatBalance;
|
||||
}
|
||||
|
||||
public static Currency fromConfig(ConfigurationSection config) {
|
||||
@ -48,7 +58,8 @@ public class Currency {
|
||||
return new Currency(
|
||||
config.getString("name.singular", "dollar"),
|
||||
config.getString("name.plural", "dollars"),
|
||||
format
|
||||
format,
|
||||
config.getString("balance-format","%s %s")
|
||||
);
|
||||
}
|
||||
|
||||
@ -59,10 +70,11 @@ public class Currency {
|
||||
*/
|
||||
public String formatAmount(double amount) {
|
||||
if (amount == 1) {
|
||||
return String.format("%s %s", format.format(amount), nameSingular);
|
||||
return MessageUtils.indexedFormat(formatBalance, format.format(amount), nameSingular);
|
||||
// return String.format(formatBalance, format.format(amount), nameSingular);
|
||||
}
|
||||
|
||||
return String.format("%s %s", format.format(amount), namePlural);
|
||||
return MessageUtils.indexedFormat(formatBalance, format.format(amount), namePlural);
|
||||
// return String.format(formatBalance, format.format(amount), namePlural);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ currency:
|
||||
name:
|
||||
singular: dollar
|
||||
plural: dollars
|
||||
balance-format: '{1} {2}'
|
||||
format: '0.00'
|
||||
grouping: 3
|
||||
grouping-separator: ','
|
||||
|
Loading…
Reference in New Issue
Block a user