@@ -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