Skip to content

Commit 82187a9

Browse files
authored
Creating and deleting Vault accounts (#130)
2 parents 5912e2e + aecb39b commit 82187a9

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ public final class Permissions {
3030
public static @NotNull String HISTORY_OTHER = "bank.history.other";
3131
public static @NotNull String ACCOUNT_CREATE_OTHER = "bank.account.create.other";
3232
public static @NotNull String ACCOUNT_CREATE_BYPASS = "bank.account.create.bypass";
33+
public static @NotNull String ACCOUNT_CREATE_VAULT = "bank.account.create.vault";
3334
public static @NotNull String INSTRUMENT_CREATE_OTHER = "bank.instrument.create.other";
3435
public static @NotNull String INSTRUMENT_CREATE_BYPASS = "bank.instrument.create.bypass";
3536
public static @NotNull String SET_BALANCE = "bank.set.balance";
3637
public static @NotNull String SET_NAME_OTHER = "bank.set.name.other";
3738
public static @NotNull String SET_NAME_VAULT = "bank.set.name.vault";
3839
public static @NotNull String FREEZE_OTHER = "bank.freeze.other";
3940
public static @NotNull String DELETE_OTHER = "bank.delete.other";
41+
public static @NotNull String DELETE_VAULT = "bank.delete.vault";
4042
public static @NotNull String POS_CREATE_OTHER = "bank.pos.create.other";
4143
public static @NotNull String POS_CREATE_PERSONAL = "bank.pos.create.personal";
4244
public static @NotNull String POS_USE_OTHER = "bank.pos.use.other";

src/main/java/pro/cloudnode/smp/bankaccounts/commands/BankCommand.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ else if (args.length == 3 && args[1].equals("--player") && sender.hasPermission(
7575
if (!sender.hasPermission(Permissions.ACCOUNT_CREATE)) return suggestions;
7676
if (args.length == 2) {
7777
suggestions.addAll(Arrays.asList("PERSONAL", "BUSINESS"));
78+
if (sender.hasPermission(Permissions.ACCOUNT_CREATE_VAULT))
79+
suggestions.add("VAULT");
7880
}
7981
else if (args.length == 3 && sender.hasPermission(Permissions.ACCOUNT_CREATE_OTHER))
8082
suggestions.add("--player");
@@ -206,9 +208,9 @@ public static boolean help(final @NotNull CommandSender sender) {
206208
if (sender.hasPermission(Permissions.HISTORY))
207209
sendMessage(sender, "<click:suggest_command:/bank transactions ><green>/bank transactions <gray><account> [page=1]</gray></green> <white>- List transactions</click>");
208210
if (sender.hasPermission(Permissions.ACCOUNT_CREATE))
209-
sendMessage(sender, "<click:suggest_command:/bank create ><green>/bank create <gray><PERSONAL|BUSINESS></gray></green> <white>- Create a new account</click>");
211+
sendMessage(sender, "<click:suggest_command:/bank create ><green>/bank create <gray><PERSONAL|BUSINESS" + (sender.hasPermission(Permissions.ACCOUNT_CREATE_VAULT) ? "|VAULT" : "") + "></gray></green> <white>- Create a new account</click>");
210212
if (sender.hasPermission(Permissions.ACCOUNT_CREATE_OTHER))
211-
sendMessage(sender, "<click:suggest_command:/bank create ><green>/bank create <gray><PERSONAL|BUSINESS> --player <player></gray></green> <white>- Create an account for another player</click>");
213+
sendMessage(sender, "<click:suggest_command:/bank create ><green>/bank create <gray><PERSONAL|BUSINESS" + (sender.hasPermission(Permissions.ACCOUNT_CREATE_VAULT) ? "|VAULT" : "") + "> --player <player></gray></green> <white>- Create an account for another player</click>");
212214
if (sender.hasPermission(Permissions.FREEZE)) {
213215
sendMessage(sender, "<click:suggest_command:/bank freeze ><green>/bank freeze <gray><account></gray></green> <white>- Freeze an account</click>");
214216
sendMessage(sender, "<click:suggest_command:/bank unfreeze ><green>/bank unfreeze <gray><account></gray></green> <white>- Unfreeze an account</click>");
@@ -312,19 +314,19 @@ public static boolean create(final @NotNull CommandSender sender, final @NotNull
312314
int index = Arrays.asList(args).indexOf("--player");
313315
// index out of bounds
314316
if (index == -1 || index >= args.length - 1)
315-
return sendUsage(sender, label, "create <PERSONAL|BUSINESS> --player <player>");
317+
return sendUsage(sender, label, "create <PERSONAL|BUSINESS" + (sender.hasPermission(Permissions.ACCOUNT_CREATE_VAULT) ? "|VAULT" : "") + "> --player <player>");
316318
target = BankAccounts.getInstance().getServer().getOfflinePlayer(args[index + 1]);
317319
}
318320
}
319321
if (args.length == 0)
320-
return sendUsage(sender, label, "create <PERSONAL|BUSINESS> " + (sender.hasPermission(Permissions.ACCOUNT_CREATE_OTHER) ? "[--player <player>]" : ""));
322+
return sendUsage(sender, label, "create <PERSONAL|BUSINESS" + (sender.hasPermission(Permissions.ACCOUNT_CREATE_VAULT) ? "|VAULT" : "") + "> " + (sender.hasPermission(Permissions.ACCOUNT_CREATE_OTHER) ? "[--player <player>]" : ""));
321323
// check if target is the same as sender
322324
if (target.getUniqueId().equals(BankAccounts.getOfflinePlayer(sender)
323325
.getUniqueId()) && !sender.hasPermission(Permissions.ACCOUNT_CREATE))
324326
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNoPermission());
325327
final @NotNull Optional<Account.Type> optionalType = Account.Type.fromString(args[0]);
326-
if (optionalType.isEmpty())
327-
return sendUsage(sender, label, "create <PERSONAL|BUSINESS> " + (sender.hasPermission(Permissions.ACCOUNT_CREATE_OTHER) ? "[--player <player>]" : ""));
328+
if (optionalType.isEmpty() || optionalType.get() == Account.Type.VAULT && !sender.hasPermission(Permissions.ACCOUNT_CREATE_VAULT))
329+
return sendUsage(sender, label, "create <PERSONAL|BUSINESS" + (sender.hasPermission(Permissions.ACCOUNT_CREATE_VAULT) ? "|VAULT" : "") + "> " + (sender.hasPermission(Permissions.ACCOUNT_CREATE_OTHER) ? "[--player <player>]" : ""));
328330
if (!sender.hasPermission(Permissions.ACCOUNT_CREATE_BYPASS)) {
329331
final @NotNull Account @NotNull [] accounts = Account.get(target, optionalType.get());
330332
int limit = BankAccounts.getInstance().config().accountLimits(optionalType.get());
@@ -434,7 +436,7 @@ public static boolean delete(final @NotNull CommandSender sender, final @NotNull
434436
if (!sender.hasPermission(Permissions.DELETE_OTHER) && !account.get().owner.getUniqueId()
435437
.equals(BankAccounts.getOfflinePlayer(sender).getUniqueId()))
436438
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNotAccountOwner());
437-
if (account.get().type == Account.Type.VAULT)
439+
if (account.get().type == Account.Type.VAULT && !sender.hasPermission(Permissions.DELETE_VAULT))
438440
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsDeleteVaultAccount());
439441
final @NotNull Optional<@NotNull BigDecimal> balance = Optional.ofNullable(account.get().balance);
440442
if (balance.isPresent() && balance.get().compareTo(BigDecimal.ZERO) != 0)

0 commit comments

Comments
 (0)