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

The following examples show how to use org.bukkit.event.player.PlayerDropItemEvent#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: WarpPowderListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
    Player player = event.getPlayer();
    if (event.isCancelled() || !Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();
    if (gPlayer.isSpectator) {
        return;
    }

    WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class);
    if (warpPowder != null) {
        if (warpPowder.getStack().equals(event.getItemDrop().getItemStack())) {
            event.setCancelled(true);
        }
    }
}
 
Example 2
Source File: WarpPowderListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
    Player player = event.getPlayer();
    if (event.isCancelled() || !Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();
    if (gPlayer.isSpectator) {
        return;
    }

    WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class);
    if (warpPowder != null) {
        if (warpPowder.getStack().equals(event.getItemDrop().getItemStack())) {
            event.setCancelled(true);
        }
    }
}
 
Example 3
Source File: ItemTransferListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
    if(this.ignoreNextDropEvent) {
        this.ignoreNextDropEvent = false;
    } else {
        // If the ignore flag is clear, this drop was caused by something other than
        // an inventory click (e.g. drop key, death, etc), so an event has not yet been fired
        int initialQuantity = event.getItemDrop().getItemStack().getAmount();
        ItemStack stack = event.getItemDrop().getItemStack();
        PlayerItemTransferEvent transferEvent = new PlayerItemTransferEvent(event, ItemTransferEvent.Type.DROP, event.getPlayer(),
                                                                            Optional.of(new InventorySlot(event.getPlayer().getInventory())),
                                                                            Optional.empty(),
                                                                            stack, event.getItemDrop(), initialQuantity,
                                                                            event.getPlayer().getOpenInventory().getCursor());
        this.callEvent(transferEvent);

        if(!transferEvent.isCancelled() && transferEvent.getQuantity() < initialQuantity) {
            int diff = initialQuantity - transferEvent.getQuantity();
            stack.setAmount(stack.getAmount() - diff);
            stack = stack.clone();
            stack.setAmount(diff);
            event.getPlayer().getInventory().addItem(stack);
        }
    }
}
 
Example 4
Source File: EnhancedItemListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Prevents enhanced item from dropping.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onItemDrop(PlayerDropItemEvent e) {
    Item droppedItem = e.getItemDrop();
    ItemStack DroppedItemStack = droppedItem.getItemStack();
    Player p = e.getPlayer();
    // Checks if the item is a bounded item
    if ((DroppedItemStack.hasItemMeta()) && (DroppedItemStack.getItemMeta()
            .getLore() != null)) {
        if (DroppedItemStack.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(
                SettingsManager.lang.getString("lore.untradeableLore")))) {
            e.setCancelled(true);
            Util.sendMessage(SettingsManager.lang.getString(
                    "messages.noDrop"), p);
        }
    }
}
 
Example 5
Source File: KitLoading.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void StopDrops(PlayerDropItemEvent event)
{
    Player player = event.getPlayer();
    Item item = event.getItemDrop();
    if(item != null)
    {
	    ItemStack stack = item.getItemStack();
	    if(stack != null)
	    {
		    if(KitUtils.isSoulbound(stack))
		    {
			    player.playSound(player.getLocation(), Sound.BLAZE_HIT, 1.0F, 0.3F);
			    event.getItemDrop().remove();
		    }
	    }
    }
}
 
Example 6
Source File: ItemsDroppedListener.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDrop(final PlayerDropItemEvent event) {

    final PlayerStat stat = PlayerStat.ITEMS_DROPPED;

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

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

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

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

}
 
Example 7
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDrop(PlayerDropItemEvent die) {
  Player p = die.getPlayer();
  Game g = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(p);
  if (g == null) {
    return;
  }

  if (g.getState() != GameState.WAITING) {
    if (g.isSpectator(p)) {
      die.setCancelled(true);
    }

    return;
  }

  die.setCancelled(true);
}
 
Example 8
Source File: WarpPowderListener.java    From BedwarsRel with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
  Player p = event.getPlayer();
  Game g = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(p);
  if (g == null) {
    return;
  }

  if (g.getState() == GameState.RUNNING
      && event.getItemDrop().getItemStack().getItemMeta().getDisplayName() != null
      && event.getItemDrop().getItemStack().getItemMeta().getDisplayName()
      .equals(BedwarsRel._l("ingame.specials.warp-powder.cancel"))) {
    event.setCancelled(true);
  }

}
 
