mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-19 06:32:03 +01:00
Added EventHandler#removeEventCallback
This commit is contained in:
parent
b1e86adb23
commit
45e8ba2f03
@ -496,6 +496,15 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
||||
this.eventCallbacks.put(eventClass, callbacks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends Event> void removeEventCallback(Class<E> eventClass, EventCallback<E> eventCallback) {
|
||||
Check.notNull(eventClass, "Event class cannot be null");
|
||||
Check.notNull(eventCallback, "Event callback cannot be null");
|
||||
List<EventCallback> callbacks = getEventCallbacks(eventClass);
|
||||
callbacks.remove(eventCallback);
|
||||
this.eventCallbacks.put(eventClass, callbacks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends Event> List<EventCallback> getEventCallbacks(Class<E> eventClass) {
|
||||
Check.notNull(eventClass, "Event class cannot be null");
|
||||
|
@ -1680,7 +1680,7 @@ public class Player extends LivingEntity {
|
||||
}
|
||||
|
||||
/**
|
||||
* All packets in the queue are executed in the {@link #update()} method
|
||||
* All packets in the queue are executed in the {@link #update(long)} method
|
||||
* It is used internally to add all received packet from the client
|
||||
* Could be used to "simulate" a received packet, but to use at your own risk
|
||||
*
|
||||
|
@ -3,6 +3,9 @@ package net.minestom.server.event.entity;
|
||||
import net.minestom.server.entity.ItemEntity;
|
||||
import net.minestom.server.event.CancellableEvent;
|
||||
|
||||
/**
|
||||
* Called when two {@link ItemEntity} are merging their ItemStack together to form a sole entity
|
||||
*/
|
||||
public class EntityItemMergeEvent extends CancellableEvent {
|
||||
|
||||
private ItemEntity source;
|
||||
@ -13,10 +16,24 @@ public class EntityItemMergeEvent extends CancellableEvent {
|
||||
this.merged = merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity who is receiving {@link #getMerged()} ItemStack
|
||||
* <p>
|
||||
* This can be used to get the final ItemEntity position
|
||||
*
|
||||
* @return the source ItemEntity
|
||||
*/
|
||||
public ItemEntity getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity who will be merged
|
||||
* <p>
|
||||
* This entity will be removed after the event
|
||||
*
|
||||
* @return the merged ItemEntity
|
||||
*/
|
||||
public ItemEntity getMerged() {
|
||||
return merged;
|
||||
}
|
||||
|
@ -17,6 +17,15 @@ public interface EventHandler {
|
||||
*/
|
||||
<E extends Event> void addEventCallback(Class<E> eventClass, EventCallback<E> eventCallback);
|
||||
|
||||
/**
|
||||
* Remove an event callback
|
||||
*
|
||||
* @param eventClass the event class
|
||||
* @param eventCallback the event callback
|
||||
* @param <E> the event type
|
||||
*/
|
||||
<E extends Event> void removeEventCallback(Class<E> eventClass, EventCallback<E> eventCallback);
|
||||
|
||||
/**
|
||||
* @param eventClass
|
||||
* @param <E>
|
||||
|
@ -425,6 +425,13 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
this.eventCallbacks.put(eventClass, callbacks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends Event> void removeEventCallback(Class<E> eventClass, EventCallback<E> eventCallback) {
|
||||
List<EventCallback> callbacks = getEventCallbacks(eventClass);
|
||||
callbacks.remove(eventCallback);
|
||||
this.eventCallbacks.put(eventClass, callbacks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends Event> List<EventCallback> getEventCallbacks(Class<E> eventClass) {
|
||||
return eventCallbacks.getOrDefault(eventClass, new CopyOnWriteArrayList<>());
|
||||
|
Loading…
Reference in New Issue
Block a user