This commit is contained in:
BenceX100 2024-04-17 17:21:43 +02:00
parent 03fad3cd50
commit ba1e3fb28b
6 changed files with 37 additions and 8 deletions

View File

@ -56,7 +56,7 @@ public final class AxTrade extends AxPlugin {
MESSAGEUTILS = new MessageUtils(LANG.getBackingDocument(), "prefix", CONFIG.getBackingDocument());
threadedQueue = new ThreadedQueue<>("AxRewards-Datastore-thread");
threadedQueue = new ThreadedQueue<>("AxTrade-Datastore-thread");
BUKKITAUDIENCES = BukkitAudiences.create(this);

View File

@ -179,8 +179,8 @@ public class TradeGui extends GuiFrame {
if (trade.ended) return;
trade.prepTime = System.currentTimeMillis();
String am = result.getLine(0);
TradePlayer.Result addResult = TradePlayer.Result.NOT_A_NUMBER;
if (com.artillexstudios.axapi.utils.NumberUtils.isDouble(am) && (addResult = player.setCurrency(currencyStr, Double.parseDouble(am))) == TradePlayer.Result.SUCCESS) {
TradePlayer.Result addResult = player.setCurrency(currencyStr, am);
if (addResult == TradePlayer.Result.SUCCESS) {
MESSAGEUTILS.sendLang(player1, "currency-editor.success");
} else {
switch (addResult) {

View File

@ -2,6 +2,7 @@ package com.artillexstudios.axtrade.trade;
import com.artillexstudios.axtrade.hooks.HookManager;
import com.artillexstudios.axtrade.hooks.currency.CurrencyHook;
import com.artillexstudios.axtrade.utils.NumberUtils;
import com.artillexstudios.axtrade.utils.SoundUtils;
import org.bukkit.entity.Player;
@ -88,7 +89,10 @@ public class TradePlayer {
return currencies.get(currencyHook);
}
public Result setCurrency(String currency, double amount) {
public Result setCurrency(String currency, String am) {
final Double unformatted = NumberUtils.parseNumber(am);
if (unformatted == null && !com.artillexstudios.axapi.utils.NumberUtils.isDouble(am)) return Result.NOT_A_NUMBER;
double amount = unformatted == null ? Double.parseDouble(am) : unformatted;
if (Double.isNaN(amount)) return Result.NOT_A_NUMBER;
final CurrencyHook currencyHook = HookManager.getCurrencyHook(currency);
if (currencyHook == null) return Result.CURRENCY_NOT_FOUND;

View File

@ -1,23 +1,29 @@
package com.artillexstudios.axtrade.utils;
import org.jetbrains.annotations.Nullable;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;
import static com.artillexstudios.axtrade.AxTrade.CONFIG;
public class NumberUtils {
private static NumberFormat formatter = new DecimalFormat(CONFIG.getString("number-formatting.formatted", "#,###.##"));
private static NumberFormat shortFormat = new DecimalFormat(CONFIG.getString("number-formatting.formatted", "#,###.##"));
public static void reload() {
final String[] lang = CONFIG.getString("number-formatting.short", "en_US").split("_");
shortFormat = DecimalFormat.getCompactNumberInstance(new Locale(lang[0], lang[1]), NumberFormat.Style.SHORT);
int mode = CONFIG.getInt("number-formatting.mode", 0);
switch (mode) {
case 0:
formatter = new DecimalFormat(CONFIG.getString("number-formatting.formatted", "#,###.##"));
break;
case 1:
final String[] lang = CONFIG.getString("number-formatting.short", "en_US").split("_");
formatter = DecimalFormat.getCompactNumberInstance(new Locale(lang[0], lang[1]), NumberFormat.Style.SHORT);
formatter = shortFormat;
break;
case 2:
formatter = null;
@ -28,4 +34,13 @@ public class NumberUtils {
public static String formatNumber(double number) {
return formatter == null ? "" + number : formatter.format(number);
}
@Nullable
public static Double parseNumber(String number) {
try {
return shortFormat.parse(number.toUpperCase()).doubleValue();
} catch (ParseException ex) {
return null;
}
}
}

View File

@ -22,7 +22,7 @@ public class SoundUtils {
final Sound sound = Sound.sound().type(Key.key(LANG.getString("sounds." + route))).build();
BUKKITAUDIENCES.player(player).playSound(sound);
} catch (InvalidKeyException ex) {
Bukkit.getConsoleSender().sendMessage(StringUtils.formatToString("&#FFFFAA[AxAuctions] The sound %sound% does not exist, section: %section%!".replace("%sound%", LANG.getString("sounds." + route)).replace("%section%", route)));
Bukkit.getConsoleSender().sendMessage(StringUtils.formatToString("&#FF0000[AxTrade] The sound %sound% does not exist, section: %section%!".replace("%sound%", LANG.getString("sounds." + route)).replace("%section%", route)));
}
}
}

View File

@ -5,4 +5,14 @@ api-version: '1.18'
folia-supported: true
softdepend:
- PlaceholderAPI
- AxQuestBoard
- CoinsEngine
- Kingdoms
- PlaceholderAPI
- PlayerPoints
- RivalHarvesterHoes
- RoyaleEconomy
- SuperMobCoins
- TheOnly-MobCoins
- TokenManager
- UltraEconomy