下面列出了org.bukkit.inventory.Inventory#remove ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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());
}
}
}
}
@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);
}
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);
}
}
}
}
}
@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);
}
}
}
@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));
}
}
}
}
}
}
}
/**
* 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;
}
}
}