Skip to content

Commit 339a511

Browse files
authored
Merge pull request #704 from Multiverse/feat/set-action-handler
Add setActionHandler method and update api annotations for improved clarity
2 parents ada5570 + 5f32afe commit 339a511

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/main/java/org/mvplugins/multiverse/portals/MVPortal.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.bukkit.configuration.ConfigurationSection;
2424
import org.bukkit.entity.Entity;
2525
import org.jetbrains.annotations.ApiStatus;
26+
import org.jetbrains.annotations.NotNull;
2627
import org.jetbrains.annotations.Nullable;
2728
import org.mvplugins.multiverse.core.command.MVCommandManager;
2829
import 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")) {

src/main/java/org/mvplugins/multiverse/portals/action/ActionHandlerProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void registerHandlerType(@NotNull ActionHandlerType<?, ?> handlerType) {
8181
*
8282
* @since 5.2
8383
*/
84+
@ApiStatus.AvailableSince("5.2")
8485
public @NotNull Attempt<? extends ActionHandler<?, ?>, ActionFailureReason> parseHandler(@NotNull String actionType,
8586
@NotNull String action) {
8687
return parseHandler(Bukkit.getConsoleSender(), actionType, action);

0 commit comments

Comments
 (0)