mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-29 05:55:48 +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)
|
worldEntryCheckerProvider.forWorld(player, world)
|
||||||
.canStayInWorld()
|
.canStayInWorld()
|
||||||
.success(() -> oneTickLater(() -> handleGameModeAndFlight(player, world)))
|
.onSuccess(() -> oneTickLater(() -> handleGameModeAndFlight(player, world)))
|
||||||
.failure(() -> {
|
.onFailure(() -> {
|
||||||
player.sendMessage("[MV] - Sorry you can't be in this world anymore!");
|
player.sendMessage("[MV] - Sorry you can't be in this world anymore!");
|
||||||
oneTickLater(() -> player.teleport(spawnLocation));
|
oneTickLater(() -> player.teleport(spawnLocation));
|
||||||
});
|
});
|
||||||
@ -175,13 +175,13 @@ public class NewMVPlayerListener implements InjectableListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResultGroup worldEntryResult = worldEntryCheckerProvider.forWorld(player, toWorld).canEnterWorld(fromWorld)
|
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());
|
Logging.fine("Player '%s' is allowed to use portals to enter world '%s'.", player.getName(), toWorld.getName());
|
||||||
if (!config.isUsingCustomPortalSearch()) {
|
if (!config.isUsingCustomPortalSearch()) {
|
||||||
event.setSearchRadius(config.getCustomPortalSearchRadius());
|
event.setSearchRadius(config.getCustomPortalSearchRadius());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.failure(() -> {
|
.onFailure(() -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Logging.fine("Player '%s' is not allowed to use portals to enter world '%s'.", player.getName(), toWorld.getName());
|
Logging.fine("Player '%s' is not allowed to use portals to enter world '%s'.", player.getName(), toWorld.getName());
|
||||||
//TODO send player reason for failure
|
//TODO send player reason for failure
|
||||||
@ -230,12 +230,12 @@ public class NewMVPlayerListener implements InjectableListener {
|
|||||||
|
|
||||||
ResultGroup worldEntryResult = worldEntryCheckerProvider.forWorld(teleportee, toWorld)
|
ResultGroup worldEntryResult = worldEntryCheckerProvider.forWorld(teleportee, toWorld)
|
||||||
.canEnterWorld(fromWorld.getOrNull())
|
.canEnterWorld(fromWorld.getOrNull())
|
||||||
.success(() -> Logging.fine("MV-Core is allowing '%s' to go to '%s'.", teleportee.getName(), toWorld.getName()))
|
.onSuccess(() -> Logging.fine("MV-Core is allowing '%s' to go to '%s'.", teleportee.getName(), toWorld.getName()))
|
||||||
.successWithReason(EntryFeeResult.Success.ENOUGH_MONEY, () -> {
|
.onSuccessReason(EntryFeeResult.Success.ENOUGH_MONEY, () -> {
|
||||||
economist.payEntryFee((Player) teleporter, toWorld);
|
economist.payEntryFee((Player) teleporter, toWorld);
|
||||||
//TODO send payment message
|
//TODO send payment message
|
||||||
})
|
})
|
||||||
.failure(() -> {
|
.onFailure(() -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Logging.fine("MV-Core is denying '%s' from going to '%s'.", teleportee.getName(), toWorld.getName());
|
Logging.fine("MV-Core is denying '%s' from going to '%s'.", teleportee.getName(), toWorld.getName());
|
||||||
//TODO send player reason for failure
|
//TODO send player reason for failure
|
||||||
|
@ -20,28 +20,28 @@ public sealed interface Result<S extends SuccessReason, F extends FailureReason>
|
|||||||
|
|
||||||
F failureReason();
|
F failureReason();
|
||||||
|
|
||||||
default Result<S, F> success(Consumer<S> consumer) {
|
default Result<S, F> onSuccess(Consumer<S> consumer) {
|
||||||
if (this.isSuccess()) {
|
if (this.isSuccess()) {
|
||||||
consumer.accept(this.successReason());
|
consumer.accept(this.successReason());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
default Result<S, F> failure(Consumer<F> consumer) {
|
default Result<S, F> onFailure(Consumer<F> consumer) {
|
||||||
if (this.isFailure()) {
|
if (this.isFailure()) {
|
||||||
consumer.accept(this.failureReason());
|
consumer.accept(this.failureReason());
|
||||||
}
|
}
|
||||||
return this;
|
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) {
|
if (this.isSuccess() && this.successReason() == successReason) {
|
||||||
consumer.accept(this.successReason());
|
consumer.accept(this.successReason());
|
||||||
}
|
}
|
||||||
return this;
|
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) {
|
if (this.isFailure() && this.failureReason() == failureReason) {
|
||||||
consumer.accept(this.failureReason());
|
consumer.accept(this.failureReason());
|
||||||
}
|
}
|
||||||
|
@ -35,31 +35,31 @@ public class ResultGroup {
|
|||||||
return !isSuccess;
|
return !isSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultGroup success(Runnable successRunnable) {
|
public ResultGroup onSuccess(Runnable successRunnable) {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
successRunnable.run();
|
successRunnable.run();
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultGroup failure(Runnable failureRunnable) {
|
public ResultGroup onFailure(Runnable failureRunnable) {
|
||||||
if (isFailure()) {
|
if (isFailure()) {
|
||||||
failureRunnable.run();
|
failureRunnable.run();
|
||||||
}
|
}
|
||||||
return this;
|
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);
|
getSuccessReason(successReasonClass).peek(successConsumer);
|
||||||
return this;
|
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);
|
getFailureReason(failureReasonClass).peek(failureConsumer);
|
||||||
return this;
|
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());
|
getSuccessReason(successReason.getClass()).filter(successReason::equals).peek(reason -> successRunnable.run());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user