Skip to content

Commit

Permalink
Update message replacements for give/take commands.
Browse files Browse the repository at this point in the history
Signed-off-by: creatorfromhell <[email protected]>
  • Loading branch information
creatorfromhell committed Sep 8, 2023
1 parent a5bd398 commit 1b4c3ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Core/src/net/tnemc/core/command/MoneyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public static void onGive(CmdSource<?> sender, Account player, BigDecimal amount
if(receipt.isPresent()) {
final MessageData data = new MessageData("Messages.Money.Gave");
data.addReplacement("$player", player.getName());
data.addReplacement("$currency", currency.getIdentifier());
data.addReplacement("$amount", CurrencyFormatter.format(player,
modifier.asEntry()));
sender.message(data);
Expand All @@ -209,6 +210,8 @@ public static void onGive(CmdSource<?> sender, Account player, BigDecimal amount

if(provider.isPresent()) {
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(player,
modifier.asEntry()));
provider.get().message(msgData);
Expand Down Expand Up @@ -381,6 +384,7 @@ public static void onPay(CmdSource<?> sender, Account player, BigDecimal amount,
if(receipt.isPresent()) {
final MessageData data = new MessageData("Messages.Money.Paid");
data.addReplacement("$player", player.getName());
data.addReplacement("$currency", currency.getIdentifier());
data.addReplacement("$amount", CurrencyFormatter.format(player,
modifier.asEntry()));
sender.message(data);
Expand All @@ -391,7 +395,7 @@ public static void onPay(CmdSource<?> sender, Account player, BigDecimal amount,
if(provider.isPresent()) {

final MessageData msgData = new MessageData("Messages.Money.Received");
data.addReplacement("$player", sender.name());
msgData.addReplacement("$player", (sender.name() == null)? MainConfig.yaml().getString("Core.Server.Account.Name") : sender.name());
msgData.addReplacement("$amount", CurrencyFormatter.format(player,
modifier.asEntry()));
provider.get().message(msgData);
Expand Down Expand Up @@ -422,7 +426,7 @@ public static void onRequest(CmdSource<?> sender, Account player, BigDecimal amo

final MessageData request = new MessageData("Messages.Money.Request");
request.addReplacement("$player", sender.name());
msg.addReplacement("$amount", amount.toPlainString());
request.addReplacement("$amount", amount.toPlainString());
request.addReplacement("$currency", currency.getIdentifier());
provider.get().message(request);
}
Expand All @@ -447,6 +451,7 @@ public static void onSet(CmdSource<?> sender, Account player, BigDecimal amount,
if(receipt.isPresent()) {
final MessageData msg = new MessageData("Messages.Money.Set");
msg.addReplacement("$player", player.getName());
msg.addReplacement("$currency", currency.getIdentifier());
msg.addReplacement("$amount", CurrencyFormatter.format(player,
modifier.asEntry())
);
Expand Down Expand Up @@ -475,9 +480,16 @@ public static void onSetAll(CmdSource<?> sender, BigDecimal amount, String regio
if(receipt.isPresent()) {
final MessageData msg = new MessageData("Messages.Money.Set");
msg.addReplacement("$player", account.getName());
msg.addReplacement("$currency", currency.getIdentifier());
msg.addReplacement("$amount", CurrencyFormatter.format(account,
modifier.asEntry())
);

msg.addReplacements(new String[] {
""
}, new String[] {

});
sender.message(msg);
return;
}
Expand All @@ -503,6 +515,7 @@ public static void onTake(CmdSource<?> sender, Account player, BigDecimal amount
if(receipt.isPresent()) {
final MessageData data = new MessageData("Messages.Money.Took");
data.addReplacement("$player", player.getName());
data.addReplacement("$currency", currency.getIdentifier());
data.addReplacement("$amount", CurrencyFormatter.format(player,
modifier.asEntry()));
sender.message(data);
Expand All @@ -513,7 +526,8 @@ public static void onTake(CmdSource<?> sender, Account player, BigDecimal amount

if(provider.isPresent()) {
final MessageData msgData = new MessageData("Messages.Money.Taken");
data.addReplacement("$player", sender.name());
msgData.addReplacement("$player", (sender.name() == null)? MainConfig.yaml().getString("Core.Server.Account.Name") : sender.name());
msgData.addReplacement("$currency", currency.getIdentifier());
msgData.addReplacement("$amount", CurrencyFormatter.format(player,
modifier.asEntry()));
provider.get().message(msgData);
Expand Down Expand Up @@ -594,6 +608,7 @@ public static void onWithdraw(CmdSource<?> sender, BigDecimal amount, Currency c
final Optional<Receipt> receipt = processTransaction(sender, transaction);
if(receipt.isPresent()) {
final MessageData data = new MessageData("Messages.Money.Withdrawn");
data.addReplacement("$currency", currency.getIdentifier());
data.addReplacement("$amount", CurrencyFormatter.format(senderAccount.get(),
modifier.asEntry()));
sender.message(data);
Expand Down
9 changes: 9 additions & 0 deletions Core/src/net/tnemc/core/io/message/MessageData.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public void addReplacement(final String search, final String replacement) {
this.replacements.put(search, replacement);
}

public void addReplacements(final String[] search, final String[] replacements) {
if(search.length != replacements.length) return;

for(int i = 0; i < search.length; i++) {

this.replacements.put(search[i], replacements[i]);
}
}

public Map<String, String> getReplacements() {
return replacements;
}
Expand Down

0 comments on commit 1b4c3ed

Please sign in to comment.