Search in sources :

Example 1 with ItemEntityMock

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Item(org.bukkit.entity.Item) EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) Player(org.bukkit.entity.Player) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemEntityMock(be.seeseemelk.mockbukkit.entity.ItemEntityMock) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ItemEntityMock

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());
}
Also used : HopperInventoryMock(be.seeseemelk.mockbukkit.inventory.HopperInventoryMock) Item(org.bukkit.entity.Item) InventoryPickupItemEvent(org.bukkit.event.inventory.InventoryPickupItemEvent) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemEntityMock(be.seeseemelk.mockbukkit.entity.ItemEntityMock) Inventory(org.bukkit.inventory.Inventory) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ItemEntityMock

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);
}
Also used : Item(org.bukkit.entity.Item) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) Piglin(org.bukkit.entity.Piglin) ItemEntityMock(be.seeseemelk.mockbukkit.entity.ItemEntityMock)

Example 4 with ItemEntityMock

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;
}
Also used : ItemEntityMock(be.seeseemelk.mockbukkit.entity.ItemEntityMock)

Example 5 with ItemEntityMock

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());
}
Also used : PlayerDropItemEvent(org.bukkit.event.player.PlayerDropItemEvent) Item(org.bukkit.entity.Item) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemEntityMock(be.seeseemelk.mockbukkit.entity.ItemEntityMock) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

ItemEntityMock (be.seeseemelk.mockbukkit.entity.ItemEntityMock)7 Item (org.bukkit.entity.Item)6 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)5 ItemStack (org.bukkit.inventory.ItemStack)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 Player (org.bukkit.entity.Player)3 EntityPickupItemEvent (org.bukkit.event.entity.EntityPickupItemEvent)3 HopperInventoryMock (be.seeseemelk.mockbukkit.inventory.HopperInventoryMock)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 InventoryPickupItemEvent (org.bukkit.event.inventory.InventoryPickupItemEvent)2 Inventory (org.bukkit.inventory.Inventory)2 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)1 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)1 Piglin (org.bukkit.entity.Piglin)1 PlayerDropItemEvent (org.bukkit.event.player.PlayerDropItemEvent)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1