Search in sources :

Example 1 with EntityPickupItemEvent

use of org.bukkit.event.entity.EntityPickupItemEvent in project Glowstone by GlowstoneMC.

the class GlowItem method getPickedUp.

private boolean getPickedUp(LivingEntity entity) {
    int starting = getItemStack().getAmount();
    int remaining = 0;
    if (entity instanceof InventoryHolder) {
        HashMap<Integer, ItemStack> map = ((InventoryHolder) entity).getInventory().addItem(getItemStack());
        if (entity instanceof GlowPlayer) {
            // TODO: PlayerAttemptPickupItemEvent
            GlowPlayer player = ((GlowPlayer) entity);
            // workaround for player editing slot & it immediately being filled again
            player.updateInventory();
        }
        if (!map.isEmpty()) {
            ItemStack remainingItem = map.get(0);
            setItemStack(remainingItem);
            remaining = remainingItem.getAmount();
        }
        EntityPickupItemEvent entityPickupEvent = new EntityPickupItemEvent(entity, this, remaining);
        EventFactory.getInstance().callEvent(entityPickupEvent);
        if (remaining > 0) {
            return false;
        }
    }
    entity.playPickupItemAnimation(this, starting - remaining);
    return true;
}
Also used : EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) GlowPlayer(net.glowstone.entity.GlowPlayer) ItemStack(org.bukkit.inventory.ItemStack) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 2 with EntityPickupItemEvent

use of org.bukkit.event.entity.EntityPickupItemEvent 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 3 with EntityPickupItemEvent

use of org.bukkit.event.entity.EntityPickupItemEvent 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 EntityPickupItemEvent

use of org.bukkit.event.entity.EntityPickupItemEvent in project Slimefun4 by Slimefun.

the class TestPiglinListener method testPiglinPickupWithSlimefunItem.

@Test
void testPiglinPickupWithSlimefunItem() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PIGLIN_PICKUP_MOCK", new CustomItemStack(Material.GOLD_INGOT, "&6Piglin Bait"));
    item.register(plugin);
    EntityPickupItemEvent event = createPickupEvent(item.getItem());
    listener.onPickup(event);
    Assertions.assertTrue(event.isCancelled());
}
Also used : EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with EntityPickupItemEvent

use of org.bukkit.event.entity.EntityPickupItemEvent in project Slimefun4 by Slimefun.

the class TestPiglinListener method testPiglinPickup.

@Test
void testPiglinPickup() {
    EntityPickupItemEvent event = createPickupEvent(new ItemStack(Material.GOLD_INGOT));
    listener.onPickup(event);
    Assertions.assertFalse(event.isCancelled());
}
Also used : EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

EntityPickupItemEvent (org.bukkit.event.entity.EntityPickupItemEvent)9 ItemStack (org.bukkit.inventory.ItemStack)6 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)4 Item (org.bukkit.entity.Item)4 Player (org.bukkit.entity.Player)4 ItemEntityMock (be.seeseemelk.mockbukkit.entity.ItemEntityMock)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)2 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)1 PlayerDataManager (com.github.sirblobman.api.configuration.PlayerDataManager)1 Replacer (com.github.sirblobman.api.language.Replacer)1 WorldXYZ (com.github.sirblobman.api.object.WorldXYZ)1 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)1 PlayerPunishEvent (com.github.sirblobman.combatlogx.api.event.PlayerPunishEvent)1 PlayerUntagEvent (com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent)1 Expansion (com.github.sirblobman.combatlogx.api.expansion.Expansion)1