org.bukkit.event.inventory.InventoryPickupItemEvent Java Examples

The following examples show how to use org.bukkit.event.inventory.InventoryPickupItemEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemTransferListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onBlockPickupItem(InventoryPickupItemEvent event) {
    int initialQuantity = getQuantityPlaceable(event.getItem().getItemStack(), event.getInventory());
    ItemTransferEvent transferEvent = new ItemTransferEvent(
        event, ItemTransferEvent.Type.PICKUP,
        Optional.empty(),
        Optional.of(new InventorySlot<>(event.getInventory())),
        event.getItem().getItemStack(), event.getItem(), initialQuantity
    );

    this.callEvent(transferEvent);

    if(initialQuantity != transferEvent.getQuantity() && !event.isCancelled()) {
        event.setCancelled(true);
        ItemStack stack = event.getItem().getItemStack();
        stack.setAmount(stack.getAmount() - transferEvent.getQuantity());
        stack = stack.clone();
        stack.setAmount(transferEvent.getQuantity());
        event.getInventory().addItem(stack);
    }
}
 
Example #2
Source File: BlockListeners.java    From CratesPlus with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryPickup(InventoryPickupItemEvent event) {
    if (!cratesPlus.getConfigHandler().isDisableKeySwapping())
        return;
    if (event.getItem().getItemStack() != null) {
        String title;
        ItemStack item = event.getItem().getItemStack();
        for (Map.Entry<String, Crate> crate : cratesPlus.getConfigHandler().getCrates().entrySet()) {
            if (!(crate.getValue() instanceof KeyCrate)) {
                continue;
            }
            KeyCrate keyCrate = (KeyCrate) crate.getValue();
            Key key = keyCrate.getKey();
            if (key == null)
                continue;
            title = key.getName();

            if (item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().contains(title)) {
                // Send message?
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example #3
Source File: QAListener.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onHopperpickup(InventoryPickupItemEvent e) {
	if (e.isCancelled())
		return;
	if (e.getInventory().getType() == InventoryType.HOPPER)
		if (QualityArmory.isGun(e.getItem().getItemStack()))
			e.setCancelled(true);
}
 
Example #4
Source File: ItemDropEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
@SuppressWarnings("unused")
public void onPickupInventoryEvent(InventoryPickupItemEvent event) {
    if (!plugin.getWorldManager().isSkyWorld(event.getItem().getWorld())) {
        return;
    }
    // I.e. hoppers...
    clearDropInfo(event.getItem());
}
 
Example #5
Source File: ItemPickupListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onHopperPickup(InventoryPickupItemEvent e) {
    if (SlimefunUtils.hasNoPickupFlag(e.getItem())) {
        e.setCancelled(true);
    }
    else if (e.getItem().getItemStack().hasItemMeta() && e.getItem().getItemStack().getItemMeta().hasDisplayName() && e.getItem().getItemStack().getItemMeta().getDisplayName().startsWith(ITEM_PREFIX)) {
        e.setCancelled(true);
        e.getItem().remove();
    }
}
 
Example #6
Source File: CustomItemListener.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
private void inventoryPickupItemItem(InventoryPickupItemEvent event) {
	CustomItem customItem = CustomItemManager.getCustomItem(event.getItem().getItemStack());
	if (verifyCustomItem(customItem, event.getItem().getWorld())) {
		customItem.onDropperPickup(event);
	}
}
 
Example #7
Source File: QuickCrate.java    From Crazy-Crates with MIT License 4 votes vote down vote up
@EventHandler
public void onHopperPickUp(InventoryPickupItemEvent e) {
    if (cc.isDisplayReward(e.getItem())) {
        e.setCancelled(true);
    }
}
 
Example #8
Source File: EffectEventHandlers.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void hopperPickupSafeguard(InventoryPickupItemEvent event) {
    if (EntityTracker.isItemVisualEffect(event.getItem()))
        event.setCancelled(true);
}
 
Example #9
Source File: BatBomb.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDropperPickup(InventoryPickupItemEvent event) {
	if (event.getItem().hasMetadata("is-active")) {
		event.setCancelled(true);
	}
}
 
Example #10
Source File: ChickenHandler.java    From EliteMobs with GNU General Public License v3.0 3 votes vote down vote up
@EventHandler
public void onHopperSuperEggPickup(InventoryPickupItemEvent event) {

    if (event.getItem().getItemStack().hasItemMeta() && event.getItem().getItemStack().getItemMeta().hasLore() &&
            event.getItem().getItemStack().getItemMeta().getLore().equals(lore)) {

        event.setCancelled(true);

    }

}
 
Example #11
Source File: CustomItem.java    From NBTEditor with GNU General Public License v3.0 votes vote down vote up
public void onDropperPickup(InventoryPickupItemEvent event) { }