org.bukkit.event.player.PlayerPickupItemEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerPickupItemEvent. 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 vote down vote up
@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 vote down vote up
@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: ToolRepairMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void processRepair(PlayerPickupItemEvent event) {
  ItemStack pickup = event.getItem().getItemStack();

  if (this.toRepair.contains(pickup.getType())) {
    PlayerInventory inv = event.getPlayer().getInventory();
    for (ItemStack invStack :
        Iterables.concat(
            Arrays.asList(inv.getContents()), Arrays.asList(inv.getArmorContents()))) {
      if (this.canRepair(pickup, invStack)) {
        this.doRepair(event, invStack);
        return;
      }
    }
  }
}
 
Example #4
Source File: ItemsPickedUpListener.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerPickUp(final PlayerPickupItemEvent event) {

    final PlayerStat stat = PlayerStat.ITEMS_PICKED_UP;

    // Get player
    final Player player = event.getPlayer();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    PlayerStatSpecification specification = new ItemsPickedUpSpecification(player.getUniqueId(),
            event.getItem().getItemStack().getAmount(), player.getWorld().getName(),
            event.getItem().getItemStack().getType());

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());

}
 
Example #5
Source File: PlayerEvents2.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorPickup(final PlayerPickupItemEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    Island island = plugin.getGrid().getIslandAt(e.getItem().getLocation());
    if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_PICKUP)) 
            || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getItem().getLocation())) {
        return;
    }
    e.setCancelled(true);
}
 
Example #6
Source File: BonusGoodieManager.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR) 
public void OnPlayerPickupItem(PlayerPickupItemEvent event) {
	BonusGoodie goodie = CivGlobal.getBonusGoodie(event.getItem().getItemStack());
	
	if (goodie == null) {
		return;
	}
	
	try {
		goodie.setHolder(event.getPlayer());
		goodie.update(false);
		goodie.updateLore(event.getItem().getItemStack());
	} catch (CivException e) {
		e.printStackTrace();
	}
}
 
Example #7
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerPickup(PlayerPickupItemEvent event) {
	
	String name;
	boolean rare = false;
	if (event.getItem().getItemStack().getItemMeta().hasDisplayName()) {
		name = event.getItem().getItemStack().getItemMeta().getDisplayName();
		rare = true;
	} else {
		name = event.getItem().getItemStack().getType().name().replace("_", " ").toLowerCase();
	}
	
	Resident resident = CivGlobal.getResident(event.getPlayer());
	if (resident.getItemMode().equals("all")) {
		CivMessage.send(event.getPlayer(), CivColor.LightGreen+"You've picked up "+CivColor.LightPurple+event.getItem().getItemStack().getAmount()+" "+name);
	} else if (resident.getItemMode().equals("rare") && rare) {
		CivMessage.send(event.getPlayer(), CivColor.LightGreen+"You've picked up "+CivColor.LightPurple+event.getItem().getItemStack().getAmount()+" "+name);
	}
}
 
Example #8
Source File: EntityNewArrow.java    From Carbon-2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #9
Source File: EntityNewArrow.java    From Carbon-2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #10
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@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 #11
Source File: CustomItemManager.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void OnPlayerItemPickup(PlayerPickupItemEvent event) {
	ItemStack stack = event.getItem().getItemStack();

	if (LoreMaterial.isCustom(stack)) {
		LoreMaterial.getMaterial(stack).onItemPickup(event);
	}
}
 
Example #12
Source File: SpectatorEvents.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onSignChange(PlayerPickupItemEvent event) {
    Player player = event.getPlayer();
    if (GameManager.getInstance().isSpectator(player)) {
        event.setCancelled(true);
    }
}
 
Example #13
Source File: Events_v1_11_R1_Down.java    From Crazy-Crates with MIT License 5 votes vote down vote up
@EventHandler
public void onItemPickUp(PlayerPickupItemEvent e) {
    if (cc.isDisplayReward(e.getItem())) {
        e.setCancelled(true);
    }
    if (cc.isInOpeningList(e.getPlayer())) {
        e.setCancelled(true);
    }
}
 
Example #14
Source File: ListenerLegacyItemPickup.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@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 #15
Source File: Trade.java    From TradePlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPickup(PlayerPickupItemEvent event) {
  if (cancelled) return;
  Player player = event.getPlayer();
  if (player.equals(player1) || player.equals(player2)) {
    event.setCancelled(true);
  }
}
 
Example #16
Source File: GeneralEventHandler.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
@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 #17
Source File: PlayerPickupItem.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onPickup(PlayerPickupItemEvent event) {
    if (event.getPlayer().getWorld().getName().equals("world")) {
        event.setCancelled(true);
    } else {
        event.setCancelled(true);
    }
}
 
