-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This also breaks InteractBlockEvent.Secondary and SpawnEntityEvent.Pre
- Loading branch information
Showing
3 changed files
with
96 additions
and
34 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/org/spongepowered/api/event/CompositeEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.spongepowered.api.event; | ||
|
||
import org.spongepowered.api.util.annotation.eventgen.NoFactoryMethod; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* A {@link CompositeEvent} is an {@link Event} that contains multiple | ||
* side effectual {@link Event Events}, which may have their own side effects | ||
* and may be {@link Cancellable}. In some cases, the interactions of this event | ||
* may be cancellable as a whole, but are not guaranteed to revert all side | ||
* effects on the {@link org.spongepowered.api.Game}. The {@link #children()} of | ||
* this event are ordered in a "best-effort" basis, and may not be guaranteed | ||
* to be in any particular order. | ||
* <p>Using {@link #setCancelled(boolean)} will perform a best effort cancellation | ||
* on each of the children events. | ||
*/ | ||
@NoFactoryMethod | ||
public interface CompositeEvent<E extends Event> extends Event, Cancellable { | ||
|
||
E baseEvent(); | ||
|
||
List<Event> children(); | ||
|
||
default <E extends Event> List<? extends E> event(Class<E> type) { | ||
return this.children().stream() | ||
.filter(type::isInstance) | ||
.map(type::cast) | ||
.toList(); | ||
} | ||
|
||
default <E extends Event> void applyTo(Class<E> type, Consumer<? super E> consumer) { | ||
this.children().stream() | ||
.filter(type::isInstance) | ||
.map(type::cast) | ||
.forEach(consumer); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* Cancels this event and all related events captured {@link #children()}. | ||
* Selectively, if individual events are wished to be cancelled, | ||
* the individual events should be cancelled instead. | ||
* | ||
* @param cancel The new cancelled state | ||
*/ | ||
@Override | ||
void setCancelled(boolean cancel); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters