@@ -180,6 +180,7 @@ public static boolean run(final @NotNull CommandSender sender, final @NotNull St
180180 case "unfreeze" , "enable" , "unblock" -> unfreeze (sender , argsSubset , label );
181181 case "delete" -> delete (sender , argsSubset , label );
182182 case "changeowner" , "newowner" , "newholder" , "changeholder" -> changeOwner (sender , argsSubset , label );
183+ case "acceptchangeowner" -> acceptChangeOwner (sender , argsSubset , label );
183184 case "transfer" , "send" , "pay" -> transfer (sender , argsSubset , label );
184185 case "transactions" , "history" -> transactions (sender , argsSubset , label );
185186 case "instrument" , "card" -> instrument (sender , argsSubset , label );
@@ -490,6 +491,33 @@ public static boolean changeOwner(final @NotNull CommandSender sender, final @No
490491 return true ;
491492 }
492493
494+ /**
495+ * Accept ownership change request
496+ */
497+ public static boolean acceptChangeOwner (final @ NotNull CommandSender sender , final @ NotNull String @ NotNull [] args , final @ NotNull String label ) {
498+ if (!sender .hasPermission (Permissions .CHANGE_OWNER_ACCEPT )) return sendMessage (sender , BankAccounts .getInstance ().config ().messagesErrorsNoPermission ());
499+ if (args .length < 1 ) return sendUsage (sender , label , "acceptchangeowner <account>" );
500+ final @ NotNull Optional <Account .@ NotNull ChangeOwnerRequest > request = Account .ChangeOwnerRequest .get (args [0 ], BankAccounts .getOfflinePlayer (sender ));
501+ if (request .isEmpty ()) return sendMessage (sender , BankAccounts .getInstance ().config ().messagesErrorsChangeOwnerNotFound ());
502+ final @ NotNull Optional <@ NotNull Account > account = request .get ().account ();
503+ if (account .isEmpty ()) return sendMessage (sender , BankAccounts .getInstance ().config ().messagesErrorsAccountNotFound ());
504+
505+ if (!sender .hasPermission (Permissions .ACCOUNT_CREATE_BYPASS )) {
506+ final @ NotNull Account @ NotNull [] accounts = Account .get (BankAccounts .getOfflinePlayer (sender ), account .get ().type );
507+ int limit = BankAccounts .getInstance ().config ().accountLimits (account .get ().type );
508+ if (limit != -1 && accounts .length >= limit )
509+ return sendMessage (sender , BankAccounts .getInstance ().config ().messagesErrorsMaxAccounts (),
510+ Placeholder .unparsed ("type" , account .get ().type .getName ()),
511+ Placeholder .unparsed ("limit" , String .valueOf (limit ))
512+ );
513+ }
514+
515+ final boolean success = request .get ().confirm ();
516+ if (!success ) return sendMessage (sender , BankAccounts .getInstance ().config ().messagesErrorsChangeOwnerAcceptFailed ());
517+ // TODO: send success message to new owner
518+ return true ;
519+ }
520+
493521 /**
494522 * Make a transfer to another account
495523 * <p>
0 commit comments