当前位置: 首页>>代码示例>>Java>>正文


Java ItemStack.setAmount方法代码示例

本文整理汇总了Java中org.bukkit.inventory.ItemStack.setAmount方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.setAmount方法的具体用法?Java ItemStack.setAmount怎么用?Java ItemStack.setAmount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.inventory.ItemStack的用法示例。


在下文中一共展示了ItemStack.setAmount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: giveModularized

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private static void giveModularized(Player p, int amount, ItemStack base, String name) {
    if (amount <= 0)
        return;
    ItemStack item = base.clone();
    item.setAmount(amount);
    HashMap<Integer, ItemStack> remaining = p.getInventory().addItem(item);
    if (!remaining.isEmpty()) {
        int extra = 0;
        for (Entry<Integer, ItemStack> e : remaining.entrySet()) {
            int remainingAmount = e.getValue().getAmount();
            extra += remainingAmount;
            while (remainingAmount > 0) {
                ItemStack temp = base.clone();
                if (remainingAmount > temp.getMaxStackSize())
                    temp.setAmount(temp.getMaxStackSize());
                else
                    temp.setAmount(remainingAmount);
                remainingAmount -= temp.getAmount();
                p.getWorld().dropItem(p.getEyeLocation(), temp);
            }
        }
        p.sendMessage(ChatColor.RED + "You ran out of inventory space for " + name + " you received.");
        p.sendMessage(ChatColor.RED.toString() + extra + " extra " + name + " were dropped around you.");
    }
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:26,代码来源:ShardManager.java

示例2: addItem

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public void addItem( ItemStack itemStack ) {
    if( itemStack == null ) {
        return;
    }
    this.lock.writeLock().lock();
    try {
        for( int i = 0; i < items.length; i++ ) {
            ItemStack t = items[ i ];
            if( t == null ) {
                setItem0( i, itemStack );
                return;
            } else if( t.getType() == itemStack.getType() && t.getDurability() == itemStack.getDurability() && t.getAmount() + itemStack.getAmount() <= 64 ) {
                t.setAmount( t.getAmount() + itemStack.getAmount() );
                setItem0( i, t );
                return;
            }
        }
    } finally {
        this.lock.writeLock().unlock();
    }
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:22,代码来源:FlexInventory.java

示例3: takeItem

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean takeItem(Inventory inv, ItemStack item, int takeAmount) {
    Set<Integer> removeSlots = new HashSet<>(takeAmount);
    for (int i = 0; i < inv.getSize(); i++) {
        ItemStack elemItem = inv.getItem(i);
        if (elemItem == null || elemItem.getType() == Material.AIR
                || !elemItem.isSimilar(item))
            continue;

        int amount = elemItem.getAmount();
        if (takeAmount > amount) {
            takeAmount -= amount;
            removeSlots.add(i);
        } else {
            if (takeAmount < amount) {
                elemItem.setAmount(amount - takeAmount);
            } else {
                removeSlots.add(i);
            }
            removeSlots.forEach(inv::clear);
            return true;
        }
    }
    return false;
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:25,代码来源:Inventories.java

示例4: addItem_PartiallyFilled_AddsOneStack_HalfAdded

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Test
public void addItem_PartiallyFilled_AddsOneStack_HalfAdded()
{
	ItemStack filler = new ItemStack(Material.COBBLESTONE, 1);
	for (int i = 2; i < inventory.getSize(); i++)
	{
		inventory.setItem(i, filler);
	}
	ItemStack preset = new ItemStack(Material.DIRT, 48);
	inventory.setItem(0, preset);
	inventory.setItem(2, preset);
	preset.setAmount(64);
	inventory.setItem(1, preset);

	ItemStack store = new ItemStack(Material.DIRT, 64);
	ItemStack remaining = inventory.addItem(store);
	assertNotNull(remaining);
	assertEquals(32, remaining.getAmount());
}
 
开发者ID:seeseemelk,项目名称:MockBukkit,代码行数:20,代码来源:PlayerInventoryMockTest.java

示例5: refillOneWoolPerContainer

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Repeatable(interval = @Time(seconds = 30), scope = MatchScope.RUNNING)
public void refillOneWoolPerContainer() {
    if(!Config.Wool.autoRefillWoolChests()) return;

    for(Entry<Inventory, Map<Integer, ItemStack>> chest : this.woolChests.entrySet()) {
        Inventory inv = chest.getKey();
        for(Entry<Integer, ItemStack> slotEntry : chest.getValue().entrySet()) {
            int slot = slotEntry.getKey();
            ItemStack wool = slotEntry.getValue();
            ItemStack stack = inv.getItem(slotEntry.getKey());

            if(stack == null) {
                stack = wool.clone();
                stack.setAmount(1);
                inv.setItem(slot, stack);
                break;
            } else if(stack.isSimilar(wool) && stack.getAmount() < wool.getAmount()) {
                stack.setAmount(stack.getAmount() + 1);
                inv.setItem(slot, stack);
                break;
            }
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:25,代码来源:WoolMatchModule.java

示例6: extractItem

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack extractItem(WrappedDirection extractDirection, int extractAmount, List<ItemData> filterItems,
		FilteringMode filteringMode) {
	if (!cachedChunk.isLoaded()) {
		return null;
	}
	if (isInvLocked(cachedInvHolder)) {
		return null;
	}
	ItemStack takenIs = null;
	for (int i = 0; i < cachedInv.getSize(); i++) {
		if (cachedInv.getItem(i) != null) {
			int amountBefore = takenIs != null ? takenIs.getAmount() : 0;
			if (takenIs == null) {
				if (new ItemData(cachedInv.getItem(i)).checkFilter(filterItems, filteringMode)) {
					takenIs = cachedInv.getItem(i).clone();
					takenIs.setAmount(Math.min(extractAmount, takenIs.getAmount()));
				} else {
					continue;
				}
			} else if (takenIs.isSimilar(cachedInv.getItem(i))) {
				takenIs.setAmount(Math.min(extractAmount, amountBefore + cachedInv.getItem(i).getAmount()));
			}
			ItemStack invItem = cachedInv.getItem(i);
			cachedInv.setItem(i, InventoryUtils.changeAmount(invItem, -(takenIs.getAmount() - amountBefore)));
		}
	}
	if (takenIs != null) {
		block.getState().update();
	}
	return takenIs;
}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:33,代码来源:SimpleInventoryContainer.java

示例7: onArcherSpeedClick

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=false, priority=EventPriority.HIGH)
public void onArcherSpeedClick(PlayerInteractEvent event)
{
    Action action = event.getAction();
    if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) &&
            (event.hasItem()) && (event.getItem().getType() == Material.SUGAR))
    {
        if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) {
            return;
        }
        Player player = event.getPlayer();
        UUID uuid = player.getUniqueId();
        long timestamp = this.archerSpeedCooldowns.get(uuid);
        long millis = System.currentTimeMillis();
        long remaining = timestamp == this.archerSpeedCooldowns.getNoEntryValue() ? -1L : timestamp - millis;
        if (remaining > 0L)
        {
            player.sendMessage(ChatColor.RED + "Cannot use Speed Boost for another " + DurationFormatUtils.formatDurationWords(remaining, true, true) + ".");
        }
        else
        {
            ItemStack stack = player.getItemInHand();
            if (stack.getAmount() == 1) {
                player.setItemInHand(new ItemStack(Material.AIR, 1));
            } else {
                stack.setAmount(stack.getAmount() - 1);
            }
            player.sendMessage(ChatColor.GREEN + "Speed 4 activated for 7 seconds.");

            this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_SPEED_EFFECT);
            this.archerSpeedCooldowns.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + ARCHER_SPEED_COOLDOWN_DELAY);
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:35,代码来源:ArcherClass.java

示例8: onCommand

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public boolean onCommand(CommandSender cs, String[] args) {

	if (!cs.hasPermission("transportpipes.creative")) {
		return false;
	}

	if (cs instanceof Player) {
		Inventory inv = Bukkit.createInventory(null, 9 * 3, LocConf.load(LocConf.CREATIVE_TITLE));

		int i = 0;
		List<ItemStack> ductItems = DuctItemUtils.getAllDuctItems();
		for (ItemStack is : ductItems) {
			ItemStack clonedIs = is.clone();
			clonedIs.setAmount(16);
			inv.setItem(i, clonedIs);
			i++;
		}
		inv.setItem(i++, DuctItemUtils.getClonedWrenchItem());

		((Player) cs).openInventory(inv);
	} else {
		cs.sendMessage("§cYou're not a player!");
	}

	return true;
}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:28,代码来源:CreativeCommandExecutor.java

示例9: onConsume

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerInteractEvent e) {
    SurvivalUser u = PASurvival.getPlayer(e.getPlayer());

    if (e.getItem() == null) return;

    if (e.getItem().getType() == Material.BREAD && e.getItem().hasItemMeta()) {
        if (e.getItem().getEnchantments().keySet().contains(Enchantment.ARROW_DAMAGE)) {
            String name = ChatColor.stripColor(e.getItem().getItemMeta().getDisplayName());
            ItemStack i = u.getPlayer().getInventory().getItemInMainHand();

            if (u.getPlayer().getFoodLevel() >= 20) return;

            if (name.equalsIgnoreCase("Bocadillo de Jamón")) {
                if (u.getPlayer().getFoodLevel() + 5 > 20) {
                    u.getPlayer().setFoodLevel(20);
                } else {
                    u.getPlayer().setFoodLevel(u.getPlayer().getFoodLevel() + 5);
                }
                u.getPlayer().setSaturation(3F);
                i.setAmount(i.getAmount() - 1);
                u.getPlayer().getInventory().setItemInMainHand(i);
            }

            if (name.equalsIgnoreCase("Hamburguesa Artesana")) {
                if (u.getPlayer().getFoodLevel() + 6 > 20) {
                    u.getPlayer().setFoodLevel(20);
                } else {
                    u.getPlayer().setFoodLevel(u.getPlayer().getFoodLevel() + 6);
                }
                u.getPlayer().setSaturation(4F);
                i.setAmount(i.getAmount() - 1);
                u.getPlayer().getInventory().setItemInMainHand(i);
            }
        }
    }
}
 
开发者ID:cadox8,项目名称:PA,代码行数:38,代码来源:PlayerEvents.java

示例10: saveGoldenPipeInv

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void saveGoldenPipeInv(Player p, Inventory inv) {
	if (inv != null && goldenPipeInventories.containsValue(inv)) {
		GoldenPipe pipe = null;
		//get pipe with inventory
		for (GoldenPipe gp : goldenPipeInventories.keySet()) {
			if (goldenPipeInventories.get(gp).equals(inv)) {
				pipe = gp;
				break;
			}
		}
		//cache new items in golden pipe
		linefor: for (int line = 0; line < 6; line++) {
			ItemData[] items = pipe.getFilteringItems(WrappedDirection.fromID(line));
			int scrollValue = scrollValues.get(pipe).containsKey(line) ? scrollValues.get(pipe).get(line) : 0;
			for (int i = 2; i < 8; i++) {
				ItemStack is = inv.getItem(line * 9 + i);
				//make sure the glass pane won't be saved
				if (!InventoryUtils.isGlassItemOrBarrier(is)) {
					if (is != null && is.getAmount() > 1) {
						ItemStack drop = is.clone();
						drop.setAmount(is.getAmount() - 1);
						p.getWorld().dropItem(p.getLocation(), drop);
						is.setAmount(1);
					}
					items[scrollValue] = is != null ? new ItemData(is) : null;
				} else {
					//skip this save-sequenz if this line is not available (not a pipe or block as neighbor)
					continue linefor;
				}
				scrollValue++;
			}
		}
	}
}
 
开发者ID:RoboTricker,项目名称:Transport-Pipes,代码行数:35,代码来源:GoldenPipeInv.java

示例11: onInteract

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler
public void onInteract(final PlayerInteractEvent event) {
    if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) return;

    ItemStack item = event.getItem();
    if (item instanceof PlayerheadItemStack) {
        event.setCancelled(true);
        Player player = event.getPlayer();

        //Use the item
        if (item.getAmount() > 1) item.setAmount(item.getAmount() - 1);
        else player.getInventory().remove(item);

        MainConfiguration config = UHC.getInstance().getMainConfig();

        //Give effects & crap
        PlayerheadItemStack playerhead = (PlayerheadItemStack) item;
        boolean golden = playerhead.isGolden();
        player.sendMessage(colour("&aYou ate " + playerhead.getFrom() + "'s playerhead!"));

        int regenDuration = golden ? config.getGoldenHeadRegenerationDuration() : config.getHeadRegenerationDuration();
        int regenAmpf = golden ? config.getGoldenHeadRegenerationAmplifier() : config.getHeadRegenerationAmplifier();
        int absorpDuration = golden ? config.getGoldenHeadAbsorptionDuration() : config.getHeadAbsorptionDuration();
        int absorpAmpf = golden ? config.getGoldenHeadAbsorptionAmplifier() : config.getHeadAbsorptionAmplifier();

        player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, regenDuration, regenAmpf, false, true));
        player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, absorpDuration, absorpAmpf, false, true));
    }
}
 
