Search in sources :

Example 1 with LocaleManager

use of org.black_ixx.playerpoints.manager.LocaleManager in project PlayerPoints by Rosewood-Development.

the class PointsUtils method setCachedValues.

public static void setCachedValues(RosePlugin rosePlugin) {
    LocaleManager localeManager = rosePlugin.getManager(LocaleManager.class);
    String separator = localeManager.getLocaleMessage("currency-separator");
    DecimalFormat decimalFormat = new DecimalFormat();
    DecimalFormatSymbols symbols = decimalFormat.getDecimalFormatSymbols();
    if (!separator.isEmpty()) {
        symbols.setGroupingSeparator(separator.charAt(0));
        decimalFormat.setGroupingUsed(true);
        decimalFormat.setGroupingSize(3);
        decimalFormat.setDecimalFormatSymbols(symbols);
        formatter = decimalFormat;
    } else {
        formatter = null;
    }
    suffixes.clear();
    suffixes.put(1_000L, localeManager.getLocaleMessage("number-abbreviation-thousands"));
    suffixes.put(1_000_000L, localeManager.getLocaleMessage("number-abbreviation-millions"));
    suffixes.put(1_000_000_000L, localeManager.getLocaleMessage("number-abbreviation-billions"));
    decimal = localeManager.getLocaleMessage("currency-decimal");
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) LocaleManager(org.black_ixx.playerpoints.manager.LocaleManager)

Example 2 with LocaleManager

use of org.black_ixx.playerpoints.manager.LocaleManager in project PlayerPoints by Rosewood-Development.

the class ConvertCommand method execute.

@Override
public void execute(PlayerPoints plugin, CommandSender sender, String[] args) {
    LocaleManager localeManager = plugin.getManager(LocaleManager.class);
    if (args.length < 1) {
        localeManager.sendMessage(sender, "command-convert-usage");
        return;
    }
    CurrencyPlugin currencyPlugin = CurrencyPlugin.get(args[0]);
    ConversionManager conversionManager = plugin.getManager(ConversionManager.class);
    if (currencyPlugin == null || !conversionManager.getEnabledConverters().contains(currencyPlugin)) {
        localeManager.sendMessage(sender, "command-convert-invalid", StringPlaceholders.single("plugin", args[0]));
        return;
    }
    if (args.length != 2 || !args[1].equalsIgnoreCase("confirm")) {
        localeManager.sendMessage(sender, "command-convert-warning", StringPlaceholders.single("plugin", args[0]));
        return;
    }
    Bukkit.getScheduler().runTaskAsynchronously(PlayerPoints.getInstance(), () -> {
        if (conversionManager.convert(currencyPlugin)) {
            localeManager.sendMessage(sender, "command-convert-success", StringPlaceholders.single("plugin", args[0]));
        } else {
            localeManager.sendMessage(sender, "command-convert-failure");
        }
    });
}
Also used : CurrencyPlugin(org.black_ixx.playerpoints.conversion.CurrencyPlugin) ConversionManager(org.black_ixx.playerpoints.manager.ConversionManager) LocaleManager(org.black_ixx.playerpoints.manager.LocaleManager)

Example 3 with LocaleManager

use of org.black_ixx.playerpoints.manager.LocaleManager in project PlayerPoints by Rosewood-Development.

the class GiveAllCommand method execute.

