From 4920d8fd2c548f7a391b8190c92f68a28577e5f2 Mon Sep 17 00:00:00 2001 From: "Daniel V." Date: Thu, 9 Jan 2025 08:50:21 -0500 Subject: [PATCH] Add /money giveall. --- .changelog/0.1.3.5.md | 1 + Core/resources/messages.yml | 7 ++- .../net/tnemc/core/command/MoneyCommand.java | 60 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/.changelog/0.1.3.5.md b/.changelog/0.1.3.5.md index 52da7471..2be13897 100644 --- a/.changelog/0.1.3.5.md +++ b/.changelog/0.1.3.5.md @@ -6,6 +6,7 @@ - Added /tne reloaddb - reloads data from the database and clears the in-memory cache. ~~ doesn't save data ~~ - Added two new config options in data.yml to allow auto db reload after some minutes have passed when the first player joins. - Added ability to use $balance in the Messages.Money.PlaceholderTopEntry message used in top 10 placeholder +- Added /money giveall command. ## Internals - Updated VaultUnlocked Hook to 2.9.0 diff --git a/Core/resources/messages.yml b/Core/resources/messages.yml index f6cff1a3..3211fbf6 100644 --- a/Core/resources/messages.yml +++ b/Core/resources/messages.yml @@ -4,7 +4,7 @@ # All configurable messages in TNE Messages: - config-version: 9 + config-version: 10 General: Version: "TNE Version: $version - Build: $build" @@ -478,7 +478,10 @@ Messages: Description: "Deposits money from an item form into a virtual bank for mixed currencies." Give: Arguments: " [currency] [world]" - Description: "Adds money into your economy, and gives it to a player." + Description: "Adds money into your economy, and gives it to a account." + GiveAll: + Arguments: " [currency] [world]" + Description: "Adds money into your economy, and gives it to every account." GiveNote: Arguments: " [currency]" Description: "Gives a player a physical money note they can redeem for monies." diff --git a/Core/src/net/tnemc/core/command/MoneyCommand.java b/Core/src/net/tnemc/core/command/MoneyCommand.java index db43caf1..1c1b4d2c 100644 --- a/Core/src/net/tnemc/core/command/MoneyCommand.java +++ b/Core/src/net/tnemc/core/command/MoneyCommand.java @@ -50,8 +50,10 @@ import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -290,6 +292,64 @@ public static void onGive(final CmdSource sender, final Account account, fina provider.ifPresent(playerProvider->playerProvider.message(msgData)); } } + }//ArgumentsParser: [world] [currency] + public static void onGiveAll(final CmdSource sender, final PercentBigDecimal amount, String region, final Currency currency) { + + final Optional player = sender.player(); + if(EconomyManager.limitCurrency() && player.isPresent()) { + if(!player.get().hasPermission("tne.money.give." + currency.getIdentifier())) { + final MessageData data = new MessageData("Messages.Account.BlockedAction"); + data.addReplacement("$action", "give funds"); + data.addReplacement("$currency", currency.getDisplay()); + sender.message(data); + return; + } + } + + if(player.isPresent() && region.equalsIgnoreCase("world-113")) { + region = player.get().world(); + } + + region = TNECore.eco().region().resolve(region); + + final HoldingsModifier modifier = new HoldingsModifier(region, + currency.getUid(), + amount); + + final List accounts = new ArrayList<>(); + + final UUID sourceID = (sender.identifier().isPresent())? sender.identifier().get() : TNECore.instance().getServerAccount(); + for(final Account account : TNECore.eco().account().getAccounts().values()) { + + final Transaction transaction = new Transaction("give") + .to(account, modifier) + .source(new PlayerSource(sourceID)); + + final Optional receipt = processTransaction(sender, transaction, account.getName(), amount.value()); + if(receipt.isPresent()) { + + accounts.add(account.getName()); + + final MessageData msgData = new MessageData("Messages.Money.Given"); + msgData.addReplacement("$currency", currency.getIdentifier()); + msgData.addReplacement("$player", (sender.name() == null)? MainConfig.yaml().getString("Core.Server.Account.Name") : sender.name()); + msgData.addReplacement("$amount", CurrencyFormatter.format(account, modifier.asEntry())); + + MessageHandler.send(account.getIdentifier(), msgData.grab(account.getIdentifier())); + if(account.isPlayer() && ((PlayerAccount)account).isOnline()) { + + final Optional provider = ((PlayerAccount)account).getPlayer(); + + provider.ifPresent(playerProvider->playerProvider.message(msgData)); + } + } + } + + final MessageData data = new MessageData("Messages.Money.Gave"); + data.addReplacement("$player", String.join(", ", accounts)); + data.addReplacement("$currency", currency.getIdentifier()); + data.addReplacement("$amount", CurrencyFormatter.format(null, modifier.asEntry())); + sender.message(data); } public static void onGiveNote(final CmdSource sender, final Account acc, final BigDecimal amount, final Currency currency) {