Java Code Examples for org.bukkit.event.player.PlayerPickupItemEvent#isCancelled()
The following examples show how to use
org.bukkit.event.player.PlayerPickupItemEvent#isCancelled() .
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: EntityNewArrow.java From Carbon-2 with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void d(final EntityHuman entityhuman) { if (!this.world.isClientSide && this.inGround && (this.shake <= 0)) { boolean pickup = (this.fromPlayer == 1) || ((this.fromPlayer == 2) && entityhuman.abilities.canInstantlyBuild); ItemStack itemstack = this.getItemStack(); if ((this.fromPlayer == 1) && !entityhuman.inventory.pickup(itemstack)) { pickup = false; } final EntityItem item = new EntityItem(this.world, this.locX, this.locY, this.locZ, itemstack); final PlayerPickupItemEvent event = new PlayerPickupItemEvent((Player) entityhuman.getBukkitEntity(), new CraftItem(this.world.getServer(), this, item), 0); this.world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } if (pickup) { this.makeSound("random.pop", 0.2F, (((this.random.nextFloat() - this.random.nextFloat()) * 0.7F) + 1.0F) * 2.0F); entityhuman.receive(this, 1); this.die(); } } }
Example 2
Source File: EntityNewArrow.java From Carbon-2 with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void d(final EntityHuman entityhuman) { if (!this.world.isClientSide && this.inGround && (this.shake <= 0)) { boolean pickup = (this.fromPlayer == 1) || ((this.fromPlayer == 2) && entityhuman.abilities.canInstantlyBuild); ItemStack itemstack = this.getItemStack(); if ((this.fromPlayer == 1) && !entityhuman.inventory.pickup(itemstack)) { pickup = false; } final EntityItem item = new EntityItem(this.world, this.locX, this.locY, this.locZ, itemstack); final PlayerPickupItemEvent event = new PlayerPickupItemEvent((Player) entityhuman.getBukkitEntity(), new CraftItem(this.world.getServer(), this, item), 0); this.world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } if (pickup) { this.makeSound("random.pop", 0.2F, (((this.random.nextFloat() - this.random.nextFloat()) * 0.7F) + 1.0F) * 2.0F); entityhuman.receive(this, 1); this.die(); } } }
Example 3
Source File: ToolRepair.java From CardinalPGM with MIT License | 6 votes |
@EventHandler public void onPlayerPickupItem(PlayerPickupItemEvent event) { if (!event.isCancelled()) { ItemStack item1 = event.getItem().getItemStack(); if (materials.contains(item1.getType()) && event.getPlayer().getInventory().contains(item1.getType())) { for (ItemStack item2 : event.getPlayer().getInventory().getContents()) { if (item2 != null && Items.toMaxDurability(item1).equals(Items.toMaxDurability(item2))) { event.setCancelled(true); event.getItem().remove(); event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.1F, 1); int result = item2.getDurability() - (item1.getType().getMaxDurability() - item1.getDurability()); item2.setDurability((short) (result < 0 ? 0 : result)); break; } } } } }
Example 4
Source File: ItemTransferListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerPickupItem(PlayerPickupItemEvent event) { // When this event is fired, the ItemStack in the Item being picked up is temporarily // set to the amount that will actually be picked up, while the difference from the // actual amount in the stack is available from getRemaining(). When the event returns, // the original amount is restored to the stack, meaning that we can't change the amount // from inside the event, so instead we replace the entire stack. int initialQuantity = event.getItem().getItemStack().getAmount(); PlayerItemTransferEvent transferEvent = new PlayerItemTransferEvent( event, ItemTransferEvent.Type.PICKUP, event.getPlayer(), Optional.empty(), Optional.of(new InventorySlot<>(event.getPlayer().getInventory())), event.getItem().getItemStack(), event.getItem(), initialQuantity, event.getPlayer().getOpenInventory().getCursor() ); this.callEvent(transferEvent); int quantity = Math.min(transferEvent.getQuantity(), initialQuantity); if(!event.isCancelled() && quantity < initialQuantity) { event.setCancelled(true); if(quantity > 0) { ItemStack stack = event.getItem().getItemStack().clone(); stack.setAmount(stack.getAmount() - quantity); event.getItem().setItemStack(stack); stack = stack.clone(); stack.setAmount(quantity); event.getPlayer().getInventory().addItem(stack); event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, 1); } } }
Example 5
Source File: PlayerPickupItem.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerPickupItem(PlayerPickupItemEvent event) { if (event.isCancelled()) return; ItemStack item = event.getItem().getItemStack(); if (!AdditionsAPI.isCustomItem(item)) return; CustomItemStack cStack = new CustomItemStack(item); Bukkit.getPluginManager().callEvent(new PlayerPickupCustomItemEvent(event, cStack)); }
Example 6
Source File: ItemTransferListener.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerPickupItem(PlayerPickupItemEvent event) { // When this event is fired, the ItemStack in the Item being picked up is temporarily // set to the amount that will actually be picked up, while the difference from the // actual amount in the stack is available from getRemaining(). When the event returns, // the original amount is restored to the stack, meaning that we can't change the amount // from inside the event, so instead we replace the entire stack. int initialQuantity = event.getItem().getItemStack().getAmount(); PlayerItemTransferEvent transferEvent = new PlayerItemTransferEvent( event, ItemTransferEvent.Type.PICKUP, event.getPlayer(), null, null, event.getPlayer().getInventory(), null, event.getItem().getItemStack(), event.getItem(), initialQuantity, event.getPlayer().getOpenInventory().getCursor()); this.callEvent(transferEvent); int quantity = Math.min(transferEvent.getQuantity(), initialQuantity); if (!event.isCancelled() && quantity < initialQuantity) { event.setCancelled(true); if (quantity > 0) { ItemStack stack = event.getItem().getItemStack().clone(); stack.setAmount(stack.getAmount() - quantity); event.getItem().setItemStack(stack); stack = stack.clone(); stack.setAmount(quantity); event.getPlayer().getInventory().addItem(stack); event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ITEM_PICKUP, 1, 1); } } }