Skip to content

Commit 9f1d906

Browse files
authored
Creating account on join is optional if Vault not enabled (#129)
2 parents 82187a9 + 7548b94 commit 9f1d906

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/main/java/pro/cloudnode/smp/bankaccounts/BankConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ public boolean integrationsVaultEnabled() {
131131
}
132132

133133
// starting-balance
134-
public @NotNull BigDecimal startingBalance() {
135-
if (Objects.requireNonNull(config.getString("starting-balance")).equalsIgnoreCase("null"))
136-
return BigDecimal.ZERO;
137-
else return new BigDecimal(Objects.requireNonNull(config.getString("starting-balance")));
134+
public @NotNull Optional<@NotNull BigDecimal> startingBalance() {
135+
if (Objects.requireNonNull(config.getString("starting-balance")).equalsIgnoreCase("false"))
136+
return Optional.empty();
137+
else return Optional.of(new BigDecimal(Objects.requireNonNull(config.getString("starting-balance"))));
138138
}
139139

140140
// server-account.name

src/main/java/pro/cloudnode/smp/bankaccounts/events/Join.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,24 @@
1010
import pro.cloudnode.smp.bankaccounts.Permissions;
1111

1212
import java.math.BigDecimal;
13+
import java.util.Optional;
1314

1415
public final class Join implements Listener {
1516
@EventHandler
1617
public void onPlayerJoin(final @NotNull PlayerJoinEvent event) {
1718
final @NotNull Player player = event.getPlayer();
18-
final @NotNull BigDecimal startingBalance = BankAccounts.getInstance().config().startingBalance();
19+
final @NotNull Optional<@NotNull BigDecimal> startingBalance = BankAccounts.getInstance().config().startingBalance();
1920
BankAccounts.getInstance().getServer().getScheduler().runTaskAsynchronously(BankAccounts.getInstance(), () -> {
2021
if (Account.getVaultAccount(player).isEmpty()) {
21-
// if the player already has a personal account, they will not be given starting balance
22-
final @NotNull BigDecimal balance = startingBalance.compareTo(BigDecimal.ZERO) <= 0 || Account.get(player, Account.Type.PERSONAL).length > 0 ? BigDecimal.ZERO : startingBalance;
23-
new Account(player, Account.Type.VAULT, null, balance, false).insert();
22+
if (startingBalance.isPresent()) {
23+
// if the player already has a personal account, they will not be given starting balance
24+
final @NotNull BigDecimal balance = startingBalance.get().compareTo(BigDecimal.ZERO) <= 0 || Account.get(player, Account.Type.PERSONAL).length > 0 ? BigDecimal.ZERO : startingBalance.get();
25+
new Account(player, Account.Type.VAULT, null, balance, false).insert();
26+
}
27+
else if (BankAccounts.getInstance().config().integrationsVaultEnabled()) {
28+
// Vault account is required if the Vault integration is enabled, regardless of starting balance
29+
new Account(player, Account.Type.VAULT, null, BigDecimal.ZERO, false).insert();
30+
}
2431
}
2532
});
2633
if (player.hasPermission(Permissions.NOTIFY_UPDATE)) {

src/main/resources/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ currency:
5252
format: "#,##0.00"
5353

5454
# Starting balance
55+
# Min value is 0. Set to "false" to disable creating an account on join.
56+
# If the Vault integration is enabled and this is set to "false", an account with 0 balance will be created regardless.
5557
starting-balance: 0
5658

5759
# Server account

0 commit comments

Comments
 (0)