Skip to content

Commit

Permalink
GH-43 Transaction limit (#48)
Browse files Browse the repository at this point in the history
* Add limit on the amount of money sent in one transaction.

* Update eternaleconomy-core/src/main/java/com/eternalcode/economy/command/player/MoneyTransferCommand.java

* Update message display color.

* Update message display color.

---------

Co-authored-by: Verni <[email protected]>
  • Loading branch information
Rollczi and VerniQ authored Oct 21, 2024
1 parent 95d4f8c commit 5bc160a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void onEnable() {
new AdminResetCommand(accountPaymentService, noticeService),
new AdminBalanceCommand(noticeService, decimalFormatter),
new MoneyBalanceCommand(noticeService, decimalFormatter),
new MoneyTransferCommand(accountPaymentService, decimalFormatter, noticeService),
new MoneyTransferCommand(accountPaymentService, decimalFormatter, noticeService, pluginConfig),
new EconomyReloadCommand(configService, noticeService)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.eternalcode.economy.account.Account;
import com.eternalcode.economy.account.AccountPaymentService;
import com.eternalcode.economy.command.validator.notsender.NotSender;
import com.eternalcode.economy.config.implementation.PluginConfig;
import com.eternalcode.economy.format.DecimalFormatter;
import com.eternalcode.economy.multification.NoticeService;
import dev.rollczi.litecommands.annotations.argument.Arg;
Expand All @@ -21,15 +22,18 @@ public class MoneyTransferCommand {
private final AccountPaymentService accountPaymentService;
private final DecimalFormatter decimalFormatter;
private final NoticeService noticeService;
private PluginConfig pluginConfig;

public MoneyTransferCommand(
AccountPaymentService accountPaymentService,
DecimalFormatter decimalFormatter,
NoticeService noticeService
NoticeService noticeService,
PluginConfig pluginConfig
) {
this.accountPaymentService = accountPaymentService;
this.decimalFormatter = decimalFormatter;
this.noticeService = noticeService;
this.pluginConfig = pluginConfig;
}

@Execute
Expand All @@ -45,6 +49,16 @@ void execute(@Context Account payer, @Arg @NotSender Account receiver, @Arg @Pos
return;
}

if (amount.compareTo(this.pluginConfig.transactionLimit) > 0) {
this.noticeService.create()
.notice(notice -> notice.player.transferLimit)
.placeholder("{LIMIT}", this.decimalFormatter.format(this.pluginConfig.transactionLimit))
.player(payer.uuid())
.send();

return;
}

this.accountPaymentService.payment(payer, receiver, amount);

this.noticeService.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class PluginConfig extends OkaeriConfig {
@Comment("Default balance for new accounts")
public BigDecimal defaultBalance = BigDecimal.valueOf(0.0);

@Comment("Limit on the amount of money sent in one transaction")
public BigDecimal transactionLimit = BigDecimal.valueOf(1_000_000_000.0);

public static class Units extends OkaeriConfig {

public List<DecimalUnit> format = Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public class MessagesPlayerSubSection extends OkaeriConfig {
public Notice transferReceived = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> "
+ "<dark_gray>➤</dark_gray> <white>Received <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> from "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferLimit = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray>"
+ " <white>Transaction limit is <gradient:#00FFA2:#34AE00>{LIMIT}</gradient>.</white>");
}

0 comments on commit 5bc160a

Please sign in to comment.