mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 00:21:26 +01:00
Lazily add eventhandler node to root for backward compatibility
This commit is contained in:
parent
d800c94dcc
commit
12a215349d
@ -16,6 +16,7 @@ import net.minestom.server.collision.CollisionUtils;
|
||||
import net.minestom.server.data.Data;
|
||||
import net.minestom.server.data.DataContainer;
|
||||
import net.minestom.server.entity.metadata.EntityMeta;
|
||||
import net.minestom.server.event.EventCallback;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.EventFilter;
|
||||
import net.minestom.server.event.EventNode;
|
||||
@ -157,7 +158,6 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
||||
Entity.ENTITY_BY_UUID.put(uuid, this);
|
||||
|
||||
this.eventNode = EventNode.value("entity-" + uuid, EventFilter.ENTITY, this::equals);
|
||||
MinecraftServer.getGlobalEventHandler().addChild(eventNode);
|
||||
}
|
||||
|
||||
public Entity(@NotNull EntityType entityType) {
|
||||
@ -777,6 +777,14 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
||||
return eventNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized <V extends EntityEvent> boolean addEventCallback(@NotNull Class<V> eventClass, @NotNull EventCallback<V> eventCallback) {
|
||||
if (eventNode.getParent() == null) {
|
||||
MinecraftServer.getGlobalEventHandler().addChild(eventNode);
|
||||
}
|
||||
return EventHandler.super.addEventCallback(eventClass, eventCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Each entity has an unique id (server-wide) which will change after a restart.
|
||||
*
|
||||
|
@ -3,6 +3,7 @@ package net.minestom.server.event.handler;
|
||||
import net.minestom.server.event.Event;
|
||||
import net.minestom.server.event.EventCallback;
|
||||
import net.minestom.server.event.EventNode;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@ -13,7 +14,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
@Deprecated
|
||||
public interface EventHandler<T extends Event> {
|
||||
|
||||
@Deprecated
|
||||
@ApiStatus.Internal
|
||||
@Deprecated(forRemoval = true)
|
||||
@NotNull EventNode<T> getEventNode();
|
||||
|
||||
@Deprecated
|
||||
|
@ -12,6 +12,7 @@ import net.minestom.server.entity.EntityCreature;
|
||||
import net.minestom.server.entity.ExperienceOrb;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.pathfinding.PFInstanceSpace;
|
||||
import net.minestom.server.event.EventCallback;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.EventFilter;
|
||||
import net.minestom.server.event.EventNode;
|
||||
@ -121,7 +122,6 @@ public abstract class Instance implements BlockModifier, Tickable, EventHandler<
|
||||
this.worldBorder = new WorldBorder(this);
|
||||
|
||||
this.eventNode = EventNode.value("instance-" + uniqueId, EventFilter.INSTANCE, this::equals);
|
||||
MinecraftServer.getGlobalEventHandler().addChild(eventNode);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -841,6 +841,14 @@ public abstract class Instance implements BlockModifier, Tickable, EventHandler<
|
||||
return eventNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized <V extends InstanceEvent> boolean addEventCallback(@NotNull Class<V> eventClass, @NotNull EventCallback<V> eventCallback) {
|
||||
if (eventNode.getParent() == null) {
|
||||
MinecraftServer.getGlobalEventHandler().addChild(eventNode);
|
||||
}
|
||||
return EventHandler.super.addEventCallback(eventClass, eventCallback);
|
||||
}
|
||||
|
||||
// UNSAFE METHODS (need most of time to be synchronized)
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user