Skip to content

Commit 6844b24

Browse files
committed
fix IDE warnings (mostly usage of deprecated Account.get(String))
1 parent 3ea985c commit 6844b24

File tree

11 files changed

+85
-101
lines changed

11 files changed

+85
-101
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.Optional;
1515
import java.util.Set;
1616
import java.util.regex.Matcher;
17-
import java.util.regex.Pattern;
1817
import java.util.stream.Collectors;
1918

2019
public abstract class Command implements CommandExecutor, TabCompleter {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Invoice(final @NotNull Account seller, final @NotNull BigDecimal amount,
5858
public Invoice(final @NotNull ResultSet rs) throws @NotNull SQLException {
5959
this(
6060
rs.getString("id"),
61-
Account.get(rs.getString("seller")).orElse(new Account.ClosedAccount()),
61+
Account.get(Account.Tag.id(rs.getString("seller"))).orElse(new Account.ClosedAccount()),
6262
rs.getBigDecimal("amount"),
6363
rs.getString("description"),
6464
rs.getString("buyer") == null ? null : BankAccounts.getInstance().getServer().getOfflinePlayer(UUID.fromString(rs.getString("buyer"))),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public POS(final @NotNull ResultSet rs) throws @NotNull SQLException, @NotNull I
100100
this.world = world.get();
101101
this.price = rs.getBigDecimal("price");
102102
this.description = rs.getString("description");
103-
this.seller = Account.get(rs.getString("seller")).orElse(new Account.ClosedAccount());
103+
this.seller = Account.get(Account.Tag.from(rs.getString("seller"))).orElse(new Account.ClosedAccount());
104104
this.created = rs.getDate("created");
105105
}
106106

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,45 @@
33
import org.jetbrains.annotations.NotNull;
44

55
public final class Permissions {
6-
public static @NotNull String COMMAND = "bank.command";
7-
public static @NotNull String BALANCE_SELF = "bank.balance.self";
8-
public static @NotNull String TRANSFER_SELF = "bank.transfer.self";
9-
public static @NotNull String TRANSFER_OTHER = "bank.transfer.other";
10-
public static @NotNull String HISTORY = "bank.history";
11-
public static @NotNull String ACCOUNT_CREATE = "bank.account.create";
12-
public static @NotNull String INSTRUMENT_CREATE = "bank.instrument.create";
13-
public static @NotNull String WHOIS = "bank.whois";
14-
public static @NotNull String SET_NAME = "bank.set.name";
15-
public static @NotNull String FREEZE = "bank.freeze";
16-
public static @NotNull String DELETE = "bank.delete";
17-
public static @NotNull String BALTOP = "bank.baltop";
18-
public static @NotNull String POS_CREATE = "bank.pos.create";
19-
public static @NotNull String POS_USE = "bank.pos.use";
20-
public static @NotNull String INVOICE_CREATE = "bank.invoice.create";
21-
public static @NotNull String INVOICE_CREATE_OTHER = "bank.invoice.create.other";
22-
public static @NotNull String INVOICE_VIEW = "bank.invoice.view";
23-
public static @NotNull String INVOICE_VIEW_OTHER = "bank.invoice.view.other";
24-
public static @NotNull String INVOICE_PAY_OTHER = "bank.invoice.pay.other";
25-
public static @NotNull String INVOICE_PAY_ACCOUNT_OTHER = "bank.invoice.pay.account-other";
26-
public static @NotNull String INVOICE_SEND = "bank.invoice.send";
27-
public static @NotNull String INVOICE_SEND_OTHER = "bank.invoice.send.other";
28-
public static @NotNull String RELOAD = "bank.reload";
29-
public static @NotNull String BALANCE_OTHER = "bank.balance.other";
30-
public static @NotNull String TRANSFER_FROM_OTHER = "bank.transfer.from-other";
31-
public static @NotNull String HISTORY_OTHER = "bank.history.other";
32-
public static @NotNull String ACCOUNT_CREATE_OTHER = "bank.account.create.other";
33-
public static @NotNull String ACCOUNT_CREATE_BYPASS = "bank.account.create.bypass";
34-
public static @NotNull String ACCOUNT_CREATE_VAULT = "bank.account.create.vault";
35-
public static @NotNull String INSTRUMENT_CREATE_OTHER = "bank.instrument.create.other";
36-
public static @NotNull String INSTRUMENT_CREATE_BYPASS = "bank.instrument.create.bypass";
37-
public static @NotNull String SET_BALANCE = "bank.set.balance";
38-
public static @NotNull String SET_NAME_OTHER = "bank.set.name.other";
39-
public static @NotNull String SET_NAME_VAULT = "bank.set.name.vault";
40-
public static @NotNull String FREEZE_OTHER = "bank.freeze.other";
41-
public static @NotNull String DELETE_OTHER = "bank.delete.other";
42-
public static @NotNull String DELETE_VAULT = "bank.delete.vault";
43-
public static @NotNull String POS_CREATE_OTHER = "bank.pos.create.other";
44-
public static @NotNull String POS_CREATE_PERSONAL = "bank.pos.create.personal";
45-
public static @NotNull String POS_USE_OTHER = "bank.pos.use.other";
46-
public static @NotNull String NOTIFY_UPDATE = "bank.notify-update";
6+
public static final @NotNull String COMMAND = "bank.command";
7+
public static final @NotNull String BALANCE_SELF = "bank.balance.self";
8+
public static final @NotNull String TRANSFER_SELF = "bank.transfer.self";
9+
public static final @NotNull String TRANSFER_OTHER = "bank.transfer.other";
10+
public static final @NotNull String HISTORY = "bank.history";
11+
public static final @NotNull String ACCOUNT_CREATE = "bank.account.create";
12+
public static final @NotNull String INSTRUMENT_CREATE = "bank.instrument.create";
13+
public static final @NotNull String WHOIS = "bank.whois";
14+
public static final @NotNull String SET_NAME = "bank.set.name";
15+
public static final @NotNull String FREEZE = "bank.freeze";
16+
public static final @NotNull String DELETE = "bank.delete";
17+
public static final @NotNull String BALTOP = "bank.baltop";
18+
public static final @NotNull String POS_CREATE = "bank.pos.create";
19+
public static final @NotNull String POS_USE = "bank.pos.use";
20+
public static final @NotNull String INVOICE_CREATE = "bank.invoice.create";
21+
public static final @NotNull String INVOICE_CREATE_OTHER = "bank.invoice.create.other";
22+
public static final @NotNull String INVOICE_VIEW = "bank.invoice.view";
23+
public static final @NotNull String INVOICE_VIEW_OTHER = "bank.invoice.view.other";
24+
public static final @NotNull String INVOICE_PAY_OTHER = "bank.invoice.pay.other";
25+
public static final @NotNull String INVOICE_PAY_ACCOUNT_OTHER = "bank.invoice.pay.account-other";
26+
public static final @NotNull String INVOICE_SEND = "bank.invoice.send";
27+
public static final @NotNull String INVOICE_SEND_OTHER = "bank.invoice.send.other";
28+
public static final @NotNull String RELOAD = "bank.reload";
29+
public static final @NotNull String BALANCE_OTHER = "bank.balance.other";
30+
public static final @NotNull String TRANSFER_FROM_OTHER = "bank.transfer.from-other";
31+
public static final @NotNull String HISTORY_OTHER = "bank.history.other";
32+
public static final @NotNull String ACCOUNT_CREATE_OTHER = "bank.account.create.other";
33+
public static final @NotNull String ACCOUNT_CREATE_BYPASS = "bank.account.create.bypass";
34+
public static final @NotNull String ACCOUNT_CREATE_VAULT = "bank.account.create.vault";
35+
public static final @NotNull String INSTRUMENT_CREATE_OTHER = "bank.instrument.create.other";
36+
public static final @NotNull String INSTRUMENT_CREATE_BYPASS = "bank.instrument.create.bypass";
37+
public static final @NotNull String SET_BALANCE = "bank.set.balance";
38+
public static final @NotNull String SET_NAME_OTHER = "bank.set.name.other";
39+
public static final @NotNull String SET_NAME_VAULT = "bank.set.name.vault";
40+
public static final @NotNull String FREEZE_OTHER = "bank.freeze.other";
41+
public static final @NotNull String DELETE_OTHER = "bank.delete.other";
42+
public static final @NotNull String DELETE_VAULT = "bank.delete.vault";
43+
public static final @NotNull String POS_CREATE_OTHER = "bank.pos.create.other";
44+
public static final @NotNull String POS_CREATE_PERSONAL = "bank.pos.create.personal";
45+
public static final @NotNull String POS_USE_OTHER = "bank.pos.use.other";
46+
public static final @NotNull String NOTIFY_UPDATE = "bank.notify-update";
4747
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public Transaction(Account from, Account to, BigDecimal amount, @Nullable String
9696
* @param rs Result set
9797
*/
9898
public Transaction(ResultSet rs) throws SQLException {
99-
this(rs.getInt("id"), Account.get(rs.getString("from")).orElse(new Account.ClosedAccount()), Account.get(rs.getString("to")).orElse(new Account.ClosedAccount()), rs.getBigDecimal("amount"), rs.getTimestamp("time"), rs.getString("description"), rs.getString("instrument"));
99+
this(rs.getInt("id"), Account.get(Account.Tag.from(rs.getString("from"))).orElse(new Account.ClosedAccount()), Account.get(Account.Tag.from(rs.getString("to"))).orElse(new Account.ClosedAccount()), rs.getBigDecimal("amount"), rs.getTimestamp("time"), rs.getString("description"), rs.getString("instrument"));
100100
}
101101

102102
/**

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

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ else if (args[0].equals("--player")) {
310310
else {
311311
if (!sender.hasPermission(Permissions.BALANCE_SELF))
312312
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNoPermission());
313-
final @NotNull Optional<@NotNull Account> account;
314-
if (!args[0].startsWith("@")) account = Account.get(args[0]);
315-
else account = Account.getVaultAccount(sender.getServer().getOfflinePlayer(args[0].substring(1)));
313+
final @NotNull Optional<@NotNull Account> account = Account.get(Account.Tag.from(args[0]));
316314
if (account.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
317315
else if (!sender.hasPermission(Permissions.BALANCE_OTHER) && !account.get().owner.getUniqueId()
318316
.equals((BankAccounts.getOfflinePlayer(sender)).getUniqueId()))
@@ -395,9 +393,7 @@ public static boolean setBalance(final @NotNull CommandSender sender, final @Not
395393
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNoPermission());
396394
if (args.length < 2)
397395
return sendUsage(sender, label, "setbalance " + (args.length > 0 ? args[0] : "<account>") + " <balance|Infinity>");
398-
final @NotNull Optional<@NotNull Account> account;
399-
if (args[0].startsWith("@")) account = Account.getVaultAccount(sender.getServer().getOfflinePlayer(args[0].substring(1)));
400-
else account = Account.get(args[0]);
396+
final @NotNull Optional<@NotNull Account> account = Account.get(Account.Tag.from(args[0]));
401397
if (account.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
402398
else {
403399
final @Nullable BigDecimal balance;
@@ -421,11 +417,7 @@ public static boolean setName(final @NotNull CommandSender sender, final @NotNul
421417
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNoPermission());
422418
if (args.length < 2)
423419
return sendUsage(sender, label, "setname " + (args.length > 0 ? args[0] : "<account>") + " [name]");
424-
/*final @NotNull Optional<@NotNull Account> account = Account.get(args[0]);*/
425-
final @NotNull Optional<@NotNull Account> account;
426-
if (args[0].startsWith("@") && sender.hasPermission(Permissions.SET_NAME_VAULT))
427-
account = Account.getVaultAccount(sender.getServer().getOfflinePlayer(args[0].substring(1)));
428-
else account = Account.get(args[0]);
420+
final @NotNull Optional<@NotNull Account> account = Account.get(Account.Tag.from(args[0]));
429421
if (account.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
430422
else {
431423
if (!sender.hasPermission(Permissions.SET_NAME_OTHER) && !account.get().owner.getUniqueId()
@@ -450,9 +442,7 @@ public static boolean setName(final @NotNull CommandSender sender, final @NotNul
450442
public static boolean freeze(final @NotNull CommandSender sender, final @NotNull String @NotNull [] args, final @NotNull String label) {
451443
if (!sender.hasPermission(Permissions.FREEZE)) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNoPermission());
452444
if (args.length < 1) return sendUsage(sender, label, "freeze <account>");
453-
final @NotNull Optional<@NotNull Account> account;
454-
if (args[0].startsWith("@")) account = Account.getVaultAccount(sender.getServer().getOfflinePlayer(args[0].substring(1)));
455-
else account = Account.get(args[0]);
445+
final @NotNull Optional<@NotNull Account> account = Account.get(Account.Tag.from(args[0]));
456446
if (account.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
457447
if (!sender.hasPermission(Permissions.FREEZE_OTHER) && !account.get().owner.getUniqueId()
458448
.equals(BankAccounts.getOfflinePlayer(sender).getUniqueId()))
@@ -467,9 +457,7 @@ public static boolean freeze(final @NotNull CommandSender sender, final @NotNull
467457
public static boolean unfreeze(final @NotNull CommandSender sender, final @NotNull String @NotNull [] args, final @NotNull String label) {
468458
if (!sender.hasPermission(Permissions.FREEZE)) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNoPermission());
469459
if (args.length < 1) return sendUsage(sender, label, "unfreeze <account>");
470-
final @NotNull Optional<@NotNull Account> account;
471-
if (args[0].startsWith("@")) account = Account.getVaultAccount(sender.getServer().getOfflinePlayer(args[0].substring(1)));
472-
else account = Account.get(args[0]);
460+
final @NotNull Optional<@NotNull Account> account = Account.get(Account.Tag.from(args[0]));
473461
if (account.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
474462
if (!sender.hasPermission(Permissions.FREEZE_OTHER) && !account.get().owner.getUniqueId()
475463
.equals(BankAccounts.getOfflinePlayer(sender).getUniqueId()))
@@ -487,9 +475,7 @@ public static boolean unfreeze(final @NotNull CommandSender sender, final @NotNu
487475
public static boolean delete(final @NotNull CommandSender sender, final @NotNull String @NotNull [] args, final @NotNull String label) {
488476
if (!sender.hasPermission(Permissions.DELETE)) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNoPermission());
489477
if (args.length < 1) return sendUsage(sender, label, "delete <account>");
490-
final @NotNull Optional<@NotNull Account> account;
491-
if (args[0].startsWith("@") && sender.hasPermission(Permissions.DELETE_VAULT)) account = Account.getVaultAccount(sender.getServer().getOfflinePlayer(args[0].substring(1)));
492-
else account = Account.get(args[0]);
478+
final @NotNull Optional<@NotNull Account> account = Account.get(Account.Tag.from(args[0]));
493479
if (account.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
494480
if (!sender.hasPermission(Permissions.DELETE_OTHER) && !account.get().owner.getUniqueId()
495481
.equals(BankAccounts.getOfflinePlayer(sender).getUniqueId()))
@@ -518,9 +504,7 @@ public static boolean transfer(final @NotNull CommandSender sender, final @NotNu
518504
if (confirm) argsCopy = Arrays.copyOfRange(argsCopy, 1, argsCopy.length);
519505
if (args.length < 3)
520506
return sendUsage(sender, label, "transfer " + (argsCopy.length > 0 ? argsCopy[0] : "<from>") + " " + (argsCopy.length > 1 ? argsCopy[1] : "<to>") + " <amount> [description]");
521-
final @NotNull Optional<@NotNull Account> from;
522-
if (argsCopy[0].startsWith("@")) from = Account.getVaultAccount(sender.getServer().getOfflinePlayer(argsCopy[0].substring(1)));
523-
else from = Account.get(argsCopy[0]);
507+
final @NotNull Optional<@NotNull Account> from = Account.get(Account.Tag.from(argsCopy[0]));
524508
// account does not exist
525509
if (from.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
526510
// sender does not own account
@@ -529,9 +513,7 @@ public static boolean transfer(final @NotNull CommandSender sender, final @NotNu
529513
// account is frozen
530514
if (from.get().frozen)
531515
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsFrozen(from.get()));
532-
final @NotNull Optional<@NotNull Account> to;
533-
if (argsCopy[1].startsWith("@")) to = Account.getVaultAccount(sender.getServer().getOfflinePlayer(argsCopy[1].substring(1)));
534-
else to = Account.get(argsCopy[1]);
516+
final @NotNull Optional<@NotNull Account> to = Account.get(Account.Tag.from(argsCopy[1]));
535517
// recipient does not exist
536518
if (to.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
537519
// to is same as from
@@ -598,9 +580,7 @@ public static boolean transfer(final @NotNull CommandSender sender, final @NotNu
598580
public static boolean transactions(final @NotNull CommandSender sender, final @NotNull String @NotNull [] args, final @NotNull String label) {
599581
if (!sender.hasPermission(Permissions.HISTORY)) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNoPermission());
600582
if (args.length < 1) return sendUsage(sender, label, "transactions <account> [page=1|--all]");
601-
final @NotNull Optional<@NotNull Account> account;
602-
if (args[0].startsWith("@")) account = Account.getVaultAccount(sender.getServer().getOfflinePlayer(args[0].substring(1)));
603-
else account = Account.get(args[0]);
583+
final @NotNull Optional<@NotNull Account> account = Account.get(Account.Tag.from(args[0]));
604584
if (account.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
605585
if (!sender.hasPermission(Permissions.HISTORY_OTHER) && !account.get().owner.getUniqueId()
606586
.equals(BankAccounts.getOfflinePlayer(sender).getUniqueId()))
@@ -656,9 +636,7 @@ else if (args.length < 1)
656636
.getInstance().getServer().getPlayer(args[1]) : player;
657637
if (target == null || !target.isOnline())
658638
return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsPlayerNotFound());
659-
final @NotNull Optional<@NotNull Account> account;
660-
if (args[0].startsWith("@")) account = Account.getVaultAccount(sender.getServer().getOfflinePlayer(args[0].substring(1)));
661-
else account = Account.get(args[0]);
639+
final @NotNull Optional<@NotNull Account> account = Account.get(Account.Tag.from(args[0]));
662640
if (account.isEmpty()) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound());
663641
if (!sender.hasPermission(Permissions.INSTRUMENT_CREATE_OTHER) && !account.get().owner.getUniqueId()
664642
.equals(BankAccounts.getOfflinePlayer(sender).getUniqueId()))
@@ -693,9 +671,7 @@ else if (args.length < 1)
693671
public static boolean whois(final @NotNull CommandSender sender, final @NotNull String @NotNull [] args, final @NotNull String label) {
694672
if (!sender.hasPermission(Permissions.WHOIS)) return sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsNoPermission());
695673
if (args.length < 1) return sendUsage(sender, label, "whois <account>");
696-
final @NotNull Optional<@NotNull Account> account;
697-
if (args[0].startsWith("@")) account = Account.getVaultAccount(sender.getServer().getOfflinePlayer(args[0].substring(1)));
698-
else account = Account.get(args[0]);
674+
final @NotNull Optional<@NotNull Account> account = Account.get(Account.Tag.from(args[0]));
699675
return account
700676
.map(value -> sendMessage(sender, BankAccounts.getInstance().config().messagesWhois(value)))
701677
.orElseGet(() -> sendMessage(sender, BankAccounts.getInstance().config().messagesErrorsAccountNotFound()));

0 commit comments

Comments
 (0)