Java Code Examples for org.bukkit.event.player.PlayerPickupItemEvent#getPlayer()

The following examples show how to use org.bukkit.event.player.PlayerPickupItemEvent#getPlayer() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: ItemTransferListener.java    From PGM with GNU Affero General Public License v3.0 4 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(),
          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);
    }
  }
}