Java Code Examples for org.bukkit.event.player.PlayerPickupItemEvent#setCancelled()
The following examples show how to use
org.bukkit.event.player.PlayerPickupItemEvent#setCancelled() .
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: PlayerEventHandler.java From GriefDefender with MIT License | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerPickupItem(PlayerPickupItemEvent event) { if (!GDFlags.ITEM_PICKUP) { return; } final Player player = event.getPlayer(); GDCauseStackManager.getInstance().pushCause(player); final World world = player.getWorld(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) { return; } if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ITEM_PICKUP.getName(), player, world.getUID())) { return; } if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_PICKUP.getName(), event.getItem(), world.getUID())) { return; } final Location location = event.getItem().getLocation(); final GDClaim targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location); if (GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.ITEM_PICKUP, player, event.getItem(), player, TrustTypes.ACCESSOR, true) == Tristate.FALSE) { event.setCancelled(true); } }
Example 2
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 3
Source File: PlayerListener.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onPickup(PlayerPickupItemEvent ppie) { Player player = ppie.getPlayer(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { game = BedwarsRel.getInstance().getGameManager().getGameByLocation(player.getLocation()); if (game == null) { return; } } if (game.getState() != GameState.WAITING && game.isInGame(player)) { return; } ppie.setCancelled(true); }
Example 4
Source File: Events_v1_11_R1_Down.java From Crazy-Crates with MIT License | 5 votes |
@EventHandler public void onItemPickUp(PlayerPickupItemEvent e) { if (cc.isDisplayReward(e.getItem())) { e.setCancelled(true); } if (cc.isInOpeningList(e.getPlayer())) { e.setCancelled(true); } }
Example 5
Source File: CreativeModeListener.java From ShopChest with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerPickup(PlayerPickupItemEvent e) { // Cancel any item pickups if SelectClickType is set ClickType clickType = ClickType.getPlayerClickType(e.getPlayer()); if (clickType instanceof SelectClickType) e.setCancelled(true); }
Example 6
Source File: PlayerPickupItem.java From ZombieEscape with GNU General Public License v2.0 | 5 votes |
@EventHandler public void onPickup(PlayerPickupItemEvent event) { if (event.getPlayer().getWorld().getName().equals("world")) { event.setCancelled(true); } else { event.setCancelled(true); } }
Example 7
Source File: GeneralEventHandler.java From SuperVanish with Mozilla Public License 2.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onItemPickUp(PlayerPickupItemEvent e) { try { VanishPlayer vanishPlayer = plugin.getVanishPlayer(e.getPlayer()); if (vanishPlayer == null || !vanishPlayer.isOnlineVanished()) return; if (!vanishPlayer.hasItemPickUpsEnabled()) e.setCancelled(true); if (plugin.getSettings().getBoolean("RestrictiveOptions.PreventModifyingOwnInventory") && !vanishPlayer.getPlayer().hasPermission("sv.modifyowninv")) { e.setCancelled(true); } } catch (Exception er) { plugin.logException(er); } }
Example 8
Source File: Trade.java From TradePlus with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPickup(PlayerPickupItemEvent event) { if (cancelled) return; Player player = event.getPlayer(); if (player.equals(player1) || player.equals(player2)) { event.setCancelled(true); } }
Example 9
Source File: ListenerLegacyItemPickup.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority= EventPriority.HIGH, ignoreCancelled=true) public void onPickupItem(PlayerPickupItemEvent e) { FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); if(!config.getBoolean("items.prevent-item-pickup")) return; Player player = e.getPlayer(); ICombatManager combatManager = this.plugin.getCombatManager(); if(!combatManager.isInCombat(player)) return; e.setCancelled(true); sendMessage(player); }
Example 10
Source File: EntityPickupItemListener.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@EventHandler public void onEntityPickupItem(PlayerPickupItemEvent event) { try { final Item item = event.getItem(); final Location location = item.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); final Island island = islandManager.getIslandViaLocation(location); if (island == null) return; final Player player = event.getPlayer(); final User user = User.getUser(player); if (!island.getPermissions(user).pickupItems) event.setCancelled(true); } catch (Exception ex) { IridiumSkyblock.getInstance().sendErrorMessage(ex); } }
Example 11
Source File: PlayerPickupItem.java From StaffPlus with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPickup(PlayerPickupItemEvent event) { Player player = event.getPlayer(); if(options.modeItemChange || !modeCoordinator.isInMode(player.getUniqueId())) { return; } event.setCancelled(true); }
Example 12
Source File: PlayerPickupCustomItem.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerPickupCustomItemLowest(PlayerPickupCustomItemEvent customEvent) { if (customEvent.isCancelled()) return; CustomItem cItem = customEvent.getCustomItem(); ItemPermissions perm = cItem.getPermissions(); PlayerPickupItemEvent event = customEvent.getPlayerPickupItemEvent(); if (!PermissionUtils.allowedAction(event.getPlayer(), perm.getType(), perm.getPickup())) event.setCancelled(true); }
Example 13
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 14
Source File: ToolRepairMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private void doRepair(PlayerPickupItemEvent event, ItemStack stack) { ItemStack pickup = event.getItem().getItemStack(); int hitsLeft = pickup.getType().getMaxDurability() - pickup.getDurability() + 1; stack.setDurability((short) Math.max(stack.getDurability() - hitsLeft, 0)); event.setCancelled(true); event.getItem().remove(); event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.5f, 1f); }
Example 15
Source File: UHPluginListener.java From KTP with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerPickupItem(PlayerPickupItemEvent ev) { if (ev.getItem().getItemStack().getType() == Material.GHAST_TEAR && ev.getPlayer().getGameMode().equals(GameMode.SURVIVAL)) ev.setCancelled(true); p.updatePlayerListName(ev.getPlayer()); }
Example 16
Source File: EffectEventHandlers.java From EliteMobs with GNU General Public License v3.0 | 4 votes |
@EventHandler public void playerPickupSafeguard(PlayerPickupItemEvent event) { if (EntityTracker.isItemVisualEffect(event.getItem())) event.setCancelled(true); }
Example 17
Source File: InventoryEvent.java From MCAuthenticator with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPickup(PlayerPickupItemEvent e){ if(!auth(e)) e.setCancelled(true); }
Example 18
Source File: EnvironmentControlListener.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGH) public void pickupItem(PlayerPickupItemEvent event) { event.setCancelled(true); }
Example 19
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); } } }
Example 20
Source File: UnitItemMaterial.java From civcraft with GNU General Public License v2.0 | 4 votes |
@Override public void onItemPickup(PlayerPickupItemEvent event) { // Should never be able to pick up these items. event.setCancelled(true); event.getItem().remove(); }