Add interruptTrue/Default/False as util methods

This commit is contained in:
shedaniel
2021-04-17 22:05:35 +08:00
parent f06776d884
commit 5accb65ee8
3 changed files with 64 additions and 1 deletions

View File

@@ -58,6 +58,39 @@ public class CompoundEventResult<T> {
return new CompoundEventResult<>(EventResult.interrupt(value), object);
}
/**
* Interrupts the event and stops it from being passed on to other listeners,
* denotes the {@code true} outcome and may or may not set an extra data of the event.
*
* @param object the extra data of the result, this usually is the returning value of the event
* @return an event that interrupts the event
*/
public static <T> CompoundEventResult<T> interruptTrue(T object) {
return new CompoundEventResult<>(EventResult.interruptTrue(), object);
}
/**
* Interrupts the event and stops it from being passed on to other listeners,
* does not set an outcome and may or may not set an extra data of the event.
*
* @param object the extra data of the result, this usually is the returning value of the event
* @return an event that interrupts the event
*/
public static <T> CompoundEventResult<T> interruptDefault(T object) {
return new CompoundEventResult<>(EventResult.interruptDefault(), object);
}
/**
* Interrupts the event and stops it from being passed on to other listeners,
* denotes the {@code false} outcome and may or may not set an extra data of the event.
*
* @param object the extra data of the result, this usually is the returning value of the event
* @return an event that interrupts the event
*/
public static <T> CompoundEventResult<T> interruptFalse(T object) {
return new CompoundEventResult<>(EventResult.interruptFalse(), object);
}
private CompoundEventResult(EventResult result, T object) {
this.result = result;
this.object = object;

View File

@@ -56,6 +56,36 @@ public final class EventResult {
return FALSE;
}
/**
* Interrupts the event and stops it from being passed on to other listeners,
* and denotes the {@code true} outcome.
*
* @return an event that interrupts the event
*/
public static EventResult interruptTrue() {
return TRUE;
}
/**
* Interrupts the event and stops it from being passed on to other listeners,
* and does not set an outcome.
*
* @return an event that interrupts the event
*/
public static EventResult interruptDefault() {
return STOP;
}
/**
* Interrupts the event and stops it from being passed on to other listeners,
* and denotes the {@code false} outcome.
*
* @return an event that interrupts the event
*/
public static EventResult interruptFalse() {
return FALSE;
}
private final boolean interruptsFurtherEvaluation;
private final Boolean value;

View File

@@ -6,7 +6,7 @@ supported_version=1.16.4/5
archives_base_name=architectury
archives_base_name_snapshot=architectury-snapshot
base_version=1.11
base_version=1.12
maven_group=me.shedaniel
fabric_loader_version=0.11.1