mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-11 09:51:35 +01:00
Added EventHandler#getEventCallbacks
This commit is contained in:
parent
b6fc3ee978
commit
403e0c897f
@ -37,6 +37,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||||
|
|
||||||
@ -558,6 +559,11 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
|||||||
return eventCallbacks.computeIfAbsent(eventClass, clazz -> new CopyOnWriteArrayList<>());
|
return eventCallbacks.computeIfAbsent(eventClass, clazz -> new CopyOnWriteArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<EventCallback> getEventCallbacks() {
|
||||||
|
return eventCallbacks.values().stream().flatMap(Collection::stream);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Each entity has an unique id which will change after a restart
|
* Each entity has an unique id which will change after a restart
|
||||||
* All entities can be retrieved by calling {@link Entity#getEntity(int)}
|
* All entities can be retrieved by calling {@link Entity#getEntity(int)}
|
||||||
|
@ -5,6 +5,7 @@ import net.minestom.server.event.Event;
|
|||||||
import net.minestom.server.event.EventCallback;
|
import net.minestom.server.event.EventCallback;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public interface EventHandler {
|
public interface EventHandler {
|
||||||
|
|
||||||
@ -35,6 +36,14 @@ public interface EventHandler {
|
|||||||
*/
|
*/
|
||||||
<E extends Event> List<EventCallback> getEventCallbacks(Class<E> eventClass);
|
<E extends Event> List<EventCallback> getEventCallbacks(Class<E> eventClass);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@link Stream} containing all the added callbacks, no matter to which event they are linked
|
||||||
|
*
|
||||||
|
* @return a {@link Stream} containing all the added callbacks
|
||||||
|
*/
|
||||||
|
Stream<EventCallback> getEventCallbacks();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the specified event type using the Event object parameter
|
* Call the specified event type using the Event object parameter
|
||||||
*
|
*
|
||||||
|
@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instances are what are called "worlds" in Minecraft
|
* Instances are what are called "worlds" in Minecraft
|
||||||
@ -754,6 +755,11 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
|||||||
return eventCallbacks.computeIfAbsent(eventClass, clazz -> new CopyOnWriteArrayList<>());
|
return eventCallbacks.computeIfAbsent(eventClass, clazz -> new CopyOnWriteArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<EventCallback> getEventCallbacks() {
|
||||||
|
return eventCallbacks.values().stream().flatMap(Collection::stream);
|
||||||
|
}
|
||||||
|
|
||||||
// UNSAFE METHODS (need most of time to be synchronized)
|
// UNSAFE METHODS (need most of time to be synchronized)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user