Example #18
Source File: CreativeModeListener.java    From ShopChest with MIT License 5 votes vote down vote up
@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 #19
Source File: EntityPickupItemListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@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 #20
Source File: UnitMaterial.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onItemPickup(PlayerPickupItemEvent event) {
			
	if(!validateUnitUse(event.getPlayer(), event.getItem().getItemStack())) {
		CivMessage.sendErrorNoRepeat(event.getPlayer(), "You cannot use this unit because it does not belong to your civilization.");
		event.setCancelled(true);
		return;
	}
	
	ConfigUnit unit = Unit.getPlayerUnit(event.getPlayer());
	if (unit != null) {
		CivMessage.sendErrorNoRepeat(event.getPlayer(), "Already a "+unit.name+" cannot pickup another unit item.");
		event.setCancelled(true);
	} else {
		// Reposition item to the last quickbar slot
		
		// Check that the inventory is not full, clear out the
		// the required slot, and then re-add what was in there.
		Inventory inv = event.getPlayer().getInventory();
		
		ItemStack lastSlot = inv.getItem(LAST_SLOT);
		if (lastSlot != null) {
			inv.setItem(LAST_SLOT, event.getItem().getItemStack());
			inv.addItem(lastSlot);
			event.getPlayer().updateInventory();
		} else {
			inv.setItem(LAST_SLOT, event.getItem().getItemStack());
		}
		
		
		this.onItemToPlayer(event.getPlayer(), event.getItem().getItemStack());
		event.getItem().remove();
		event.setCancelled(true);
	}
}
 
Example #21
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void PlayerPickupItemEvent(PlayerPickupItemEvent event) {
    if (event.getItem().hasMetadata("ce.Volley")) {
        event.getItem().remove();
        event.setCancelled(true);
    }
}
 
Example #22
Source File: WoolObjective.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onWoolPickup(PlayerPickupItemEvent event) {
    Player player = event.getPlayer();
    if (!this.complete && GameHandler.getGameHandler().getMatch().isRunning()) {
        try {
            if (event.getItem().getItemStack().getType() == Material.WOOL && ((Wool) event.getItem().getItemStack().getData()).getColor().equals(color)) {
                if (Teams.getTeamByPlayer(player).orNull() == team) {
                    boolean touchMessage = false;
                    if (!this.playersTouched.contains(player.getUniqueId())) {
                        this.playersTouched.add(player.getUniqueId());
                        if (this.show && !this.complete) {
                            Teams.getTeamChannel(Optional.of(team)).sendLocalizedMessage(new UnlocalizedChatMessage(ChatColor.WHITE + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_PICKED, team.getColor() + player.getName() + ChatColor.WHITE, MiscUtil.convertDyeColorToChatColor(color) + name.toUpperCase().replaceAll("_", " ") + ChatColor.WHITE, team.getCompleteName() + ChatColor.WHITE)));
                            for (Player player1 : Bukkit.getOnlinePlayers()) {
                                if (Teams.getTeamByPlayer(player1).isPresent() && Teams.getTeamByPlayer(player1).get().isObserver()) {
                                    player1.sendMessage(new UnlocalizedChatMessage(ChatColor.GRAY + "{0}", new LocalizedChatMessage(ChatConstant.UI_OBJECTIVE_PICKED_FOR, team.getColor() + player.getName() + ChatColor.GRAY, MiscUtil.convertDyeColorToChatColor(color) + name.toUpperCase().replaceAll("_", " ") + ChatColor.GRAY, team.getCompleteName() + ChatColor.GRAY)).getMessage(player1.getLocale()));
                                }
                            }
                            touchMessage = true;
                        }
                    }
                    if (!touched) touched = true;
                    ObjectiveTouchEvent touchEvent = new ObjectiveTouchEvent(this, player, touchMessage);
                    Bukkit.getServer().getPluginManager().callEvent(touchEvent);
                }
            }
        } catch (NullPointerException e) {
        }
    }
}
 
Example #23
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldHandleSimpleCancelableEvents() {
    withServiceMock(listenerService)
        .check(listener::onPlayerShear, PlayerShearEntityEvent.class)
        .check(listener::onPlayerFish, PlayerFishEvent.class)
        .check(listener::onPlayerBedEnter, PlayerBedEnterEvent.class)
        .check(listener::onPlayerDropItem, PlayerDropItemEvent.class)
        .check(listener::onPlayerHitPlayerEvent, EntityDamageByEntityEvent.class)
        .check(listener::onPlayerConsumeItem, PlayerItemConsumeEvent.class)
        .check(listener::onPlayerInteract, PlayerInteractEvent.class)
        .check(listener::onPlayerPickupItem, PlayerPickupItemEvent.class)
        .check(listener::onPlayerInteractEntity, PlayerInteractEntityEvent.class)
        .check(listener::onPlayerHeldItem, PlayerItemHeldEvent.class);
}
 
Example #24
Source File: PlayerPickupItem.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@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 #25
Source File: PlayerPickupItem.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
@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 #26
Source File: PlayerPickupCustomItem.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@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 #27
Source File: ProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerPickupProjectileEvent(PlayerPickupItemEvent event) {
  ItemStack itemStack = event.getItem().getItemStack();
  ProjectileCooldown projectileCooldown =
      this.getProjectileCooldown(
          this.match.getPlayer(event.getPlayer()), getProjectileDefinition(itemStack));
  if (projectileCooldown != null && projectileCooldown.isActive()) {
    projectileCooldown.setItemCoutdownName(itemStack);
  }
}
 
Example #28
Source File: ToolRepairMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #29
Source File: ItemTransferListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #30
Source File: ToolRepairMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
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.ITEM_PICKUP, 0.5f, 1f);
}