org.bukkit.event.entity.EntityPickupItemEvent Java Examples

The following examples show how to use org.bukkit.event.entity.EntityPickupItemEvent. 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: ItemDropEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
@SuppressWarnings("unused")
public void onPickupEvent(EntityPickupItemEvent event) {
    if (!(event.getEntity() instanceof Player)) {
        return;
    }
    Player player = (Player) event.getEntity();
    if (event.isCancelled() || !plugin.getWorldManager().isSkyWorld(player.getWorld())) {
        clearDropInfo(event.getItem());
        return;
    }
    if (wasDroppedBy(player, event) || player.hasPermission("usb.mod.bypassprotection") || plugin.playerIsOnIsland(player) || plugin.playerIsInSpawn(player)) {
        clearDropInfo(event.getItem());
        return; // Allowed
    }
    // You are on another's island, and the stuff dropped weren't yours.
    event.setCancelled(true);
    plugin.notifyPlayer(player, tr("You cannot pick up other players' loot when you are a visitor!"));
}
 
Example #2
Source File: PlayerEvents3.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 EntityPickupItemEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (e.getEntity() instanceof Player) {
        Player player = (Player)e.getEntity();
        if (!IslandGuard.inWorld(player)) {
            return;
        }
        Island island = plugin.getGrid().getIslandAt(e.getItem().getLocation());
        if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_PICKUP)) 
                || player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")
                || plugin.getGrid().locationIsOnIsland(player, e.getItem().getLocation())) {
            return;
        }
        e.setCancelled(true);
    }
}
 
Example #3
Source File: Player112Listener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPickup(EntityPickupItemEvent event) {
    if (!(event.getEntity() instanceof Player)) {
        return;
    }

    PlayerListener.onItemPickup((Player) event.getEntity(), event.getItem(), event);
}
 
Example #4
Source File: Player112Listener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPickup(EntityPickupItemEvent event) {
    if (!(event.getEntity() instanceof Player)) {
        return;
    }

    PlayerListener.onItemPickup((Player) event.getEntity(), event.getItem(), event);
}
 
Example #5
Source File: GuiListener.java    From IF with The Unlicense 5 votes vote down vote up
/**
 * Handles users picking up items while their bottom inventory is in use.
 *
 * @param event the event fired when an entity picks up an item
 * @since 0.6.1
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onEntityPickupItem(@NotNull EntityPickupItemEvent event) {
    if (!(event.getEntity() instanceof HumanEntity)) {
        return;
    }

    InventoryHolder holder = ((HumanEntity) event.getEntity()).getOpenInventory().getTopInventory().getHolder();

    if (!(holder instanceof Gui)) {
        return;
    }

    Gui gui = (Gui) holder;

    if (gui.getState() != Gui.State.BOTTOM) {
        return;
    }

    int leftOver = gui.getHumanEntityCache().add((HumanEntity) event.getEntity(), event.getItem().getItemStack());

    if (leftOver == 0) {
        event.getItem().remove();
    } else {
        ItemStack itemStack = event.getItem().getItemStack();

        itemStack.setAmount(leftOver);

        event.getItem().setItemStack(itemStack);
    }

    event.setCancelled(true);
}
 
Example #6
Source File: Events_v1_12_R1_Up.java    From Crazy-Crates with MIT License 5 votes vote down vote up
@EventHandler
public void onItemPickUp(EntityPickupItemEvent e) {
    if (cc.isDisplayReward(e.getItem())) {
        e.setCancelled(true);
    } else {
        if (e.getEntity() instanceof Player) {
            Player player = (Player) e.getEntity();
            if (cc.isInOpeningList(player)) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example #7
Source File: LootProtectListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPickup(EntityPickupItemEvent e) {
    if (plugin.cfg.lootProtectMode == LootProtectMode.OFF || !(e.getEntity() instanceof Player))
        return;
    Player p = (Player) e.getEntity();
    if (!p.isSneaking() && bypassVanillaPlayer.get(p.getUniqueId()) == VanillaStrategy.REJECT) {
        ItemStack item = e.getItem().getItemStack();
        if (!(item.hasItemMeta() && item.getItemMeta().hasLore())) {
            e.setCancelled(true);
        }
    }
}
 
Example #8
Source File: ListenerNewItemPickup.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(EntityPickupItemEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("items.prevent-item-pickup")) return;

    LivingEntity entity = e.getEntity();
    if(!(entity instanceof Player)) return;

    Player player = (Player) entity;
    ICombatManager combatManager = this.plugin.getCombatManager();
    if(!combatManager.isInCombat(player)) return;

    e.setCancelled(true);
    sendMessage(player);
}
 
Example #9
Source File: ItemDropEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private boolean wasDroppedBy(Player player, EntityPickupItemEvent event) {
    ItemStack itemStack = event.getItem().getItemStack();
    ItemMeta meta = itemStack.getItemMeta();
    if (meta != null) {
        List<String> lore = meta.getLore();
        if (lore != null && !lore.isEmpty()) {
            String lastLine = lore.get(lore.size() - 1);
            return lastLine.equalsIgnoreCase(tr("Owner: {0}", player.getName()));
        }
    }
    return false;
}
 
Example #10
Source File: ItemPickupListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityPickup(EntityPickupItemEvent e) {
    if (SlimefunUtils.hasNoPickupFlag(e.getItem())) {
        e.setCancelled(true);
    }
    else if (e.getItem().getItemStack().hasItemMeta() && e.getItem().getItemStack().getItemMeta().hasDisplayName() && e.getItem().getItemStack().getItemMeta().getDisplayName().startsWith(ITEM_PREFIX)) {
        e.setCancelled(true);
        e.getItem().remove();
    }
}
 
Example #11
Source File: CustomItemListener.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
private void playerPickupItem(EntityPickupItemEvent event) {
	CustomItem customItem = CustomItemManager.getCustomItem(event.getItem().getItemStack());
	Entity entity = event.getEntity();
	if (entity instanceof Player && verifyCustomItem(customItem, (Player) entity, true)) {
		customItem.onPickup(event);
	}
}
 
Example #12
Source File: KingsCrown.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPickup(EntityPickupItemEvent event) {
	Player player = ((Player) event.getEntity());
	PlayerInventory inv = player.getInventory();
	ItemStack lastHelmet = inv.getHelmet();
	if (lastHelmet == null || inv.addItem(lastHelmet).size() == 0) {
		inv.setHelmet(event.getItem().getItemStack());
		event.getItem().remove();
		event.setCancelled(true);
		if (shouldBroadcastMessage()) {
			UtilsMc.broadcastToWorld(player.getWorld(), MessageFormat.format("§6{0} §fhas been crown §6King§f!", player.getName(), getName()));
		}
	}
}
 
Example #13
Source File: SimpleMine.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPickup(EntityPickupItemEvent event) {
	event.setCancelled(true);
	Item item = event.getItem();
	ItemStack stack = item.getItemStack();
	Location loc = item.getLocation();
	item.remove();
	loc.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 4f + 0.2f*stack.getAmount(), false, false);
}
 
Example #14
Source File: DropProtectListener.java    From NyaaUtils with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPickup(EntityPickupItemEvent e) {
    if (plugin.cfg.dropProtectMode == DropProtectMode.OFF) return;
    items.invalidate(e.getItem().getEntityId());
}
 
Example #15
Source File: CustomItem.java    From NBTEditor with GNU General Public License v3.0 votes vote down vote up
public void onPickup(EntityPickupItemEvent event) { }