开发者ID:Project-Coalesce,项目名称:UHC,代码行数:30,代码来源:HeadEatHandler.java

示例12: removeAmmo

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public void removeAmmo(TWDPlayer player, Weapon weapon, int bullets){
    for (ItemStack i : player.getPlayer().getInventory().getContents()){
        if (i == null || !(i.equals(weapon.getAmmo().toItemStack()))) return;
        if (i.getAmount() > bullets){
            i.setAmount(i.getAmount() - bullets);
            return;
        }
        if (i.getAmount() == bullets){
            player.getPlayer().getInventory().remove(weapon.getAmmo().toItemStack());
            return;
        }
    }
}
 
开发者ID:cadox8,项目名称:WC,代码行数:14,代码来源:Ammo.java

示例13: removeItem

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void removeItem(Player p){
    ItemStack i = p.getInventory().getItemInMainHand();
    int amount = i.getAmount();

    if (amount == 1){
        i.setType(Material.AIR);
    } else {
        i.setAmount(amount - 1);
    }
}
 
开发者ID:cadox8,项目名称:WC,代码行数:11,代码来源:WorldInteract.java

示例14: matches

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public boolean matches(ItemStack anotherItem) {
    ItemStack base = itemTemplate.clone();
    ItemStack given = anotherItem.clone();
    base.setAmount(1);
    given.setAmount(1);
    if (requireExact) return base.equals(given);
    if (!base.getType().equals(given.getType())) return false;

    if (repairCostMatch == MatchingMode.EXACT &&
            base.getItemMeta() instanceof Repairable && given.getItemMeta() instanceof Repairable &&
            !(((Repairable) given.getItemMeta()).getRepairCost() == ((Repairable) base.getItemMeta()).getRepairCost())) {
        return false;
    }

    int baseDamage = base.getDurability();
    int givenDamage = given.getDurability();
    if (minDamageValue == -2 && givenDamage < baseDamage) return false;
    if (minDamageValue >= 0 && givenDamage < minDamageValue) return false;
    if (maxDamageValue == -2 && givenDamage > baseDamage) return false;
    if (maxDamageValue >= 0 && givenDamage > maxDamageValue) return false;

    String baseDisplay = getDisplayName(base);
    String givenDisplay = getDisplayName(given);
    if (nameMatch == MatchingMode.EXACT && !baseDisplay.equals(givenDisplay)) return false;
    if (nameMatch == MatchingMode.EXACT_TEXT && !ChatColor.stripColor(baseDisplay).equals(ChatColor.stripColor(givenDisplay)))
        return false;
    if (nameMatch == MatchingMode.CONTAINS && !givenDisplay.contains(baseDisplay)) return false;
    if (nameMatch == MatchingMode.CONTAINS_TEXT && !ChatColor.stripColor(givenDisplay).contains(ChatColor.stripColor(baseDisplay)))
        return false;

    Map<Enchantment, Integer> baseEnch = base.getEnchantments();
    Map<Enchantment, Integer> givenEnch = given.getEnchantments();
    if (enchantMatch == MatchingMode.EXACT || enchantMatch == MatchingMode.EXACT_TEXT) {
        if (!baseEnch.equals(givenEnch)) return false;
    } else if (enchantMatch == MatchingMode.CONTAINS || enchantMatch == MatchingMode.CONTAINS_TEXT) {
        for (Map.Entry<Enchantment, Integer> e : baseEnch.entrySet()) {
            if (!givenEnch.containsKey(e.getKey()) || givenEnch.get(e.getKey()) < e.getValue())
                return false;
        }
    }

    String[] baseLore = getLore(base);
    String[] givenLore = getLore(given);
    if (loreMatch == MatchingMode.EXACT && !Arrays.deepEquals(baseLore, givenLore)) return false;
    if (loreMatch == MatchingMode.CONTAINS && !containStrArr(givenLore, baseLore, false)) return false;
    if (loreMatch == MatchingMode.EXACT_TEXT) {
        for (int i = 0; i < baseLore.length; i++) baseLore[i] = ChatColor.stripColor(baseLore[i]);
        for (int i = 0; i < givenLore.length; i++) givenLore[i] = ChatColor.stripColor(givenLore[i]);
        if (!Arrays.deepEquals(baseLore, givenLore)) return false;
    }
    if (loreMatch == MatchingMode.CONTAINS_TEXT && !containStrArr(givenLore, baseLore, true)) return false;

    return true;
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:55,代码来源:BasicItemMatcher.java

示例15: subItemInHand

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void subItemInHand(PlayerInteractEvent e){
	ItemStack is=e.getItem();
	is.setAmount(is.getAmount()-1);
	e.getPlayer().getInventory().setItemInMainHand(is);
}
 
开发者ID:SchoolUniform,项目名称:RealSurvival,代码行数:6,代码来源:UseItemEvent.java


注:本文中的org.bukkit.inventory.ItemStack.setAmount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。