use of be.seeseemelk.mockbukkit.entity.ItemEntityMock in project Slimefun4 by Slimefun.
the class TestItemPickupListener method testAltarProbeForEntities.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void testAltarProbeForEntities(boolean flag) {
Player player = server.addPlayer();
ItemStack stack;
if (flag) {
stack = new CustomItemStack(Material.DIAMOND, AncientPedestal.ITEM_PREFIX + System.nanoTime());
} else {
stack = new CustomItemStack(Material.DIAMOND, "&5Just a normal named diamond");
}
AtomicBoolean removed = new AtomicBoolean(false);
Item item = new ItemEntityMock(server, UUID.randomUUID(), stack) {
@Override
public void remove() {
removed.set(true);
}
};
EntityPickupItemEvent event = new EntityPickupItemEvent(player, item, 1);
listener.onEntityPickup(event);
Assertions.assertEquals(flag, event.isCancelled());
Assertions.assertEquals(flag, removed.get());
}
use of be.seeseemelk.mockbukkit.entity.ItemEntityMock in project Slimefun4 by Slimefun.
the class TestItemPickupListener method testNoPickupFlagForInventories.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void testNoPickupFlagForInventories(boolean flag) {
Inventory inventory = new HopperInventoryMock(null);
Item item = new ItemEntityMock(server, UUID.randomUUID(), new ItemStack(Material.COMPASS));
if (flag) {
SlimefunUtils.markAsNoPickup(item, "Unit Test");
}
InventoryPickupItemEvent event = new InventoryPickupItemEvent(inventory, item);
listener.onHopperPickup(event);
Assertions.assertEquals(flag, event.isCancelled());
}
use of be.seeseemelk.mockbukkit.entity.ItemEntityMock in project Slimefun4 by Slimefun.
the class TestPiglinListener method createPickupEvent.
private EntityPickupItemEvent createPickupEvent(ItemStack item) {
Piglin piglin = Mockito.mock(Piglin.class);
Mockito.when(piglin.getType()).thenReturn(EntityType.PIGLIN);
Item itemEntity = new ItemEntityMock(server, UUID.randomUUID(), item);
return new EntityPickupItemEvent(piglin, itemEntity, 1);
}
use of be.seeseemelk.mockbukkit.entity.ItemEntityMock in project MockBukkit by MockBukkit.
the class WorldMock method dropItem.
@Override
public ItemEntityMock dropItem(@NotNull Location loc, @NotNull ItemStack item, @Nullable Consumer<Item> function) {
Validate.notNull(loc, "The provided location must not be null.");
Validate.notNull(item, "Cannot drop items that are null.");
Validate.isTrue(!item.getType().isAir(), "Cannot drop air.");
ItemEntityMock entity = new ItemEntityMock(server, UUID.randomUUID(), item);
entity.setLocation(loc);
if (function != null) {
function.accept(entity);
}
server.registerEntity(entity);
return entity;
}
use of be.seeseemelk.mockbukkit.entity.ItemEntityMock in project Slimefun4 by Slimefun.
the class TestBackpackListener method testBackpackDropNormalItem.
@Test
@DisplayName("Test backpacks not disturbing normal item dropping")
void testBackpackDropNormalItem() throws InterruptedException {
Player player = server.addPlayer();
openMockBackpack(player, "DROP_NORMAL_ITEM_BACKPACK_TEST", 27);
Item item = new ItemEntityMock(server, UUID.randomUUID(), new ItemStack(Material.SUGAR_CANE));
PlayerDropItemEvent event = new PlayerDropItemEvent(player, item);
listener.onItemDrop(event);
Assertions.assertFalse(event.isCancelled());
}
Aggregations