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;
}
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());
}
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);
}
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());
}
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());
}
Aggregations