Browse Source

Add interruptTrue/Default/False as util methods

shedaniel 4 years ago
parent
commit
5accb65ee8

+ 33 - 0
common/src/main/java/me/shedaniel/architectury/event/CompoundEventResult.java

@@ -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;

+ 30 - 0
common/src/main/java/me/shedaniel/architectury/event/EventResult.java

@@ -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;

+ 1 - 1
gradle.properties

@@ -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