mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 12:05:14 +01:00
refactor: Rename success and failure consumer methods
This commit is contained in:
parent
302c22f690
commit
ef14a398c3
@ -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
|
||||
|
@ -20,28 +20,28 @@ public sealed interface Result<S extends SuccessReason, F extends FailureReason>
|
||||
|
||||
F failureReason();
|
||||
|
||||
default Result<S, F> success(Consumer<S> consumer) {
|
||||
default Result<S, F> onSuccess(Consumer<S> consumer) {
|
||||
if (this.isSuccess()) {
|
||||
consumer.accept(this.successReason());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
default Result<S, F> failure(Consumer<F> consumer) {
|
||||
default Result<S, F> onFailure(Consumer<F> consumer) {
|
||||
if (this.isFailure()) {
|
||||
consumer.accept(this.failureReason());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
default Result<S, F> successWithReason(S successReason, Consumer<S> consumer) {
|
||||
default Result<S, F> onSuccessReason(S successReason, Consumer<S> consumer) {
|
||||
if (this.isSuccess() && this.successReason() == successReason) {
|
||||
consumer.accept(this.successReason());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
default Result<S, F> failureWithReason(F failureReason, Consumer<F> consumer) {
|
||||
default Result<S, F> onFailureReason(F failureReason, Consumer<F> consumer) {
|
||||
if (this.isFailure() && this.failureReason() == failureReason) {
|
||||
consumer.accept(this.failureReason());
|
||||
}
|
||||
|
@ -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 <S extends SuccessReason> ResultGroup successWithReason(Class<S> successReasonClass, Consumer<S> successConsumer) {
|
||||
public <S extends SuccessReason> ResultGroup onSuccessReason(Class<S> successReasonClass, Consumer<S> successConsumer) {
|
||||
getSuccessReason(successReasonClass).peek(successConsumer);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <F extends FailureReason> ResultGroup failureWithReason(Class<F> failureReasonClass, Consumer<F> failureConsumer) {
|
||||
public <F extends FailureReason> ResultGroup onFailureReason(Class<F> failureReasonClass, Consumer<F> failureConsumer) {
|
||||
getFailureReason(failureReasonClass).peek(failureConsumer);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <S extends SuccessReason> ResultGroup successWithReason(S successReason, Runnable successRunnable) {
|
||||
public <S extends SuccessReason> ResultGroup onSuccessReason(S successReason, Runnable successRunnable) {
|
||||
getSuccessReason(successReason.getClass()).filter(successReason::equals).peek(reason -> successRunnable.run());
|
||||
return this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user