Fix checks

This commit is contained in:
TheMode 2021-06-08 17:18:00 +02:00
parent 34cde8390a
commit 3fae5ed35f
2 changed files with 11 additions and 10 deletions

View File

@ -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;
}

View File

@ -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));