mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-16 07:35:35 +01:00
Allow node predicate based on tag
This commit is contained in:
parent
27bdbe7275
commit
9177e94d1b
@ -2,8 +2,11 @@ package net.minestom.server.event;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import net.minestom.server.tag.Tag;
|
||||
import net.minestom.server.tag.TagReadable;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -38,6 +41,17 @@ public class EventNode<T extends Event> {
|
||||
return predicate(filter, (e, h) -> predicate.test(h));
|
||||
}
|
||||
|
||||
public static <E extends Event, V extends TagReadable> EventNode<E> predicateTag(@NotNull EventFilter<E, V> filter,
|
||||
@NotNull Tag<?> tag) {
|
||||
return predicate(filter, (e, h) -> h.hasTag(tag));
|
||||
}
|
||||
|
||||
public static <E extends Event, V extends TagReadable, V2> EventNode<E> predicateTag(@NotNull EventFilter<E, V> filter,
|
||||
@NotNull Tag<V2> tag,
|
||||
@NotNull Predicate<@Nullable V2> consumer) {
|
||||
return predicate(filter, (e, h) -> consumer.test(h.getTag(tag)));
|
||||
}
|
||||
|
||||
private final Map<Class<? extends T>, List<EventListener<T>>> listenerMap = new ConcurrentHashMap<>();
|
||||
private final Map<Object, EventNode<T>> redirectionMap = new ConcurrentHashMap<>();
|
||||
private final Set<EventNode<T>> children = new CopyOnWriteArraySet<>();
|
||||
|
@ -35,6 +35,7 @@ import net.minestom.server.item.metadata.CompassMeta;
|
||||
import net.minestom.server.monitoring.BenchmarkManager;
|
||||
import net.minestom.server.monitoring.TickMonitor;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.tag.Tag;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.Vector;
|
||||
@ -152,6 +153,8 @@ public class PlayerInit {
|
||||
var conditional = EventNode.predicateValue(EventFilter.PLAYER, Player::isCreative)
|
||||
.addListener(PlayerMoveEvent.class, (event) -> System.out.println("creative player moved"));
|
||||
|
||||
var tagNode = EventNode.predicateTag(EventFilter.ITEM, Tag.String("tag"), s -> s != null && !s.isEmpty());
|
||||
|
||||
node.addChild(conditional);
|
||||
node.call(new PlayerTickEvent(null));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user