### Example IEventFilter Implementation
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
This Java code demonstrates an IEventFilter implementation that allows events extending EventBase and throws exceptions for specific call or explicit registration types.
```java
public boolean check(final Class event, final CheckType checkType) {
if (event instanceof EventBase) return true;
if (CheckType.CALL.equals(checkType)) throw new IllegalArgumentException();
if (CheckType.EXPLICIT_REGISTER.equals(checkType)) throw new IllegalArgumentException();
return false;
}
```
--------------------------------
### Create Basic LambdaManager Instance
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Instantiate the LambdaManager with a provided IGenerator. This is the main class for event management.
```java
LambdaManager eventManager = LambdaManager.basic(generator);
```
--------------------------------
### Create Thread-Safe LambdaManager Instance
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Instantiate a thread-safe LambdaManager with a provided IGenerator. Use this when concurrent access is expected.
```java
LambdaManager eventManager = LambdaManager.threadSafe(generator);
```
--------------------------------
### Gradle Dependency for LambdaEvents
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Add this to your Gradle build file to include LambdaEvents. Replace 'x.x.x' with the desired version.
```groovy
repositories {
mavenCentral()
}
dependencies {
implementation "net.lenni0451:LambdaEvents:x.x.x"
}
```
--------------------------------
### Maven Dependency for LambdaEvents
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Add this to your Maven pom.xml to include LambdaEvents. Replace 'x.x.x' with the desired version.
```xml
net.lenni0451
LambdaEvents
x.x.x
```
--------------------------------
### Implement ICancellableEvent Interface
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Implement the ICancellableEvent interface to manage event cancellation. The interface provides methods to check and set the cancellation status.
```java
public class Event implements ICancellableEvent {
private boolean cancelled = false;
public boolean isCancelled() {
return this.cancelled;
}
public void setCancelled(final boolean cancelled) {
this.cancelled = cancelled;
}
}
```
--------------------------------
### Register Static Event Handler
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Register static event handlers by passing the owner class to the LambdaManager's register method.
```java
eventManager.register(Example.class);
```
--------------------------------
### Register Independent Event Handler (Consumer)
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Register independent event handlers like Consumers by providing the handler, priority, and event type.
```java
Consumer handler = e -> System.out.println("called " + e);
eventManager.register(handler, 0, Event.class);
```
--------------------------------
### Register Virtual Event Handler
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Register virtual event handlers by passing the owner object to the LambdaManager's register method.
```java
eventManager.register(new Example());
```
--------------------------------
### Call an Event
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Call an event by passing the event object to the LambdaManager's call method.
```java
eventManager.call(new Event());
```
--------------------------------
### Register Independent Event Handler (Runnable)
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Register independent event handlers like Runnables by providing the handler, priority, and event type.
```java
Runnable handler = () -> System.out.println("called");
eventManager.register(handler, 0, Event.class);
```
--------------------------------
### EventHandler with handleCancelled = true (default)
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
This event handler will be called even if the event is cancelled, as handleCancelled defaults to true.
```java
public class Handler {
@EventHandler
public void handleEvent(final Event event) {
//This handler will be called even if the event is cancelled
}
}
```
--------------------------------
### Handle Cancelled Event in Caller
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Check if an event is cancelled after calling it and conditionally proceed. This prevents further execution if the event has been cancelled.
```java
public class Caller {
public static void callEvent(final LambdaManager eventManager) {
Event event = eventManager.call(new Event());
if (event.isCancelled()) {
return;
}
//Continue the method
//...
}
}
```
--------------------------------
### EventHandler with handleCancelled = false
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
This event handler will not be called if the event is cancelled, as handleCancelled is explicitly set to false.
```java
@EventHandler(handleCancelled = false)
public void handleEvent(final Event event) {
//This handler will not be called if the event is cancelled
}
```
--------------------------------
### Unregister All Event Handlers with Optional Static/Virtual Flag
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Unregister all event handlers for an event type, with an option to specify whether to include static/virtual handlers.
```java
//The unregisterAll method also has an optional boolean to only unregister static/virtual event handlers
eventManager.unregisterAll(event, predicate, true /*static*/);
```
--------------------------------
### Unregister Static Event Handler
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Unregister static event handlers by calling the unregister method with the owner class.
```java
eventManager.unregister(Example.class);
```
--------------------------------
### Unregister Virtual Event Handler
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Unregister virtual event handlers by calling the unregister method with the owner object instance.
```java
eventManager.unregister(oldExampleInstance);
```
--------------------------------
### Unregister All Event Handlers for an Event Type
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Unregister all event handlers for a specific event type using the unregisterAll method.
```java
//Unregister all event handlers for the event type
//This includes static and virtual event handlers
eventManager.unregisterAll(Event.class);
```
--------------------------------
### Unregister All Event Handlers with Class Predicate
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Unregister all event handlers for an event type that match a given class predicate.
```java
//Unregister all event handler for the event type and the given class predicate
//In this case all handlers which extend AbstractVirtualHandler are unregistered
//This includes static and virtual event handlers
eventManager.unregisterAll(Event.class, AbstractVirtualHandler.class::isAssignableFrom);
```
--------------------------------
### Unregister Independent Event Handler
Source: https://github.com/lenni0451/lambdaevents/blob/main/README.md
Unregister independent event handlers by calling the unregister method with the handler and event type.
```java
eventManager.unregister(handler, Event.class);
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.