Java Code Examples for org.bukkit.entity.Item#remove()

The following examples show how to use org.bukkit.entity.Item#remove() . 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: GunGizmo.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    for(Item item : Bukkit.getWorlds().get(0).getEntitiesByClass(Item.class)) {
        if(item.getItemStack().getType() != Material.GHAST_TEAR) continue;
        UUID skip = Gizmos.gunGizmo.items.get(item);

        for(Entity entity : item.getNearbyEntities(0.5d, 0.5d, 0.5d)) {
            if(entity instanceof Player && !entity.getUniqueId().equals(skip)) {
                Player player = (Player) entity;
                if(player.hasPermission("gizmo.immunity")) continue;
                player.damage(0d, item);
                Gizmos.gunGizmo.gifts.add(player.getUniqueId());
                item.remove();
                break;
            }
        }

        if(item.getTicksLived() >= 6000) item.remove();
    }
}
 
Example 2
Source File: AncientAltarTask.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private void checkPedestal(Block pedestal) {
    Item item = listener.findItem(pedestal);

    if (item == null || itemLock.remove(item) == null) {
        abort();
    }
    else {
        particleLocations.add(pedestal.getLocation().add(0.5, 1.5, 0.5));
        items.add(listener.fixItemStack(item.getItemStack(), item.getCustomName()));
        pedestal.getWorld().playSound(pedestal.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 2F);

        dropLocation.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, pedestal.getLocation().add(0.5, 1.5, 0.5), 16, 0.3F, 0.2F, 0.3F);
        dropLocation.getWorld().spawnParticle(Particle.CRIT_MAGIC, pedestal.getLocation().add(0.5, 1.5, 0.5), 8, 0.3F, 0.2F, 0.3F);

        itemLock.remove(item);
        item.remove();
        item.removeMetadata("no_pickup", SlimefunPlugin.instance);
    }
}
 
Example 3
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCivilianDropItem(PlayerDropItemEvent event) {
    Item item = event.getItemDrop();
    if (checkDroppedItem(item.getItemStack(), event.getPlayer())) {
        item.remove();
    }
}
 
Example 4
Source File: AncientAltarListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private void usePedestal(Block pedestal, Player p) {
    if (altarsInUse.contains(pedestal.getLocation())) {
        return;
    }

    // getting the currently placed item
    Item stack = findItem(pedestal);

    if (stack == null) {
        // Check if the Item in hand is valid
        if (p.getInventory().getItemInMainHand().getType() != Material.AIR) {
            // Check for pedestal obstructions
            if (pedestal.getRelative(0, 1, 0).getType() != Material.AIR) {
                SlimefunPlugin.getLocalization().sendMessage(p, "machines.ANCIENT_PEDESTAL.obstructed", true);
                return;
            }

            // place the item onto the pedestal
            insertItem(p, pedestal);
        }
    }
    else if (!removedItems.contains(stack.getUniqueId())) {
        UUID uuid = stack.getUniqueId();
        removedItems.add(uuid);

        Slimefun.runSync(() -> removedItems.remove(uuid), 30L);

        stack.remove();
        p.getInventory().addItem(fixItemStack(stack.getItemStack(), stack.getCustomName()));
        p.playSound(pedestal.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1F, 1F);
    }
}
 
Example 5
Source File: ItemsCollector.java    From Minepacks with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run()
{
	for(Player player : Bukkit.getServer().getOnlinePlayers())
	{
		if(plugin.isDisabled(player) != WorldBlacklistMode.None) return;
		if(player.getInventory().firstEmpty() == -1 && player.hasPermission(Permissions.USE) && player.hasPermission(Permissions.FULL_PICKUP))
		{
			// Only check loaded backpacks (loading them would take to much time for a repeating task, the backpack will be loaded async soon enough)
			Backpack backpack = (Backpack) plugin.getBackpackCachedOnly(player);
			if(backpack == null)
			{
				continue;
			}
			List<Entity> entities = player.getNearbyEntities(radius, radius, radius);
			for(Entity entity : entities)
			{
				if(entity instanceof Item)
				{
					Item item = (Item) entity;
					if(!item.isDead() && item.getPickupDelay() <= 0)
					{
						if(itemFilter != null && itemFilter.isItemBlocked(item.getItemStack())) continue;
						Map<Integer, ItemStack> full = backpack.addItems(item.getItemStack());
						backpack.setChanged();
						if(!full.isEmpty())
						{
							item.setItemStack(full.get(0));
						}
						else
						{
							item.remove();
						}
					}
				}
			}
		}
	}
}
 
Example 6
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 7
Source File: DropTransferModule.java    From Modern-LWC with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onDropItem(LWCDropItemEvent event) {
    Player bPlayer = event.getPlayer();
    Item item = event.getEvent().getItemDrop();
    ItemStack itemStack = item.getItemStack();

    LWCPlayer player = lwc.wrapPlayer(bPlayer);
    int protectionId = getPlayerDropTransferTarget(player);

    if (protectionId == -1) {
        return;
    }

    if (!isPlayerDropTransferring(player)) {
        return;
    }

    Protection protection = lwc.getPhysicalDatabase().loadProtection(protectionId);

    if (protection == null) {
        lwc.sendLocale(player, "lwc.nolongerexists");
        player.disableMode(player.getMode("dropTransfer"));
        return;
    }

    // load the world and the inventory
    World world = player.getServer().getWorld(protection.getWorld());

    if (world == null) {
        lwc.sendLocale(player, "lwc.invalidworld");
        player.disableMode(player.getMode("dropTransfer"));
        return;
    }

    // Don't allow them to transfer items across worlds
    if (bPlayer.getWorld() != world && !lwc.getConfiguration().getBoolean("modes.droptransfer.crossWorld", false)) {
        lwc.sendLocale(player, "lwc.dropxfer.acrossworlds");
        player.disableMode(player.getMode("dropTransfer"));
        return;
    }

    Block block = world.getBlockAt(protection.getX(), protection.getY(), protection.getZ());
    Map<Integer, ItemStack> remaining = lwc.depositItems(block, itemStack);

    if (remaining == null || remaining.size() > 0) {
        lwc.sendLocale(player, "lwc.dropxfer.chestfull");
        event.getEvent().setCancelled(true);
    }

    bPlayer.updateInventory(); // if they're in the chest and dropping items, this is required
    item.remove();
}
 
Example 8
Source File: VisualItemRemover.java    From EliteMobs with GNU General Public License v3.0 3 votes vote down vote up
public static void removeItems(Object[][] multiDimensionalTrailTracker) {

        for (int i = 0; i < multiDimensionalTrailTracker.length; i++)
            for (int j = 0; j < multiDimensionalTrailTracker[i].length; j++) {

                if (!(multiDimensionalTrailTracker[i][j] instanceof Item)) continue;
                Item item = (Item) multiDimensionalTrailTracker[i][j];
                item.remove();
                EntityTracker.unregisterItemVisualEffects(item);

            }

    }