Example 9
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDropItem(PlayerDropItemEvent event) {
    final Player player = event.getPlayer();
    GDCauseStackManager.getInstance().pushCause(player);
    if (!GDFlags.ITEM_DROP) {
        return;
    }

    final World world = event.getPlayer().getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }
    if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ITEM_DROP.getName(), player, world.getUID())) {
        return;
    }

    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_DROP.getName(), event.getItemDrop(), world.getUID())) {
        return;
    }

    final Location location = event.getItemDrop().getLocation();
    final GDClaim targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location);

    if (GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.ITEM_DROP, player, event.getItemDrop(), player, TrustTypes.ACCESSOR, true) == Tristate.FALSE) {
        event.setCancelled(true);
    }
}
 
Example 10
Source File: ItemTransferListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
  if (this.ignoreNextDropEvent) {
    this.ignoreNextDropEvent = false;
  } else {
    // If the ignore flag is clear, this drop was caused by something other than
    // an inventory click (e.g. drop key, death, etc), so an event has not yet been fired
    int initialQuantity = event.getItemDrop().getItemStack().getAmount();
    ItemStack stack = event.getItemDrop().getItemStack();
    PlayerItemTransferEvent transferEvent =
        new PlayerItemTransferEvent(
            event,
            ItemTransferEvent.Type.DROP,
            event.getPlayer(),
            event.getPlayer().getInventory(),
            null,
            null,
            null,
            stack,
            event.getItemDrop(),
            initialQuantity,
            event.getPlayer().getOpenInventory().getCursor());
    this.callEvent(transferEvent);

    if (!transferEvent.isCancelled() && transferEvent.getQuantity() < initialQuantity) {
      int diff = initialQuantity - transferEvent.getQuantity();
      stack.setAmount(stack.getAmount() - diff);
      stack = stack.clone();
      stack.setAmount(diff);
      event.getPlayer().getInventory().addItem(stack);
    }
  }
}
 
Example 11
Source File: LWCPlayerListener.java    From Modern-LWC with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDropItem(PlayerDropItemEvent event) {
    if (event.isCancelled() || !LWC.ENABLED) {
        return;
    }

    Player player = event.getPlayer();

    LWCDropItemEvent evt = new LWCDropItemEvent(player, event);
    plugin.getLWC().getModuleLoader().dispatchEvent(evt);

    if (evt.isCancelled()) {
        event.setCancelled(true);
    }
}
 
Example 12
Source File: ItemsListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerDropItem(PlayerDropItemEvent event) {
	Player player = event.getPlayer();
	ItemStack item = event.getItemDrop().getItemStack();
	GameManager gm = GameManager.getGameManager();

	if (gm.getGameState() == GameState.WAITING && GameItem.isGameItem(item)){
		event.setCancelled(true);
		return;
	}
}
 
Example 13
Source File: ItemDropEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@SuppressWarnings("unused")
public void onDropEvent(PlayerDropItemEvent event) {
    Player player = event.getPlayer();
    if (!plugin.getWorldManager().isSkyWorld(player.getWorld())) {
        return;
    }
    if (!visitorsCanDrop && !plugin.playerIsOnIsland(player) && !plugin.playerIsInSpawn(player)) {
        event.setCancelled(true);
        plugin.notifyPlayer(player, tr("\u00a7eVisitors can't drop items!"));
        return;
    }
    addDropInfo(player, event.getItemDrop().getItemStack());
}
 
Example 14
Source File: DPlayerListener.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDropItem(PlayerDropItemEvent event) {
    Player player = event.getPlayer();
    if (isCitizensNPC(player)) {
        return;
    }

    GlobalPlayer dPlayer = dPlayers.get(player);
    if (dPlayer == null) {
        return;
    }

    if (dPlayer instanceof EditPlayer && !config.getDropItems() && !DPermission.hasPermission(player, DPermission.INSECURE)) {
        event.setCancelled(true);
    }

    if (!(dPlayer instanceof DGamePlayer)) {
        return;
    }

    DGamePlayer gamePlayer = (DGamePlayer) dPlayer;

    DGroup dGroup = gamePlayer.getGroup();
    if (dGroup == null) {
        return;
    }

    if (!dGroup.isPlaying()) {
        event.setCancelled(true);
        return;
    }

    if (!gamePlayer.isReady()) {
        event.setCancelled(true);
        return;
    }

    for (ExItem item : dGroup.getDungeon().getRules().getState(GameRule.SECURE_OBJECTS)) {
        if (event.getItemDrop().getItemStack().isSimilar(item.toItemStack())) {
            event.setCancelled(true);
            MessageUtil.sendMessage(player, DMessage.ERROR_DROP.getMessage());
            return;
        }
    }
}