@Override
public void execute(PlayerPoints plugin, CommandSender sender, String[] args) {
    LocaleManager localeManager = plugin.getManager(LocaleManager.class);
    if (args.length < 1) {
        localeManager.sendMessage(sender, "command-giveall-usage");
        return;
    }
    try {
        int amount = Integer.parseInt(args[0]);
        boolean includeOffline = args.length > 1 && args[1].equals("*");
        Bukkit.getScheduler().runTaskAsynchronously(PlayerPoints.getInstance(), () -> {
            boolean success;
            if (includeOffline) {
                success = plugin.getManager(DataManager.class).offsetAllPoints(amount);
            } else {
                List<UUID> playerIds = Bukkit.getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toList());
                success = plugin.getAPI().giveAll(playerIds, amount);
            }
            if (success) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    localeManager.sendMessage(player, "command-give-received", StringPlaceholders.builder("amount", PointsUtils.formatPoints(amount)).addPlaceholder("currency", localeManager.getCurrencyName(amount)).build());
                }
                localeManager.sendMessage(sender, "command-giveall-success", StringPlaceholders.builder("amount", PointsUtils.formatPoints(amount)).addPlaceholder("currency", localeManager.getCurrencyName(amount)).build());
            }
        });
    } catch (NumberFormatException e) {
        localeManager.sendMessage(sender, "invalid-amount");
    }
}
Also used : Player(org.bukkit.entity.Player) LocaleManager(org.black_ixx.playerpoints.manager.LocaleManager) UUID(java.util.UUID)

Example 4 with LocaleManager

use of org.black_ixx.playerpoints.manager.LocaleManager in project PlayerPoints by Rosewood-Development.

the class GiveCommand method execute.

@Override
public void execute(PlayerPoints plugin, CommandSender sender, String[] args) {
    LocaleManager localeManager = plugin.getManager(LocaleManager.class);
    if (args.length < 2) {
        localeManager.sendMessage(sender, "command-give-usage");
        return;
    }
    Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
        OfflinePlayer player = PointsUtils.getPlayerByName(args[0]);
        if (!player.hasPlayedBefore() && !player.isOnline()) {
            localeManager.sendMessage(sender, "unknown-player", StringPlaceholders.single("player", args[0]));
            return;
        }
        try {
            int amount = Integer.parseInt(args[1]);
            if (amount <= 0) {
                localeManager.sendMessage(sender, "invalid-amount");
                return;
            }
            if (plugin.getAPI().give(player.getUniqueId(), amount)) {
                // Send message to receiver
                if (player.isOnline()) {
                    localeManager.sendMessage((Player) player, "command-give-received", StringPlaceholders.builder("amount", PointsUtils.formatPoints(amount)).addPlaceholder("currency", localeManager.getCurrencyName(amount)).build());
                }
                // Send message to sender
                localeManager.sendMessage(sender, "command-give-success", StringPlaceholders.builder("amount", PointsUtils.formatPoints(amount)).addPlaceholder("currency", localeManager.getCurrencyName(amount)).addPlaceholder("player", player.getName()).build());
            }
        } catch (NumberFormatException e) {
            localeManager.sendMessage(sender, "invalid-amount");
        }
    });
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) LocaleManager(org.black_ixx.playerpoints.manager.LocaleManager)

Example 5 with LocaleManager

use of org.black_ixx.playerpoints.manager.LocaleManager in project PlayerPoints by Rosewood-Development.

the class HelpCommand method execute.

@Override
public void execute(PlayerPoints plugin, CommandSender sender, String[] args) {
    LocaleManager localeManager = plugin.getManager(LocaleManager.class);
    // Send header
    localeManager.sendMessage(sender, "command-help-title");
    // Send command descriptions the sender has permission for
    for (NamedExecutor executor : this.commandHandler.getExecutables()) if (executor.hasPermission(sender))
        localeManager.sendSimpleMessage(sender, "command-" + executor.getName() + "-description");
}
Also used : LocaleManager(org.black_ixx.playerpoints.manager.LocaleManager)

Aggregations

LocaleManager (org.black_ixx.playerpoints.manager.LocaleManager)16 OfflinePlayer (org.bukkit.OfflinePlayer)7 Player (org.bukkit.entity.Player)4 DataManager (org.black_ixx.playerpoints.manager.DataManager)3 SortedPlayer (org.black_ixx.playerpoints.models.SortedPlayer)3 File (java.io.File)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 MySQLConnector (dev.rosewood.rosegarden.database.MySQLConnector)1 IOException (java.io.IOException)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 TreeSet (java.util.TreeSet)1 UUID (java.util.UUID)1 CurrencyPlugin (org.black_ixx.playerpoints.conversion.CurrencyPlugin)1 ConversionManager (org.black_ixx.playerpoints.manager.ConversionManager)1