Java Code Examples for org.bukkit.inventory.Inventory#remove()

The following examples show how to use org.bukkit.inventory.Inventory#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: BonusGoodieManager.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR) 
public void OnPlayerJoinEvent(PlayerJoinEvent event) {
	Inventory inv = event.getPlayer().getInventory();
	
	for (ConfigTradeGood good : CivSettings.goods.values()) {
		for (Entry<Integer, ? extends ItemStack> itemEntry : inv.all(ItemManager.getMaterial(good.material)).entrySet()) {
			if (good.material_data != ItemManager.getData(itemEntry.getValue())) {
				continue;
			}
			
			BonusGoodie goodie = CivGlobal.getBonusGoodie(itemEntry.getValue());
			if (goodie != null) {
				inv.remove(itemEntry.getValue());				
			}
		}
	}
}
 
Example 2
Source File: FlagTrackingSpectate.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onSpectateLeave(FlagSpectate.SpectateLeaveEvent event) {
	Player player = event.getPlayer().getBukkitPlayer();
	Inventory inventory = player.getInventory();
	
	for (ItemStack stack : inventory.getContents()) {
		if (stack == null) {
			continue;
		}
		
		MetadatableItemStack metadatable = new MetadatableItemStack(stack);
		if (!metadatable.hasItemMeta() || !metadatable.getItemMeta().hasLore() || !metadatable.hasMetadata(TRACKER_KEY)) {
			continue;
		}
		
		inventory.remove(stack);
	}
	
	player.updateInventory();
	tracking.remove(player);
}
 
Example 3
Source File: UnitMaterial.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
protected void removeChildren(Inventory inv) {
	for (ItemStack stack : inv.getContents()) {
		if (stack != null) {
		//	CustomItemStack is = new CustomItemStack(stack);
			LoreMaterial material = LoreMaterial.getMaterial(stack);
			if (material != null && (material instanceof UnitItemMaterial)) {
				UnitItemMaterial umat = (UnitItemMaterial)material;
				if (umat.getParent() == this) {
					inv.remove(stack);
				}
			}
		}
	}
}
 
Example 4
Source File: JoinItems.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private void removeItem(CustomItem item, Inventory inventory) {
    for (ItemStack content : inventory.getContents()) {
        if (content == null || (content.getType() != item.getMaterial())) {
            continue;
        }
        NBTItem nbtItem = new NBTItem(content);
        if (nbtItem.hasKey("HubBasics")
                && item.getId().equalsIgnoreCase(nbtItem.getString("HubBasics"))) {
            inventory.remove(content);
        }
    }
}
 
Example 5
Source File: Tnt.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityExplode(EntityExplodeEvent event) {
    if (GameHandler.getGameHandler().getMatch().isRunning() && event.getEntity() instanceof TNTPrimed) {
        if (!blockDamage) {
            event.blockList().clear();
        } else if (yield != 0.3){
            event.setYield((float)yield);
        }
        UUID player = TntTracker.getWhoPlaced(event.getEntity());
        for (Block block : event.blockList()) {
            if (block.getState() instanceof Dispenser) {
                Inventory inventory = ((Dispenser) block.getState()).getInventory();
                Location location = block.getLocation();
                double tntCount = 0;
                for (ItemStack itemstack : inventory.getContents()) {
                    if (itemstack != null && itemstack.getType() == Material.TNT) tntCount += itemstack.getAmount() * multiplier;
                    if (tntCount >= limit) {
                        tntCount = limit;
                        break;
                    }
                }
                inventory.remove(Material.TNT);
                if (tntCount > 0) {
                    Random random = new Random();
                    for (double i = tntCount; i > 0; i--) {
                        TNTPrimed tnt = event.getWorld().spawn(location, TNTPrimed.class);
                        Vector velocity = new Vector((1.5 * random.nextDouble()) - 0.75, (1.5 * random.nextDouble()) - 0.75, (1.5 * random.nextDouble()) - 0.75);
                        tnt.setVelocity(velocity);
                        tnt.setFuseTicks(random.nextInt(10) + 10);
                        if (player != null) {
                            tnt.setMetadata("source", new FixedMetadataValue(Cardinal.getInstance(), player));
                        }
                    }
                }
            }
        }
    }
}
 
Example 6
Source File: Utils.java    From Shopkeepers with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Removes the specified amount of items which match the specified attributes from the given inventory.
 * 
 * @param inv
 * @param type
 *            The item type.
 * @param data
 *            The data value/durability. If -1 is is ignored.
 * @param displayName
 *            The displayName. If null it is ignored.
 * @param lore
 *            The item lore. If null or empty it is ignored.
 * @param ignoreNameAndLore
 * @param amount
 */
public static void removeItemsFromInventory(Inventory inv, Material type, short data, String displayName, List<String> lore, int amount) {
	for (ItemStack is : inv.getContents()) {
		if (!Utils.isSimilar(is, type, data, displayName, lore)) continue;
		int newamount = is.getAmount() - amount;
		if (newamount > 0) {
			is.setAmount(newamount);
			break;
		} else {
			inv.remove(is);
			amount = -newamount;
			if (amount == 0) break;
		}
	}
}