11package com .devkeni .balanceformatter .util ;
22
3- import lombok .RequiredArgsConstructor ;
4- import net .milkbowl .vault .economy .Economy ;
5- import org .bukkit .entity .Player ;
6- import org .bukkit .plugin .Plugin ;
3+ import com .devkeni .balanceformatter .BalanceFormatter ;
74
85import java .text .DecimalFormat ;
96
10- @ RequiredArgsConstructor
117public class NumberUtils {
128
13- private final Plugin plugin ;
14- private final Economy economy ;
9+ private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat ("###.#" );
1510
16- private final DecimalFormat DECIMAL_FORMAT = new DecimalFormat ("###,###.##" );
17-
18- public String getMoneyFormatted (Player player ) {
19- return format (economy .getBalance (player ));
20- }
21-
22- private String formatLarge (double n , int iteration ) {
11+ private static String formatLarge (double n , int iteration ) {
2312 double f = n / 1000.0D ;
2413 return f < 1000 || iteration >= getNumberFormat ().length - 1 ?
25- formatShort (f ) + getNumberFormat ()[iteration ] : formatLarge (f , iteration + 1 );
26- }
27-
28- private String formatShort (double value ) {
29- return DECIMAL_FORMAT .format (value );
14+ DECIMAL_FORMAT .format (f ) + getNumberFormat ()[iteration ] : formatLarge (f , iteration + 1 );
3015 }
3116
32- private String format (double value ) {
33- return value < 1000 ? formatShort (value ) : formatLarge (value , 0 );
17+ public static String format (double value ) {
18+ return value < 1000 ? DECIMAL_FORMAT . format (value ) : formatLarge (value , 0 );
3419 }
3520
36- private String [] getNumberFormat () {
37- return plugin .getConfig ().getString ("money-format" ).split (";" );
21+ private static String [] getNumberFormat () {
22+ return BalanceFormatter . getInstance () .getConfig ().getString ("money-format" ).split (";" );
3823 }
3924
4025}
0 commit comments