mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-20 07:02:32 +01:00
Remove predicate
from the EventNode factory methods
This commit is contained in:
parent
a15717ae49
commit
734e6f5bcb
@ -31,22 +31,22 @@ public class EventNode<T extends Event> {
|
||||
return new EventNode<>(filter, (e, o) -> predicate.test(e, (V) o));
|
||||
}
|
||||
|
||||
public static <E extends Event, V> EventNode<E> predicateEvent(@NotNull EventFilter<E, V> filter,
|
||||
public static <E extends Event, V> EventNode<E> event(@NotNull EventFilter<E, V> filter,
|
||||
@NotNull Predicate<E> predicate) {
|
||||
return predicate(filter, (e, h) -> predicate.test(e));
|
||||
}
|
||||
|
||||
public static <E extends Event, V> EventNode<E> predicateValue(@NotNull EventFilter<E, V> filter,
|
||||
public static <E extends Event, V> EventNode<E> value(@NotNull EventFilter<E, V> filter,
|
||||
@NotNull Predicate<V> predicate) {
|
||||
return predicate(filter, (e, h) -> predicate.test(h));
|
||||
}
|
||||
|
||||
public static <E extends Event> EventNode<E> predicateTag(@NotNull EventFilter<E, ? extends TagReadable> filter,
|
||||
public static <E extends Event> EventNode<E> tag(@NotNull EventFilter<E, ? extends TagReadable> filter,
|
||||
@NotNull Tag<?> tag) {
|
||||
return predicate(filter, (e, h) -> h.hasTag(tag));
|
||||
}
|
||||
|
||||
public static <E extends Event, V> EventNode<E> predicateTag(@NotNull EventFilter<E, ? extends TagReadable> filter,
|
||||
public static <E extends Event, V> EventNode<E> tag(@NotNull EventFilter<E, ? extends TagReadable> filter,
|
||||
@NotNull Tag<V> tag,
|
||||
@NotNull Predicate<@Nullable V> consumer) {
|
||||
return predicate(filter, (e, h) -> consumer.test(h.getTag(tag)));
|
||||
@ -79,6 +79,7 @@ public class EventNode<T extends Event> {
|
||||
*/
|
||||
protected boolean condition(@NotNull T event) {
|
||||
final var value = filter.getHandler(event);
|
||||
System.out.println("test "+event+" "+value);
|
||||
return predicate.test(event, value);
|
||||
}
|
||||
|
||||
|
@ -150,13 +150,16 @@ public class PlayerInit {
|
||||
.expirationCount(50)
|
||||
.build());
|
||||
|
||||
var conditional = EventNode.predicateValue(EventFilter.PLAYER, Player::isCreative)
|
||||
var conditional = EventNode.value(EventFilter.PLAYER, Player::isCreative)
|
||||
.addListener(PlayerMoveEvent.class, (event) -> System.out.println("creative player moved"));
|
||||
|
||||
var tagNode = EventNode.predicateTag(EventFilter.ITEM, Tag.String("tag"));
|
||||
var tagNode = EventNode.tag(EventFilter.ITEM, Tag.String("tag"));
|
||||
|
||||
node.addChild(conditional);
|
||||
node.call(new PlayerTickEvent(null));
|
||||
node.addChild(EventNode.value(EventFilter.PLAYER, player -> player.getUsername().equals("TheMode911"))
|
||||
.addListener(PlayerMoveEvent.class, event -> System.out.println("move!"))
|
||||
.addListener(PlayerTickEvent.class, event -> System.out.println("tick!")));
|
||||
//node.addChild(tagNode); -> Error: cannot add an item listener to a player node
|
||||
|
||||
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
|
||||
globalEventHandler.addEventCallback(EntityAttackEvent.class, event -> {
|
||||
|
Loading…
Reference in New Issue
Block a user