mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 00:21:26 +01:00
Fix checks
This commit is contained in:
parent
34cde8390a
commit
3fae5ed35f
@ -107,7 +107,8 @@ public class EventNode<T extends Event> {
|
||||
}
|
||||
|
||||
public void call(@NotNull T event) {
|
||||
if (!eventType.isInstance(event)) {
|
||||
final var eventClass = event.getClass();
|
||||
if (!eventType.isAssignableFrom(eventClass)) {
|
||||
// Invalid event type
|
||||
return;
|
||||
}
|
||||
@ -116,7 +117,7 @@ public class EventNode<T extends Event> {
|
||||
return;
|
||||
}
|
||||
// Process listener list
|
||||
final var entry = listenerMap.get(event.getClass());
|
||||
final var entry = listenerMap.get(eventClass);
|
||||
if (entry == null) {
|
||||
// No listener nor children
|
||||
return;
|
||||
@ -203,6 +204,7 @@ public class EventNode<T extends Event> {
|
||||
if (EventNode.equals(child, name, eventType)) {
|
||||
removeChild(child);
|
||||
addChild(eventNode);
|
||||
return;
|
||||
}
|
||||
child.replaceChildren(name, eventType, eventNode);
|
||||
});
|
||||
@ -221,6 +223,7 @@ public class EventNode<T extends Event> {
|
||||
this.children.forEach(child -> {
|
||||
if (EventNode.equals(child, name, eventType)) {
|
||||
removeChild(child);
|
||||
return;
|
||||
}
|
||||
child.removeChildren(name, eventType);
|
||||
});
|
||||
@ -340,7 +343,7 @@ public class EventNode<T extends Event> {
|
||||
|
||||
private static boolean equals(EventNode<?> node, String name, Class<?> eventType) {
|
||||
final boolean nameCheck = node.getName().equals(name);
|
||||
final boolean typeCheck = node.eventType.isAssignableFrom(eventType);
|
||||
final boolean typeCheck = eventType.isAssignableFrom(node.eventType);
|
||||
return nameCheck && typeCheck;
|
||||
}
|
||||
|
||||
|
@ -11,14 +11,13 @@ import net.minestom.server.entity.ItemEntity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.damage.DamageType;
|
||||
import net.minestom.server.event.Event;
|
||||
import net.minestom.server.event.EventFilter;
|
||||
import net.minestom.server.event.EventNode;
|
||||
import net.minestom.server.event.entity.EntityAttackEvent;
|
||||
import net.minestom.server.event.item.ItemDropEvent;
|
||||
import net.minestom.server.event.item.PickupItemEvent;
|
||||
import net.minestom.server.event.player.PlayerDeathEvent;
|
||||
import net.minestom.server.event.player.PlayerDisconnectEvent;
|
||||
import net.minestom.server.event.player.PlayerLoginEvent;
|
||||
import net.minestom.server.event.player.PlayerSpawnEvent;
|
||||
import net.minestom.server.event.player.*;
|
||||
import net.minestom.server.event.trait.PlayerEvent;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.instance.InstanceContainer;
|
||||
import net.minestom.server.instance.InstanceManager;
|
||||
@ -157,9 +156,8 @@ public class PlayerInit {
|
||||
var eventHandler = MinecraftServer.getGlobalEventHandler();
|
||||
eventHandler.addChild(DEMO_NODE);
|
||||
var children = eventHandler.findChildren("demo", Event.class);
|
||||
eventHandler.replaceChildren("demo", Event.class, EventNode.all("new_demo"));
|
||||
eventHandler.replaceChildren("new_demo", EventNode.all("new_demo2"));
|
||||
eventHandler.removeChildren("new_demo2");
|
||||
|
||||
eventHandler.replaceChildren("demo", PlayerEvent.class, EventNode.type("random", EventFilter.PLAYER));
|
||||
|
||||
MinecraftServer.getUpdateManager().addTickMonitor(tickMonitor ->
|
||||
LAST_TICK.set(tickMonitor));
|
||||
|
Loading…
Reference in New Issue
Block a user