|
10 | 10 | import pro.cloudnode.smp.bankaccounts.Permissions; |
11 | 11 |
|
12 | 12 | import java.math.BigDecimal; |
| 13 | +import java.util.Optional; |
13 | 14 |
|
14 | 15 | public final class Join implements Listener { |
15 | 16 | @EventHandler |
16 | 17 | public void onPlayerJoin(final @NotNull PlayerJoinEvent event) { |
17 | 18 | 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(); |
19 | 20 | BankAccounts.getInstance().getServer().getScheduler().runTaskAsynchronously(BankAccounts.getInstance(), () -> { |
20 | 21 | 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 | + } |
24 | 31 | } |
25 | 32 | }); |
26 | 33 | if (player.hasPermission(Permissions.NOTIFY_UPDATE)) { |
|
0 commit comments