Skip to content

Commit 5bc160a

Browse files
RollcziVerniQ
andauthored
GH-43 Transaction limit (#48)
* 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 <vernidev@gmail.com>
1 parent 95d4f8c commit 5bc160a

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

eternaleconomy-core/src/main/java/com/eternalcode/economy/EconomyBukkitPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void onEnable() {
127127
new AdminResetCommand(accountPaymentService, noticeService),
128128
new AdminBalanceCommand(noticeService, decimalFormatter),
129129
new MoneyBalanceCommand(noticeService, decimalFormatter),
130-
new MoneyTransferCommand(accountPaymentService, decimalFormatter, noticeService),
130+
new MoneyTransferCommand(accountPaymentService, decimalFormatter, noticeService, pluginConfig),
131131
new EconomyReloadCommand(configService, noticeService)
132132
)
133133

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.eternalcode.economy.account.Account;
55
import com.eternalcode.economy.account.AccountPaymentService;
66
import com.eternalcode.economy.command.validator.notsender.NotSender;
7+
import com.eternalcode.economy.config.implementation.PluginConfig;
78
import com.eternalcode.economy.format.DecimalFormatter;
89
import com.eternalcode.economy.multification.NoticeService;
910
import dev.rollczi.litecommands.annotations.argument.Arg;
@@ -21,15 +22,18 @@ public class MoneyTransferCommand {
2122
private final AccountPaymentService accountPaymentService;
2223
private final DecimalFormatter decimalFormatter;
2324
private final NoticeService noticeService;
25+
private PluginConfig pluginConfig;
2426

2527
public MoneyTransferCommand(
2628
AccountPaymentService accountPaymentService,
2729
DecimalFormatter decimalFormatter,
28-
NoticeService noticeService
30+
NoticeService noticeService,
31+
PluginConfig pluginConfig
2932
) {
3033
this.accountPaymentService = accountPaymentService;
3134
this.decimalFormatter = decimalFormatter;
3235
this.noticeService = noticeService;
36+
this.pluginConfig = pluginConfig;
3337
}
3438

3539
@Execute
@@ -45,6 +49,16 @@ void execute(@Context Account payer, @Arg @NotSender Account receiver, @Arg @Pos
4549
return;
4650
}
4751

52+
if (amount.compareTo(this.pluginConfig.transactionLimit) > 0) {
53+
this.noticeService.create()
54+
.notice(notice -> notice.player.transferLimit)
55+
.placeholder("{LIMIT}", this.decimalFormatter.format(this.pluginConfig.transactionLimit))
56+
.player(payer.uuid())
57+
.send();
58+
59+
return;
60+
}
61+
4862
this.accountPaymentService.payment(payer, receiver, amount);
4963

5064
this.noticeService.create()

eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/PluginConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class PluginConfig extends OkaeriConfig {
2020
@Comment("Default balance for new accounts")
2121
public BigDecimal defaultBalance = BigDecimal.valueOf(0.0);
2222

23+
@Comment("Limit on the amount of money sent in one transaction")
24+
public BigDecimal transactionLimit = BigDecimal.valueOf(1_000_000_000.0);
25+
2326
public static class Units extends OkaeriConfig {
2427

2528
public List<DecimalUnit> format = Arrays.asList(

eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/messages/MessagesPlayerSubSection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ public class MessagesPlayerSubSection extends OkaeriConfig {
2727
public Notice transferReceived = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> "
2828
+ "<dark_gray>➤</dark_gray> <white>Received <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> from "
2929
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
30+
public Notice transferLimit = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray>"
31+
+ " <white>Transaction limit is <gradient:#00FFA2:#34AE00>{LIMIT}</gradient>.</white>");
3032
}

0 commit comments

Comments
 (0)