diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/NewMVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/NewMVPlayerListener.java index 1b16f0e1..49420a47 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/NewMVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/NewMVPlayerListener.java @@ -92,8 +92,8 @@ public class NewMVPlayerListener implements InjectableListener { worldEntryCheckerProvider.forWorld(player, world) .canStayInWorld() - .success(() -> oneTickLater(() -> handleGameModeAndFlight(player, world))) - .failure(() -> { + .onSuccess(() -> oneTickLater(() -> handleGameModeAndFlight(player, world))) + .onFailure(() -> { player.sendMessage("[MV] - Sorry you can't be in this world anymore!"); oneTickLater(() -> player.teleport(spawnLocation)); }); @@ -175,13 +175,13 @@ public class NewMVPlayerListener implements InjectableListener { } ResultGroup worldEntryResult = worldEntryCheckerProvider.forWorld(player, toWorld).canEnterWorld(fromWorld) - .success(() -> { + .onSuccess(() -> { Logging.fine("Player '%s' is allowed to use portals to enter world '%s'.", player.getName(), toWorld.getName()); if (!config.isUsingCustomPortalSearch()) { event.setSearchRadius(config.getCustomPortalSearchRadius()); } }) - .failure(() -> { + .onFailure(() -> { event.setCancelled(true); Logging.fine("Player '%s' is not allowed to use portals to enter world '%s'.", player.getName(), toWorld.getName()); //TODO send player reason for failure @@ -230,12 +230,12 @@ public class NewMVPlayerListener implements InjectableListener { ResultGroup worldEntryResult = worldEntryCheckerProvider.forWorld(teleportee, toWorld) .canEnterWorld(fromWorld.getOrNull()) - .success(() -> Logging.fine("MV-Core is allowing '%s' to go to '%s'.", teleportee.getName(), toWorld.getName())) - .successWithReason(EntryFeeResult.Success.ENOUGH_MONEY, () -> { + .onSuccess(() -> Logging.fine("MV-Core is allowing '%s' to go to '%s'.", teleportee.getName(), toWorld.getName())) + .onSuccessReason(EntryFeeResult.Success.ENOUGH_MONEY, () -> { economist.payEntryFee((Player) teleporter, toWorld); //TODO send payment message }) - .failure(() -> { + .onFailure(() -> { event.setCancelled(true); Logging.fine("MV-Core is denying '%s' from going to '%s'.", teleportee.getName(), toWorld.getName()); //TODO send player reason for failure diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/result/Result.java b/src/main/java/com/onarandombox/MultiverseCore/utils/result/Result.java index df79f10c..386e7a95 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/result/Result.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/result/Result.java @@ -20,28 +20,28 @@ public sealed interface Result F failureReason(); - default Result success(Consumer consumer) { + default Result onSuccess(Consumer consumer) { if (this.isSuccess()) { consumer.accept(this.successReason()); } return this; } - default Result failure(Consumer consumer) { + default Result onFailure(Consumer consumer) { if (this.isFailure()) { consumer.accept(this.failureReason()); } return this; } - default Result successWithReason(S successReason, Consumer consumer) { + default Result onSuccessReason(S successReason, Consumer consumer) { if (this.isSuccess() && this.successReason() == successReason) { consumer.accept(this.successReason()); } return this; } - default Result failureWithReason(F failureReason, Consumer consumer) { + default Result onFailureReason(F failureReason, Consumer consumer) { if (this.isFailure() && this.failureReason() == failureReason) { consumer.accept(this.failureReason()); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/result/ResultGroup.java b/src/main/java/com/onarandombox/MultiverseCore/utils/result/ResultGroup.java index 95c13028..cd3a9a65 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/result/ResultGroup.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/result/ResultGroup.java @@ -35,31 +35,31 @@ public class ResultGroup { return !isSuccess; } - public ResultGroup success(Runnable successRunnable) { + public ResultGroup onSuccess(Runnable successRunnable) { if (isSuccess) { successRunnable.run(); } return this; } - public ResultGroup failure(Runnable failureRunnable) { + public ResultGroup onFailure(Runnable failureRunnable) { if (isFailure()) { failureRunnable.run(); } return this; } - public ResultGroup successWithReason(Class successReasonClass, Consumer successConsumer) { + public ResultGroup onSuccessReason(Class successReasonClass, Consumer successConsumer) { getSuccessReason(successReasonClass).peek(successConsumer); return this; } - public ResultGroup failureWithReason(Class failureReasonClass, Consumer failureConsumer) { + public ResultGroup onFailureReason(Class failureReasonClass, Consumer failureConsumer) { getFailureReason(failureReasonClass).peek(failureConsumer); return this; } - public ResultGroup successWithReason(S successReason, Runnable successRunnable) { + public ResultGroup onSuccessReason(S successReason, Runnable successRunnable) { getSuccessReason(successReason.getClass()).filter(successReason::equals).peek(reason -> successRunnable.run()); return this; }