Skip to content

Commit

Permalink
Add /money giveall.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Jan 9, 2025
1 parent 6408d42 commit 4920d8f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
1 change: 1 addition & 0 deletions .changelog/0.1.3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions Core/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# All configurable messages in TNE
Messages:

config-version: 9
config-version: 10

General:
Version: "<white>TNE Version: <green>$version <white>- Build: <green>$build"
Expand Down Expand Up @@ -478,7 +478,10 @@ Messages:
Description: "Deposits money from an item form into a virtual bank for mixed currencies."
Give:
Arguments: "<player> <amount> [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: "<amount> [currency] [world]"
Description: "Adds money into your economy, and gives it to every account."
GiveNote:
Arguments: "<player> <amount> [currency]"
Description: "Gives a player a physical money note they can redeem for monies."
Expand Down
60 changes: 60 additions & 0 deletions Core/src/net/tnemc/core/command/MoneyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -290,6 +292,64 @@ public static void onGive(final CmdSource<?> sender, final Account account, fina
provider.ifPresent(playerProvider->playerProvider.message(msgData));
}
}
}//ArgumentsParser: <amount> [world] [currency]
public static void onGiveAll(final CmdSource<?> sender, final PercentBigDecimal amount, String region, final Currency currency) {

final Optional<PlayerProvider> 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<String> 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> 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<PlayerProvider> 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) {
Expand Down

0 comments on commit 4920d8f

Please sign in to comment.