mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-28 02:51:42 +01:00
Add binding test
This commit is contained in:
parent
3972477b3b
commit
90a217eb9b
@ -1,9 +1,6 @@
|
||||
package event;
|
||||
|
||||
import net.minestom.server.event.Event;
|
||||
import net.minestom.server.event.EventFilter;
|
||||
import net.minestom.server.event.EventListener;
|
||||
import net.minestom.server.event.EventNode;
|
||||
import net.minestom.server.event.*;
|
||||
import net.minestom.server.event.trait.CancellableEvent;
|
||||
import net.minestom.server.event.trait.ItemEvent;
|
||||
import net.minestom.server.event.trait.RecursiveEvent;
|
||||
@ -163,4 +160,34 @@ public class EventNodeTest {
|
||||
assertTrue(result.get(), "The event should be called");
|
||||
assertTrue(childResult.get(), "The child event should be called");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBinding() {
|
||||
|
||||
record ItemTestEvent(ItemStack item) implements ItemEvent {
|
||||
@Override
|
||||
public @NotNull ItemStack getItemStack() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
var node = EventNode.all("main");
|
||||
|
||||
AtomicBoolean result = new AtomicBoolean(false);
|
||||
var binding = EventBinding.filtered(EventFilter.ITEM, itemStack -> itemStack.getMaterial() == Material.DIAMOND)
|
||||
.map(ItemTestEvent.class, (itemStack, itemTestEvent) -> result.set(true))
|
||||
.build();
|
||||
node.register(binding);
|
||||
node.call(new ItemTestEvent(ItemStack.of(Material.GOLD_BLOCK)));
|
||||
assertFalse(result.get());
|
||||
|
||||
result.set(false);
|
||||
node.call(new ItemTestEvent(ItemStack.of(Material.DIAMOND)));
|
||||
assertTrue(result.get());
|
||||
|
||||
result.set(false);
|
||||
node.unregister(binding);
|
||||
node.call(new ItemTestEvent(ItemStack.of(Material.DIAMOND)));
|
||||
assertFalse(result.get());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user