diff --git a/CoinsEngine.iml b/CoinsEngine.iml new file mode 100644 index 0000000..01358e7 --- /dev/null +++ b/CoinsEngine.iml @@ -0,0 +1,14 @@ + + + + + + + SPIGOT + BUKKIT + + 1 + + + + \ No newline at end of file diff --git a/libs/nightcore.jar b/libs/nightcore.jar new file mode 100644 index 0000000..4cee9fa Binary files /dev/null and b/libs/nightcore.jar differ diff --git a/pom.xml b/pom.xml index 8db233e..6621926 100644 --- a/pom.xml +++ b/pom.xml @@ -106,4 +106,4 @@ - \ No newline at end of file + diff --git a/src/main/java/su/nightexpress/coinsengine/api/event/CoinsExchangeEvent.java b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsExchangeEvent.java new file mode 100644 index 0000000..0682e0b --- /dev/null +++ b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsExchangeEvent.java @@ -0,0 +1,77 @@ +package su.nightexpress.coinsengine.api.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import su.nightexpress.coinsengine.api.currency.Currency; +import org.jetbrains.annotations.NotNull; + +public class CoinsExchangeEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final Player user; + private final Currency fromCurrency; + private final Currency toCurrency; + private double fromAmount; + private double toAmount; + + public CoinsExchangeEvent(@NotNull Player user, @NotNull Currency fromCurrency, @NotNull Currency toCurrency, double fromAmount, double toAmount) { + this.user = user; + this.fromCurrency = fromCurrency; + this.toCurrency = toCurrency; + this.fromAmount = fromAmount; + this.toAmount = toAmount; + } + + @NotNull + public Player getUser() { + return user; + } + + @NotNull + public Currency getFromCurrency() { + return fromCurrency; + } + + @NotNull + public Currency getToCurrency() { + return toCurrency; + } + + public double getFromAmount() { + return fromAmount; + } + + public void setFromAmount(double fromAmount) { + this.fromAmount = fromAmount; + } + + public double getToAmount() { + return toAmount; + } + + public void setToAmount(double toAmount) { + this.toAmount = toAmount; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} \ No newline at end of file diff --git a/src/main/java/su/nightexpress/coinsengine/api/event/CoinsGiveEvent.java b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsGiveEvent.java new file mode 100644 index 0000000..676b141 --- /dev/null +++ b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsGiveEvent.java @@ -0,0 +1,66 @@ +package su.nightexpress.coinsengine.api.event; + +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import su.nightexpress.coinsengine.api.currency.Currency; +import su.nightexpress.coinsengine.data.impl.CoinsUser; +import org.jetbrains.annotations.NotNull; + +public class CoinsGiveEvent extends Event{ + private static final HandlerList handlers = new HandlerList(); + private final OfflinePlayer user; + private final CommandSender from; + private final Currency currency; + private final String currencyName; + private double amount; + + public CoinsGiveEvent(@NotNull OfflinePlayer user, @NotNull Currency currency, double amount, @NotNull CommandSender from) { + this.user = user; + this.currency = currency; + this.currencyName = currency.getName(); + this.amount = amount; + this.from = from; + } + + @NotNull + public OfflinePlayer getUser() { + return user; + } + + @NotNull + public CommandSender getFrom() { + return from; + } + + public String getCurrencyName() { + return currencyName; + } + + @NotNull + public Currency getCurrency() { + return currency; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } + + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} \ No newline at end of file diff --git a/src/main/java/su/nightexpress/coinsengine/api/event/CoinsSendEvent.java b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsSendEvent.java new file mode 100644 index 0000000..fe00ccf --- /dev/null +++ b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsSendEvent.java @@ -0,0 +1,76 @@ +package su.nightexpress.coinsengine.api.event; + +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import su.nightexpress.coinsengine.api.currency.Currency; +import su.nightexpress.coinsengine.data.impl.CoinsUser; +import org.jetbrains.annotations.NotNull; + +public class CoinsSendEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final Currency currency; + private final String currencyName; + private double amount; + private final OfflinePlayer target; + private final CommandSender from; + + public CoinsSendEvent(@NotNull OfflinePlayer target, @NotNull Currency currency, double amount, @NotNull CommandSender from) { + this.target = target; + this.currency = currency; + this.currencyName = currency.getName(); + this.amount = amount; + this.from = from; + } + + @NotNull + public OfflinePlayer getTarget() { + return target; + } + + @NotNull + public Currency getCurrency() { + return currency; + } + + public double getAmount() { + return amount; + } + + public String getCurrencyName() { + return currencyName; + } + + public void setAmount(double amount) { + this.amount = amount; + } + + @NotNull + public CommandSender getFrom() { + return from; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} \ No newline at end of file diff --git a/src/main/java/su/nightexpress/coinsengine/api/event/CoinsSetEvent.java b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsSetEvent.java new file mode 100644 index 0000000..ae102db --- /dev/null +++ b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsSetEvent.java @@ -0,0 +1,68 @@ +package su.nightexpress.coinsengine.api.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import su.nightexpress.coinsengine.api.currency.Currency; +import su.nightexpress.coinsengine.data.impl.CoinsUser; +import org.jetbrains.annotations.NotNull; + +public class CoinsSetEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final CoinsUser user; + private final Currency currency; + private double amount; + private final CommandSender from; + + public CoinsSetEvent(@NotNull CoinsUser user, @NotNull Currency currency, double amount, @NotNull CommandSender from) { + this.user = user; + this.currency = currency; + this.amount = amount; + this.from = from; + } + + @NotNull + public CoinsUser getUser() { + return user; + } + + @NotNull + public Currency getCurrency() { + return currency; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } + + @NotNull + public CommandSender getFrom() { + return from; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} \ No newline at end of file diff --git a/src/main/java/su/nightexpress/coinsengine/api/event/CoinsTakeEvent.java b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsTakeEvent.java new file mode 100644 index 0000000..ca7f7f8 --- /dev/null +++ b/src/main/java/su/nightexpress/coinsengine/api/event/CoinsTakeEvent.java @@ -0,0 +1,68 @@ +package su.nightexpress.coinsengine.api.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import su.nightexpress.coinsengine.api.currency.Currency; +import su.nightexpress.coinsengine.data.impl.CoinsUser; +import org.jetbrains.annotations.NotNull; + +public class CoinsTakeEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final CoinsUser user; + private final Currency currency; + private double amount; + private final CommandSender from; + + public CoinsTakeEvent(@NotNull CoinsUser user, @NotNull Currency currency, double amount, @NotNull CommandSender from) { + this.user = user; + this.currency = currency; + this.amount = amount; + this.from = from; + } + + @NotNull + public CoinsUser getUser() { + return user; + } + + @NotNull + public Currency getCurrency() { + return currency; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } + + @NotNull + public CommandSender getFrom() { + return from; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} \ No newline at end of file diff --git a/src/main/java/su/nightexpress/coinsengine/command/impl/CurrencyCommands.java b/src/main/java/su/nightexpress/coinsengine/command/impl/CurrencyCommands.java index 4e0e1bc..5e25ad4 100644 --- a/src/main/java/su/nightexpress/coinsengine/command/impl/CurrencyCommands.java +++ b/src/main/java/su/nightexpress/coinsengine/command/impl/CurrencyCommands.java @@ -5,6 +5,10 @@ import su.nightexpress.coinsengine.CoinsEnginePlugin; import su.nightexpress.coinsengine.Placeholders; import su.nightexpress.coinsengine.api.currency.Currency; +import su.nightexpress.coinsengine.api.event.CoinsExchangeEvent; +import su.nightexpress.coinsengine.api.event.CoinsGiveEvent; +import su.nightexpress.coinsengine.api.event.CoinsSendEvent; +import su.nightexpress.coinsengine.api.event.CoinsTakeEvent; import su.nightexpress.coinsengine.command.CommandArguments; import su.nightexpress.coinsengine.command.CommandFlags; import su.nightexpress.coinsengine.config.Config; @@ -31,435 +35,675 @@ public class CurrencyCommands { - public static void loadForCurrency(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency) { - var command = RootCommand.chained(plugin, currency.getCommandAliases(), builder -> builder - .permission(currency.isPermissionRequired() ? currency.getPermission() : null) - .description(currency.replacePlaceholders().apply(Lang.COMMAND_CURRENCY_ROOT_DESC.getString())) - ); - - ChainedNode rootNode = command.getNode(); - - CommandNode balanceNode = balanceBuilder(plugin, currency, "balance").build(); - - if (Config.CURRENCY_COMMAND_DEFAULT_TO_BALANCE.get()) { - rootNode.setFallback(balanceNode); - } - rootNode.addChildren(balanceNode); - rootNode.addChildren(topBuilder(plugin, currency, "top")); + public static void loadForCurrency( + @NotNull CoinsEnginePlugin plugin, @NotNull Currency currency) { + var command = + RootCommand.chained( + plugin, + currency.getCommandAliases(), + builder -> + builder + .permission(currency.isPermissionRequired() ? currency.getPermission() : null) + .description( + currency + .replacePlaceholders() + .apply(Lang.COMMAND_CURRENCY_ROOT_DESC.getString()))); + + ChainedNode rootNode = command.getNode(); + + CommandNode balanceNode = balanceBuilder(plugin, currency, "balance").build(); + + if (Config.CURRENCY_COMMAND_DEFAULT_TO_BALANCE.get()) { + rootNode.setFallback(balanceNode); + } + rootNode.addChildren(balanceNode); + rootNode.addChildren(topBuilder(plugin, currency, "top")); - rootNode.addChildren(DirectNode.builder(plugin, "giveall") + rootNode.addChildren( + DirectNode.builder(plugin, "giveall") .permission(Perms.COMMAND_CURRENCY_GIVE_ALL) .description(Lang.COMMAND_CURRENCY_GIVE_ALL_DESC) .withArgument(CommandArguments.amount().required()) .withFlag(CommandFlags.silent()) .withFlag(CommandFlags.silentOutput()) - .executes((context, arguments) -> giveAll(plugin, currency, context, arguments)) - ); + .executes((context, arguments) -> giveAll(plugin, currency, context, arguments))); - rootNode.addChildren(DirectNode.builder(plugin, "give") + rootNode.addChildren( + DirectNode.builder(plugin, "give") .permission(Perms.COMMAND_CURRENCY_GIVE) .description(Lang.COMMAND_CURRENCY_GIVE_DESC) .withArgument(ArgumentTypes.playerName(CommandArguments.PLAYER).required()) .withArgument(CommandArguments.amount().required()) .withFlag(CommandFlags.silent()) .withFlag(CommandFlags.silentOutput()) - .executes((context, arguments) -> give(plugin, currency, context, arguments)) - ); + .executes((context, arguments) -> give(plugin, currency, context, arguments))); - rootNode.addChildren(DirectNode.builder(plugin, "set") + rootNode.addChildren( + DirectNode.builder(plugin, "set") .permission(Perms.COMMAND_CURRENCY_SET) .description(Lang.COMMAND_CURRENCY_SET_DESC) .withArgument(ArgumentTypes.playerName(CommandArguments.PLAYER).required()) .withArgument(CommandArguments.amount().required()) .withFlag(CommandFlags.silent()) .withFlag(CommandFlags.silentOutput()) - .executes((context, arguments) -> set(plugin, currency, context, arguments)) - ); + .executes((context, arguments) -> set(plugin, currency, context, arguments))); - rootNode.addChildren(DirectNode.builder(plugin, "take") + rootNode.addChildren( + DirectNode.builder(plugin, "take") .permission(Perms.COMMAND_CURRENCY_TAKE) .description(Lang.COMMAND_CURRENCY_TAKE_DESC) .withArgument(ArgumentTypes.playerName(CommandArguments.PLAYER).required()) .withArgument(CommandArguments.amount().required()) .withFlag(CommandFlags.silent()) .withFlag(CommandFlags.silentOutput()) - .executes((context, arguments) -> remove(plugin, currency, context, arguments)) - ); - - if (currency.isTransferAllowed()) { - rootNode.addChildren(payBuilder(plugin, currency, "pay", "send")); - rootNode.addChildren(DirectNode.builder(plugin, "payments") - .permission(Perms.COMMAND_CURRENCY_PAYMENTS) - .description(Lang.COMMAND_CURRENCY_PAYMENTS_DESC) - .withArgument(ArgumentTypes.playerName(CommandArguments.PLAYER).permission(Perms.COMMAND_CURRENCY_PAYMENTS_OTHERS)) - .withFlag(CommandFlags.silent().permission(Perms.COMMAND_CURRENCY_PAYMENTS_OTHERS)) - .executes((context, arguments) -> togglePayments(plugin, currency, context, arguments)) - ); - } - - if (currency.isExchangeAllowed()) { - rootNode.addChildren(DirectNode.builder(plugin, "exchange") - .playerOnly() - .permission(Perms.COMMAND_CURRENCY_EXCHANGE) - .description(Lang.COMMAND_CURRENCY_EXCHANGE_DESC) - .withArgument(CommandArguments.currency(plugin).required() - .withSamples(context -> plugin.getCurrencyManager().getCurrencies().stream() - .filter(other -> currency.getExchangeRate(other) > 0).map(Currency::getId).toList() - ) - ) - .withArgument(CommandArguments.amount().required()) - .executes((context, arguments) -> exchange(plugin, currency, context, arguments)) - ); - } - - plugin.getCommandManager().registerCommand(command); - } - - public static void loadForEconomy(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency) { - ServerCommand balanceCommand = RootCommand.build(plugin, balanceBuilder(plugin, currency, "balance", "bal")); - ServerCommand payCommand = RootCommand.build(plugin, payBuilder(plugin, currency, "pay")); - ServerCommand topCommand = RootCommand.build(plugin, topBuilder(plugin, currency, "balancetop", "baltop")); - - plugin.getCommandManager().registerCommand(balanceCommand); - plugin.getCommandManager().registerCommand(payCommand); - plugin.getCommandManager().registerCommand(topCommand); - } - - public static void unloadForCurrency(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency) { - plugin.getCommandManager().unregisterServerCommand(currency.getCommandAliases()[0]); + .executes((context, arguments) -> remove(plugin, currency, context, arguments))); + + if (currency.isTransferAllowed()) { + rootNode.addChildren(payBuilder(plugin, currency, "pay", "send")); + rootNode.addChildren( + DirectNode.builder(plugin, "payments") + .permission(Perms.COMMAND_CURRENCY_PAYMENTS) + .description(Lang.COMMAND_CURRENCY_PAYMENTS_DESC) + .withArgument( + ArgumentTypes.playerName(CommandArguments.PLAYER) + .permission(Perms.COMMAND_CURRENCY_PAYMENTS_OTHERS)) + .withFlag(CommandFlags.silent().permission(Perms.COMMAND_CURRENCY_PAYMENTS_OTHERS)) + .executes( + (context, arguments) -> togglePayments(plugin, currency, context, arguments))); } - public static void unloadForEconomy(@NotNull CoinsEnginePlugin plugin) { - plugin.getCommandManager().unregisterServerCommand("balance"); - plugin.getCommandManager().unregisterServerCommand("pay"); - plugin.getCommandManager().unregisterServerCommand("balancetop"); + if (currency.isExchangeAllowed()) { + rootNode.addChildren( + DirectNode.builder(plugin, "exchange") + .playerOnly() + .permission(Perms.COMMAND_CURRENCY_EXCHANGE) + .description(Lang.COMMAND_CURRENCY_EXCHANGE_DESC) + .withArgument( + CommandArguments.currency(plugin) + .required() + .withSamples( + context -> + plugin.getCurrencyManager().getCurrencies().stream() + .filter(other -> currency.getExchangeRate(other) > 0) + .map(Currency::getId) + .toList())) + .withArgument(CommandArguments.amount().required()) + .executes((context, arguments) -> exchange(plugin, currency, context, arguments))); } - - private static DirectNodeBuilder balanceBuilder(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull String... aliases) { - return DirectNode.builder(plugin, aliases) - .permission(Perms.COMMAND_CURRENCY_BALANCE) - .description(Lang.COMMAND_CURRENCY_BALANCE_DESC) - .withArgument(ArgumentTypes.playerName(CommandArguments.PLAYER).permission(Perms.COMMAND_CURRENCY_BALANCE_OTHERS)) - .executes((context, arguments) -> showBalance(plugin, currency, context, arguments)); - } - - private static DirectNodeBuilder payBuilder(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull String... aliases) { - return DirectNode.builder(plugin, aliases) - .playerOnly() - .permission(Perms.COMMAND_CURRENCY_SEND) - .description(Lang.COMMAND_CURRENCY_SEND_DESC) - .withArgument(ArgumentTypes.playerName(CommandArguments.PLAYER).required()) - .withArgument(CommandArguments.amount().required()) - .executes((context, arguments) -> send(plugin, currency, context, arguments)); - } - - private static DirectNodeBuilder topBuilder(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull String... aliases) { - return DirectNode.builder(plugin, aliases) - .permission(Perms.COMMAND_CURRENCY_TOP) - .description(Lang.COMMAND_CURRENCY_TOP_DESC) - .withArgument(ArgumentTypes.integerAbs(CommandArguments.AMOUNT) + plugin.getCommandManager().registerCommand(command); + } + + public static void loadForEconomy(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency) { + ServerCommand balanceCommand = + RootCommand.build(plugin, balanceBuilder(plugin, currency, "balance", "bal")); + ServerCommand payCommand = RootCommand.build(plugin, payBuilder(plugin, currency, "pay")); + ServerCommand topCommand = + RootCommand.build(plugin, topBuilder(plugin, currency, "balancetop", "baltop")); + + plugin.getCommandManager().registerCommand(balanceCommand); + plugin.getCommandManager().registerCommand(payCommand); + plugin.getCommandManager().registerCommand(topCommand); + } + + public static void unloadForCurrency( + @NotNull CoinsEnginePlugin plugin, @NotNull Currency currency) { + plugin.getCommandManager().unregisterServerCommand(currency.getCommandAliases()[0]); + } + + public static void unloadForEconomy(@NotNull CoinsEnginePlugin plugin) { + plugin.getCommandManager().unregisterServerCommand("balance"); + plugin.getCommandManager().unregisterServerCommand("pay"); + plugin.getCommandManager().unregisterServerCommand("balancetop"); + } + + private static DirectNodeBuilder balanceBuilder( + @NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull String... aliases) { + return DirectNode.builder(plugin, aliases) + .permission(Perms.COMMAND_CURRENCY_BALANCE) + .description(Lang.COMMAND_CURRENCY_BALANCE_DESC) + .withArgument( + ArgumentTypes.playerName(CommandArguments.PLAYER) + .permission(Perms.COMMAND_CURRENCY_BALANCE_OTHERS)) + .executes((context, arguments) -> showBalance(plugin, currency, context, arguments)); + } + + private static DirectNodeBuilder payBuilder( + @NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull String... aliases) { + return DirectNode.builder(plugin, aliases) + .playerOnly() + .permission(Perms.COMMAND_CURRENCY_SEND) + .description(Lang.COMMAND_CURRENCY_SEND_DESC) + .withArgument(ArgumentTypes.playerName(CommandArguments.PLAYER).required()) + .withArgument(CommandArguments.amount().required()) + .executes((context, arguments) -> send(plugin, currency, context, arguments)); + } + + private static DirectNodeBuilder topBuilder( + @NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull String... aliases) { + return DirectNode.builder(plugin, aliases) + .permission(Perms.COMMAND_CURRENCY_TOP) + .description(Lang.COMMAND_CURRENCY_TOP_DESC) + .withArgument( + ArgumentTypes.integerAbs(CommandArguments.AMOUNT) .localized(Lang.COMMAND_ARGUMENT_NAME_PAGE) - .withSamples(context -> IntStream.range(1, 11).boxed().map(String::valueOf).toList()) - ) - .executes((context, arguments) -> showTop(plugin, currency, context, arguments)); - } - - public static boolean showBalance(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { - String name = arguments.getStringArgument(CommandArguments.PLAYER, context.getSender().getName()); - boolean isOwn = !arguments.hasArgument(CommandArguments.PLAYER); - - plugin.getUserManager().manageUser(name, user -> { - if (user == null) { + .withSamples( + context -> IntStream.range(1, 11).boxed().map(String::valueOf).toList())) + .executes((context, arguments) -> showTop(plugin, currency, context, arguments)); + } + + public static boolean showBalance( + @NotNull CoinsEnginePlugin plugin, + @NotNull Currency currency, + @NotNull CommandContext context, + @NotNull ParsedArguments arguments) { + String name = + arguments.getStringArgument(CommandArguments.PLAYER, context.getSender().getName()); + boolean isOwn = !arguments.hasArgument(CommandArguments.PLAYER); + + plugin + .getUserManager() + .manageUser( + name, + user -> { + if (user == null) { context.errorBadPlayer(); return; - } - - currency.withPrefix((isOwn ? Lang.CURRENCY_BALANCE_DISPLAY_OWN : Lang.CURRENCY_BALANCE_DISPLAY_OTHERS).getMessage()).send(context.getSender(), replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.PLAYER_NAME, user.getName()) - .replace(Placeholders.GENERIC_BALANCE, currency.format(user.getBalance(currency))) - ); - }); - return true; + } + + currency + .withPrefix( + (isOwn + ? Lang.CURRENCY_BALANCE_DISPLAY_OWN + : Lang.CURRENCY_BALANCE_DISPLAY_OTHERS) + .getMessage()) + .send( + context.getSender(), + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.PLAYER_NAME, user.getName()) + .replace( + Placeholders.GENERIC_BALANCE, + currency.format(user.getBalance(currency)))); + }); + return true; + } + + public static boolean exchange( + @NotNull CoinsEnginePlugin plugin, + @NotNull Currency currency, + @NotNull CommandContext context, + @NotNull ParsedArguments arguments) { + Currency targetCurrency = arguments.getArgument(CommandArguments.CURRENCY, Currency.class); + double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); + if (amount <= 0) return false; + + Player player = context.getPlayerOrThrow(); + + // Calcola l'importo che otterrà nella valuta di destinazione + double exchangeRate = currency.getExchangeRate(targetCurrency); + double targetAmount = amount * exchangeRate; + + // Crea e chiama l'evento + CoinsExchangeEvent event = + new CoinsExchangeEvent(player, currency, targetCurrency, amount, targetAmount); + plugin.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return false; } - public static boolean exchange(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { - Currency targetCurrency = arguments.getArgument(CommandArguments.CURRENCY, Currency.class); - - double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); - if (amount <= 0) return false; - - Player player = context.getPlayerOrThrow(); - return plugin.getCurrencyManager().exchange(player, currency, targetCurrency, amount); + return plugin + .getCurrencyManager() + .exchange(player, currency, targetCurrency, event.getFromAmount()); + } + + public static boolean giveAll( + @NotNull CoinsEnginePlugin plugin, + @NotNull Currency currency, + @NotNull CommandContext context, + @NotNull ParsedArguments arguments) { + double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); + if (amount <= 0D) return false; + + plugin + .getServer() + .getOnlinePlayers() + .forEach( + player -> { + CoinsUser user = plugin.getUserManager().getOrFetch(player); + + // Crea e chiama l'evento per ogni giocatore + CoinsGiveEvent event = + new CoinsGiveEvent(player, currency, amount, context.getSender()); + plugin.getServer().getPluginManager().callEvent(event); + + double finalAmount = event.getAmount(); + + user.addBalance(currency, finalAmount); + + plugin.getUserManager().save(user); + plugin.getCoinsLogger().logGive(user, currency, finalAmount, context.getSender()); + + if (!arguments.hasFlag(CommandFlags.SILENT)) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_GIVE_NOTIFY.getMessage()) + .send( + player, + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(finalAmount)) + .replace( + Placeholders.GENERIC_BALANCE, + currency.format(user.getBalance(currency)))); + } + }); + + if (!arguments.hasFlag(CommandFlags.SILENT_FEEDBACK)) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_GIVE_ALL_DONE.getMessage()) + .send( + context.getSender(), + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount))); } - public static boolean giveAll(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { - double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); - if (amount <= 0D) return false; - - plugin.getServer().getOnlinePlayers().forEach(player -> { - CoinsUser user = plugin.getUserManager().getOrFetch(player); - - user.addBalance(currency, amount); - - plugin.getUserManager().save(user); - plugin.getCoinsLogger().logGive(user, currency, amount, context.getSender()); - - if (!arguments.hasFlag(CommandFlags.SILENT)) { - currency.withPrefix(Lang.COMMAND_CURRENCY_GIVE_NOTIFY.getMessage()).send(player, replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - .replace(Placeholders.GENERIC_BALANCE, currency.format(user.getBalance(currency))) - ); - } - }); - - if (!arguments.hasFlag(CommandFlags.SILENT_FEEDBACK)) { - currency.withPrefix(Lang.COMMAND_CURRENCY_GIVE_ALL_DONE.getMessage()).send(context.getSender(), replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - ); - } - - return true; - } - - public static boolean give(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { - double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); - if (amount <= 0D) return false; - - plugin.getUserManager().manageUser(arguments.getStringArgument(CommandArguments.PLAYER), user -> { - if (user == null) { + return true; + } + + public static boolean give( + @NotNull CoinsEnginePlugin plugin, + @NotNull Currency currency, + @NotNull CommandContext context, + @NotNull ParsedArguments arguments) { + double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); + if (amount <= 0D) return false; + + plugin + .getUserManager() + .manageUser( + arguments.getStringArgument(CommandArguments.PLAYER), + user -> { + if (user == null) { context.errorBadPlayer(); return; - } - - user.addBalance(currency, amount); - - plugin.getUserManager().save(user); - plugin.getCoinsLogger().logGive(user, currency, amount, context.getSender()); - - if (!arguments.hasFlag(CommandFlags.SILENT_FEEDBACK)) { - currency.withPrefix(Lang.COMMAND_CURRENCY_GIVE_DONE.getMessage()).send(context.getSender(), replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.PLAYER_NAME, user.getName()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - .replace(Placeholders.GENERIC_BALANCE, currency.format(user.getBalance(currency))) - ); - } - - Player target = user.getPlayer(); - if (!arguments.hasFlag(CommandFlags.SILENT) && target != null) { - currency.withPrefix(Lang.COMMAND_CURRENCY_GIVE_NOTIFY.getMessage()).send(target, replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - .replace(Placeholders.GENERIC_BALANCE, currency.format(user.getBalance(currency))) - ); - } - }); - - return true; - } - - public static boolean togglePayments(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { - boolean isOwn = !arguments.hasArgument(CommandArguments.PLAYER); - String name = arguments.getStringArgument(CommandArguments.PLAYER, context.getSender().getName()); - - plugin.getUserManager().manageUser(name, user -> { - if (user == null) { + } + + // Crea e chiama l'evento + CoinsGiveEvent event = + new CoinsGiveEvent( + user.getOfflinePlayer(), currency, amount, context.getSender()); + plugin.getServer().getPluginManager().callEvent(event); + + double finalAmount = event.getAmount(); + + user.addBalance(currency, finalAmount); + + plugin.getUserManager().save(user); + plugin.getCoinsLogger().logGive(user, currency, finalAmount, context.getSender()); + + if (!arguments.hasFlag(CommandFlags.SILENT_FEEDBACK)) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_GIVE_DONE.getMessage()) + .send( + context.getSender(), + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.PLAYER_NAME, user.getName()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(finalAmount)) + .replace( + Placeholders.GENERIC_BALANCE, + currency.format(user.getBalance(currency)))); + } + + Player target = user.getPlayer(); + if (!arguments.hasFlag(CommandFlags.SILENT) && target != null) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_GIVE_NOTIFY.getMessage()) + .send( + target, + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(finalAmount)) + .replace( + Placeholders.GENERIC_BALANCE, + currency.format(user.getBalance(currency)))); + } + }); + return true; + } + + public static boolean togglePayments( + @NotNull CoinsEnginePlugin plugin, + @NotNull Currency currency, + @NotNull CommandContext context, + @NotNull ParsedArguments arguments) { + boolean isOwn = !arguments.hasArgument(CommandArguments.PLAYER); + String name = + arguments.getStringArgument(CommandArguments.PLAYER, context.getSender().getName()); + + plugin + .getUserManager() + .manageUser( + name, + user -> { + if (user == null) { context.errorBadPlayer(); return; - } - - CurrencySettings settings = user.getSettings(currency); - settings.setPaymentsEnabled(!settings.isPaymentsEnabled()); - plugin.getUserManager().save(user); + } + + CurrencySettings settings = user.getSettings(currency); + settings.setPaymentsEnabled(!settings.isPaymentsEnabled()); + plugin.getUserManager().save(user); + + if (!isOwn) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_PAYMENTS_TARGET.getMessage()) + .send( + context.getSender(), + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.PLAYER_NAME, user.getName()) + .replace( + Placeholders.GENERIC_STATE, + Lang.getEnabledOrDisabled(settings.isPaymentsEnabled()))); + } + + Player target = user.getPlayer(); + if (!arguments.hasFlag(CommandFlags.SILENT) && target != null) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_PAYMENTS_TOGGLE.getMessage()) + .send( + target, + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace( + Placeholders.GENERIC_STATE, + Lang.getEnabledOrDisabled(settings.isPaymentsEnabled()))); + } + }); + return true; + } + + public static boolean send( + @NotNull CoinsEnginePlugin plugin, + @NotNull Currency currency, + @NotNull CommandContext context, + @NotNull ParsedArguments arguments) { + Player from = context.getPlayerOrThrow(); + String targetName = arguments.getStringArgument(CommandArguments.PLAYER); + if (from.getName().equalsIgnoreCase(targetName)) { + Lang.ERROR_COMMAND_NOT_YOURSELF.getMessage().send(context.getSender()); + return false; + } - if (!isOwn) { - currency.withPrefix(Lang.COMMAND_CURRENCY_PAYMENTS_TARGET.getMessage()).send(context.getSender(), replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.PLAYER_NAME, user.getName()) - .replace(Placeholders.GENERIC_STATE, Lang.getEnabledOrDisabled(settings.isPaymentsEnabled())) - ); - } - - Player target = user.getPlayer(); - if (!arguments.hasFlag(CommandFlags.SILENT) && target != null) { - currency.withPrefix(Lang.COMMAND_CURRENCY_PAYMENTS_TOGGLE.getMessage()).send(target, replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.GENERIC_STATE, Lang.getEnabledOrDisabled(settings.isPaymentsEnabled())) - ); - } - }); - return true; + double amount = currency.fine(arguments.getDoubleArgument(CommandArguments.AMOUNT)); + if (amount <= 0D) return false; + + if (currency.getMinTransferAmount() > 0 && amount < currency.getMinTransferAmount()) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_SEND_ERROR_TOO_LOW.getMessage()) + .send( + context.getSender(), + replacer -> + replacer.replace( + Placeholders.GENERIC_AMOUNT, + currency.format(currency.getMinTransferAmount()))); + return false; } - public static boolean send(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { - Player from = context.getPlayerOrThrow(); - String targetName = arguments.getStringArgument(CommandArguments.PLAYER); - if (from.getName().equalsIgnoreCase(targetName)) { - Lang.ERROR_COMMAND_NOT_YOURSELF.getMessage().send(context.getSender()); - return false; - } - - double amount = currency.fine(arguments.getDoubleArgument(CommandArguments.AMOUNT)); - if (amount <= 0D) return false; - - if (currency.getMinTransferAmount() > 0 && amount < currency.getMinTransferAmount()) { - currency.withPrefix(Lang.COMMAND_CURRENCY_SEND_ERROR_TOO_LOW.getMessage()).send(context.getSender(), replacer -> replacer - .replace(Placeholders.GENERIC_AMOUNT, currency.format(currency.getMinTransferAmount())) - ); - return false; - } - - plugin.getUserManager().manageUser(targetName, targetUser -> { - if (targetUser == null) { + plugin + .getUserManager() + .manageUser( + targetName, + targetUser -> { + if (targetUser == null) { context.errorBadPlayer(); return; - } + } - CoinsUser fromUser = plugin.getUserManager().getOrFetch(from); - if (amount > fromUser.getBalance(currency)) { - currency.withPrefix(Lang.COMMAND_CURRENCY_SEND_ERROR_NOT_ENOUGH.getMessage()).send(from, replacer -> replacer - .replace(currency.replacePlaceholders()) - ); + CoinsUser fromUser = plugin.getUserManager().getOrFetch(from); + if (amount > fromUser.getBalance(currency)) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_SEND_ERROR_NOT_ENOUGH.getMessage()) + .send(from, replacer -> replacer.replace(currency.replacePlaceholders())); return; - } - - CurrencySettings settings = targetUser.getSettings(currency); - if (!settings.isPaymentsEnabled()) { - currency.withPrefix(Lang.COMMAND_CURRENCY_SEND_ERROR_NO_PAYMENTS.getMessage()).send(from, replacer -> replacer - .replace(Placeholders.PLAYER_NAME, targetUser.getName()) - .replace(currency.replacePlaceholders()) - ); + } + + CurrencySettings settings = targetUser.getSettings(currency); + if (!settings.isPaymentsEnabled()) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_SEND_ERROR_NO_PAYMENTS.getMessage()) + .send( + from, + replacer -> + replacer + .replace(Placeholders.PLAYER_NAME, targetUser.getName()) + .replace(currency.replacePlaceholders())); return; - } - - targetUser.addBalance(currency, amount); - fromUser.removeBalance(currency, amount); - - plugin.getUserManager().save(targetUser); - plugin.getUserManager().save(fromUser); - plugin.getCoinsLogger().logSend(targetUser, currency, amount, from); - - currency.withPrefix(Lang.COMMAND_CURRENCY_SEND_DONE_SENDER.getMessage()).send(context.getSender(), replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - .replace(Placeholders.GENERIC_BALANCE, fromUser.getBalance(currency)) - .replace(Placeholders.PLAYER_NAME, targetUser.getName()) - ); - - Player target = plugin.getServer().getPlayer(targetUser.getName()); - if (target != null) { - currency.withPrefix(Lang.COMMAND_CURRENCY_SEND_DONE_NOTIFY.getMessage()).send(target, replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - .replace(Placeholders.GENERIC_BALANCE, targetUser.getBalance(currency)) - .replace(Placeholders.PLAYER_NAME, fromUser.getName()) - ); - } - }); - return true; - } + } - public static boolean set(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { - double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); - if (amount < 0D) return false; + // Crea e chiama l'evento + CoinsSendEvent event = + new CoinsSendEvent(targetUser.getOfflinePlayer(), currency, amount, from); + plugin.getServer().getPluginManager().callEvent(event); - plugin.getUserManager().manageUser(arguments.getStringArgument(CommandArguments.PLAYER), user -> { - if (user == null) { + if (event.isCancelled()) { + return; + } + + double finalAmount = event.getAmount(); + + targetUser.addBalance(currency, finalAmount); + fromUser.removeBalance(currency, finalAmount); + + plugin.getUserManager().save(targetUser); + plugin.getUserManager().save(fromUser); + plugin.getCoinsLogger().logSend(targetUser, currency, finalAmount, from); + + currency + .withPrefix(Lang.COMMAND_CURRENCY_SEND_DONE_SENDER.getMessage()) + .send( + context.getSender(), + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(finalAmount)) + .replace(Placeholders.GENERIC_BALANCE, fromUser.getBalance(currency)) + .replace(Placeholders.PLAYER_NAME, targetUser.getName())); + + Player target = plugin.getServer().getPlayer(targetUser.getName()); + if (target != null) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_SEND_DONE_NOTIFY.getMessage()) + .send( + target, + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(finalAmount)) + .replace( + Placeholders.GENERIC_BALANCE, targetUser.getBalance(currency)) + .replace(Placeholders.PLAYER_NAME, fromUser.getName())); + } + }); + return true; + } + + public static boolean set( + @NotNull CoinsEnginePlugin plugin, + @NotNull Currency currency, + @NotNull CommandContext context, + @NotNull ParsedArguments arguments) { + double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); + if (amount < 0D) return false; + + plugin + .getUserManager() + .manageUser( + arguments.getStringArgument(CommandArguments.PLAYER), + user -> { + if (user == null) { context.errorBadPlayer(); return; - } - - user.setBalance(currency, amount); - - plugin.getUserManager().save(user); - plugin.getCoinsLogger().logSet(user, currency, amount, context.getSender()); - - if (!arguments.hasFlag(CommandFlags.SILENT_FEEDBACK)) { - currency.withPrefix(Lang.COMMAND_CURRENCY_SET_DONE.getMessage()).send(context.getSender(), replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.PLAYER_NAME, user.getName()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - .replace(Placeholders.GENERIC_BALANCE, currency.format(user.getBalance(currency))) - ); - } - - Player target = user.getPlayer(); - - if (!arguments.hasFlag(CommandFlags.SILENT) && target != null) { - currency.withPrefix(Lang.COMMAND_CURRENCY_SET_NOTIFY.getMessage()).send(target, replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - .replace(Placeholders.GENERIC_BALANCE, currency.format(user.getBalance(currency))) - ); - } - }); - return true; - } - - public static boolean remove(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { - double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); - if (amount <= 0D) return false; - - plugin.getUserManager().manageUser(arguments.getStringArgument(CommandArguments.PLAYER), user -> { - if (user == null) { + } + + user.setBalance(currency, amount); + + plugin.getUserManager().save(user); + plugin.getCoinsLogger().logSet(user, currency, amount, context.getSender()); + + if (!arguments.hasFlag(CommandFlags.SILENT_FEEDBACK)) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_SET_DONE.getMessage()) + .send( + context.getSender(), + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.PLAYER_NAME, user.getName()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) + .replace( + Placeholders.GENERIC_BALANCE, + currency.format(user.getBalance(currency)))); + } + + Player target = user.getPlayer(); + + if (!arguments.hasFlag(CommandFlags.SILENT) && target != null) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_SET_NOTIFY.getMessage()) + .send( + target, + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) + .replace( + Placeholders.GENERIC_BALANCE, + currency.format(user.getBalance(currency)))); + } + }); + return true; + } + + public static boolean remove( + @NotNull CoinsEnginePlugin plugin, + @NotNull Currency currency, + @NotNull CommandContext context, + @NotNull ParsedArguments arguments) { + double amount = arguments.getDoubleArgument(CommandArguments.AMOUNT); + if (amount <= 0D) return false; + + plugin + .getUserManager() + .manageUser( + arguments.getStringArgument(CommandArguments.PLAYER), + user -> { + if (user == null) { context.errorBadPlayer(); return; - } + } - user.removeBalance(currency, amount); + // Crea e chiama l'evento + CoinsTakeEvent event = + new CoinsTakeEvent(user, currency, amount, context.getSender()); + plugin.getServer().getPluginManager().callEvent(event); - plugin.getUserManager().save(user); - plugin.getCoinsLogger().logTake(user, currency, amount, context.getSender()); - - if (!arguments.hasFlag(CommandFlags.SILENT_FEEDBACK)) { - currency.withPrefix(Lang.COMMAND_CURRENCY_TAKE_DONE.getMessage()).send(context.getSender(), replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.PLAYER_NAME, user.getName()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - .replace(Placeholders.GENERIC_BALANCE, currency.format(user.getBalance(currency))) - ); - } - - Player target = user.getPlayer(); - if (!arguments.hasFlag(CommandFlags.SILENT) && target != null) { - currency.withPrefix(Lang.COMMAND_CURRENCY_TAKE_NOTIFY.getMessage()).send(target, replacer -> replacer + if (event.isCancelled()) { + return; + } + + double finalAmount = event.getAmount(); + + user.removeBalance(currency, finalAmount); + + plugin.getUserManager().save(user); + plugin.getCoinsLogger().logTake(user, currency, finalAmount, context.getSender()); + + if (!arguments.hasFlag(CommandFlags.SILENT_FEEDBACK)) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_TAKE_DONE.getMessage()) + .send( + context.getSender(), + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.PLAYER_NAME, user.getName()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(finalAmount)) + .replace( + Placeholders.GENERIC_BALANCE, + currency.format(user.getBalance(currency)))); + } + + Player target = user.getPlayer(); + if (!arguments.hasFlag(CommandFlags.SILENT) && target != null) { + currency + .withPrefix(Lang.COMMAND_CURRENCY_TAKE_NOTIFY.getMessage()) + .send( + target, + replacer -> + replacer + .replace(currency.replacePlaceholders()) + .replace(Placeholders.GENERIC_AMOUNT, currency.format(finalAmount)) + .replace( + Placeholders.GENERIC_BALANCE, + currency.format(user.getBalance(currency)))); + } + }); + return true; + } + + public static boolean showTop( + @NotNull CoinsEnginePlugin plugin, + @NotNull Currency currency, + @NotNull CommandContext context, + @NotNull ParsedArguments arguments) { + int perPage = Config.TOP_ENTRIES_PER_PAGE.get(); + + List full = plugin.getCurrencyManager().getTopBalances(currency); + List> split = Lists.split(full, perPage); + int pages = split.size(); + int page = + Math.max( + 0, Math.min(pages, Math.abs(arguments.getIntArgument(CommandArguments.AMOUNT, 1))) - 1); + + List entries = pages > 0 ? split.get(page) : new ArrayList<>(); + + currency + .withPrefix(Lang.COMMAND_CURRENCY_TOP_LIST.getMessage()) + .send( + context.getSender(), + replacer -> + replacer .replace(currency.replacePlaceholders()) - .replace(Placeholders.GENERIC_AMOUNT, currency.format(amount)) - .replace(Placeholders.GENERIC_BALANCE, currency.format(user.getBalance(currency))) - ); - } - }); - return true; - } - - public static boolean showTop(@NotNull CoinsEnginePlugin plugin, @NotNull Currency currency, @NotNull CommandContext context, @NotNull ParsedArguments arguments) { - int perPage = Config.TOP_ENTRIES_PER_PAGE.get(); - - List full = plugin.getCurrencyManager().getTopBalances(currency); - List> split = Lists.split(full, perPage); - int pages = split.size(); - int page = Math.max(0, Math.min(pages, Math.abs(arguments.getIntArgument(CommandArguments.AMOUNT, 1))) - 1); - - List entries = pages > 0 ? split.get(page) : new ArrayList<>(); - - currency.withPrefix(Lang.COMMAND_CURRENCY_TOP_LIST.getMessage()).send(context.getSender(), replacer -> replacer - .replace(currency.replacePlaceholders()) - .replace(Placeholders.GENERIC_CURRENT, page + 1) - .replace(Placeholders.GENERIC_MAX, pages) - .replace(Placeholders.GENERIC_ENTRY, list -> { - for (TopEntry entry : entries) { - list.add(Lang.COMMAND_CURRENCY_TOP_ENTRY.getString() - .replace(Placeholders.GENERIC_POS, NumberUtil.format(entry.position())) - .replace(Placeholders.GENERIC_BALANCE, currency.format(entry.balance())) - .replace(Placeholders.PLAYER_NAME, entry.name())); - } - }) - ); - - return true; - } -} + .replace(Placeholders.GENERIC_CURRENT, page + 1) + .replace(Placeholders.GENERIC_MAX, pages) + .replace( + Placeholders.GENERIC_ENTRY, + list -> { + for (TopEntry entry : entries) { + list.add( + Lang.COMMAND_CURRENCY_TOP_ENTRY + .getString() + .replace( + Placeholders.GENERIC_POS, + NumberUtil.format(entry.position())) + .replace( + Placeholders.GENERIC_BALANCE, + currency.format(entry.balance())) + .replace(Placeholders.PLAYER_NAME, entry.name())); + } + })); + + return true; + } +} \ No newline at end of file