2323import org .bukkit .configuration .ConfigurationSection ;
2424import org .bukkit .entity .Entity ;
2525import org .jetbrains .annotations .ApiStatus ;
26+ import org .jetbrains .annotations .NotNull ;
2627import org .jetbrains .annotations .Nullable ;
2728import org .mvplugins .multiverse .core .command .MVCommandManager ;
2829import org .mvplugins .multiverse .core .config .handle .MemoryConfigurationHandle ;
@@ -302,7 +303,8 @@ public PortalLocation getPortalLocation() {
302303 }
303304
304305 @ ApiStatus .AvailableSince ("5.2" )
305- public Try <Void > setActionType (ActionHandlerType <?, ?> actionType ) {
306+ public Try <Void > setActionType (@ NotNull ActionHandlerType <?, ?> actionType ) {
307+ Objects .requireNonNull (actionType , "actionType cannot be null" );
306308 return configHandle .set (configNodes .actionType , actionType .getName ());
307309 }
308310
@@ -327,17 +329,24 @@ public String getAction() {
327329 }
328330
329331 @ ApiStatus .AvailableSince ("5.2" )
330- public Attempt <? extends ActionHandler <?, ?>, ActionFailureReason > getActionHandler () {
332+ public Try <Void > setActionHandler (@ NotNull ActionHandler <?, ?> action ) {
333+ Objects .requireNonNull (action , "action cannot be null" );
334+ return setActionType (action .getHandlerType ())
335+ .flatMap (v -> setAction (action .serialise ()));
336+ }
337+
338+ @ ApiStatus .AvailableSince ("5.2" )
339+ public @ NotNull Attempt <? extends ActionHandler <?, ?>, ActionFailureReason > getActionHandler () {
331340 return actionHandlerProvider .parseHandler (getActionType (), getAction ());
332341 }
333342
334343 @ ApiStatus .AvailableSince ("5.2" )
335- public Attempt <? extends ActionHandler <?, ?>, ActionFailureReason > getActionHandler (CommandSender sender ) {
344+ public @ NotNull Attempt <? extends ActionHandler <?, ?>, ActionFailureReason > getActionHandler (@ NotNull CommandSender sender ) {
336345 return actionHandlerProvider .parseHandler (sender , getActionType (), getAction ());
337346 }
338347
339348 @ ApiStatus .AvailableSince ("5.2" )
340- public Attempt <Void , ActionFailureReason > runActionFor (Entity entity ) {
349+ public @ NotNull Attempt <Void , ActionFailureReason > runActionFor (Entity entity ) {
341350 return getActionHandler (entity )
342351 .mapAttempt (actionHandler -> actionHandler .runAction (this , entity ))
343352 .onSuccess (() -> {
@@ -672,7 +681,7 @@ public boolean setDestination(String destinationString) {
672681
673682 /**
674683 * @deprecated Portals now have new types of action. Hence, the portal's destination (now called action) may not
675- * always be a multiverse destination. It can be a command or server name as well.
684+ * always be a multiverse destination. For example, it can be a command or server name as well.
676685 * Please see {@link MVPortal#getActionHandler()} instead.
677686 */
678687 @ Deprecated (since = "5.2" , forRemoval = true )
@@ -686,17 +695,19 @@ public boolean setDestination(DestinationInstance<?, ?> newDestination) {
686695 Logging .warning ("Portal " + this .name + " is not set to use multiverse destination!" );
687696 return false ;
688697 }
689- return this .configHandle .set (configNodes .action , newDestination .toString ()).isSuccess ();
698+ return setActionType ("multiverse-destination" )
699+ .flatMap (ignore -> setAction (newDestination .toString ()))
700+ .isSuccess ();
690701 }
691702
692703 /**
693704 * @deprecated Portals now have new types of action. Hence, the portal's destination (now called action) may not
694- * always be a multiverse destination. It can be a command or server name as well.
705+ * always be a multiverse destination. For example, it can be a command or server name as well.
695706 * Please see {@link MVPortal#getActionHandler()} instead.
696707 */
697708 @ Deprecated (since = "5.2" , forRemoval = true )
698709 @ ApiStatus .ScheduledForRemoval (inVersion = "6.0" )
699- public DestinationInstance <?, ?> getDestination () {
710+ public @ Nullable DestinationInstance <?, ?> getDestination () {
700711 return this .destinationsProvider .parseDestination (getAction ())
701712 .onFailure (f -> {
702713 if (getAction ().equals ("multiverse-destination" )) {
0 commit comments