本文整理汇总了Java中org.bukkit.inventory.ItemStack.getAmount方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.getAmount方法的具体用法?Java ItemStack.getAmount怎么用?Java ItemStack.getAmount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.ItemStack
的用法示例。
在下文中一共展示了ItemStack.getAmount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: howMuchSpaceForItemAsync
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public int howMuchSpaceForItemAsync(WrappedDirection insertDirection, ItemStack insertion) {
if (!cachedChunk.isLoaded()) {
return 0;
}
if (isInvLocked(cachedInvHolder)) {
return 0;
}
int freeSpace = 0;
for (int i = 0; i < cachedInv.getSize(); i++) {
ItemStack is = cachedInv.getItem(i);
if (is == null || is.getType() == Material.AIR) {
freeSpace += insertion.getMaxStackSize();
} else if (is.isSimilar(insertion) && is.getAmount() < is.getMaxStackSize()) {
freeSpace += is.getMaxStackSize() - is.getAmount();
}
}
return freeSpace;
}
示例2: howManyItemsFit
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
protected int howManyItemsFit(ItemStack toPut, ItemStack before) {
if (toPut == null) {
return 0;
}
if (before == null) {
return toPut.getMaxStackSize();
}
if (before.isSimilar(toPut)) {
if (before.getAmount() < before.getMaxStackSize()) {
return before.getMaxStackSize() - before.getAmount();
} else {
return 0;
}
} else {
return 0;
}
}
示例3: putItemInSlot
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
* tries to add item {@link toPut} to item {@link before} and returns the result
* item.<br>
* if the item couldn't be inserted, the result item is equal to {@link before}.
*/
protected ItemStack putItemInSlot(ItemStack toPut, ItemStack before) {
if (toPut == null) {
return before;
}
if (before == null) {
ItemStack returnCopy = toPut.clone();
toPut.setAmount(0);
return returnCopy;
}
ItemStack beforeItemStack = before.clone();
if (beforeItemStack.isSimilar(toPut)) {
int beforeAmount = beforeItemStack.getAmount();
beforeItemStack.setAmount(Math.min(before.getMaxStackSize(), beforeAmount + toPut.getAmount()));
toPut.setAmount(Math.max(0, toPut.getAmount() - (before.getMaxStackSize() - beforeAmount)));
}
return beforeItemStack;
}
示例4: getName
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public String getName(ItemStack stack) {
if(plugin.nmsItemsName == true){
return plugin.getItemsname().getItemStackName(stack);
} else {
String name = "";
name = stack.getType().toString();
int amt = stack.getAmount();
if(amt > 1){
name += " §3x " + amt;
}
return name;
}
}
示例5: 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;
}
}
}
示例6: 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++;
}
}
}
}
示例7: decrementHand
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void decrementHand(Player player) {
ItemStack stack = player.getItemInHand();
if (stack.getAmount() <= 1) {
player.setItemInHand(new ItemStack(Material.AIR, 1));
} else {
stack.setAmount(stack.getAmount() - 1);
}
}
示例8: getItemStackName
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public String getItemStackName(ItemStack stack){
String name = "";
try{
name = CraftItemStack.asNMSCopy(stack).getName();
} catch (Exception e){
name = stack.getType().toString();
}
int amt = stack.getAmount();
if(amt > 1){
name += " §3x " + amt;
}
return name;
}
示例9: contains
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public boolean contains(int materialId, int amount) {
if (amount <= 0) {
return true;
}
for (ItemStack item : getContents()) {
if (item != null && item.getTypeId() == materialId) {
if ((amount -= item.getAmount()) <= 0) {
return true;
}
}
}
return false;
}
示例10: 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;
}
示例11: itemStackToString
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static String itemStackToString(ItemStack item) {
StringBuilder builder = new StringBuilder();
if (item != null) {
String isType = String.valueOf(item.getType().getId());
builder.append("[email protected]").append(isType);
if (item.getDurability() != 0) {
String isDurability = String.valueOf(item.getDurability());
builder.append(":[email protected]").append(isDurability);
}
if (item.getAmount() != 1) {
String isAmount = String.valueOf(item.getAmount());
builder.append(":[email protected]").append(isAmount);
}
Map<Enchantment, Integer> isEnch = (Map<Enchantment, Integer>) item.getEnchantments();
if (isEnch.size() > 0) {
for (Map.Entry<Enchantment, Integer> ench : isEnch.entrySet()) {
builder.append(":[email protected]").append(ench.getKey().getId()).append("@").append(ench.getValue());
}
}
if (item.hasItemMeta()) {
ItemMeta imeta = item.getItemMeta();
if (imeta.hasDisplayName()) {
builder.append(":[email protected]").append(imeta.getDisplayName());
}
if (imeta.hasLore()) {
builder.append(":[email protected]").append(imeta.getLore());
}
}
}
return builder.toString();
}
示例12: matches
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static boolean matches(ItemStack itemStack1, ItemStack itemStack2) {
if (itemStack1 == null || itemStack2 == null) {
return false;
}
if (!itemStack1.getType().equals(itemStack2.getType())) {
return false;
}
if (itemStack1.getAmount() != itemStack2.getAmount()) {
return false;
}
if (itemStack1.getDurability() != itemStack2.getDurability()) {
return false;
}
if (itemStack1.getMaxStackSize() != itemStack2.getMaxStackSize()) {
return false;
}
if (itemStack1.hasItemMeta() != itemStack2.hasItemMeta()) {
return false;
}
if (itemStack1.hasItemMeta() && itemStack2.hasItemMeta() && !itemStack1.getItemMeta().equals(itemStack2.getItemMeta())) {
return false;
}
return true;
}
示例13: insertItem
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(WrappedDirection insertDirection, ItemStack insertion) {
if (!cachedChunk.isLoaded()) {
return insertion;
}
if (isInvLocked(cachedBrewingStand)) {
return insertion;
}
if (insertion.getType() == Material.POTION || insertion.getType() == Material.SPLASH_POTION || insertion.getType() == Material.LINGERING_POTION) {
if (cachedInv.getItem(0) == null) {
cachedInv.setItem(0, insertion);
return null;
} else if (cachedInv.getItem(1) == null) {
cachedInv.setItem(1, insertion);
return null;
} else if (cachedInv.getItem(2) == null) {
cachedInv.setItem(2, insertion);
return null;
}
} else if (insertDirection.isSide() && insertion.getType() == Material.BLAZE_POWDER) {
ItemStack oldFuel = cachedInv.getFuel();
cachedInv.setFuel(putItemInSlot(insertion, oldFuel));
if (insertion == null || insertion.getAmount() == 0) {
insertion = null;
}
} else if (isBrewingIngredient(insertion)) {
ItemStack oldIngredient = cachedInv.getIngredient();
cachedInv.setIngredient(putItemInSlot(insertion, oldIngredient));
if (insertion == null || insertion.getAmount() == 0) {
insertion = null;
}
}
return insertion;
}
示例14: onArcherJumpClick
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=false, priority=EventPriority.HIGH)
public void onArcherJumpClick(PlayerInteractEvent event)
{
Action action = event.getAction();
if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) &&
(event.hasItem()) && (event.getItem().getType() == Material.FEATHER))
{
if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) {
return;
}
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
long timestamp = this.archerJumpCooldowns.get(uuid);
long millis = System.currentTimeMillis();
long remaining = timestamp == this.archerJumpCooldowns.getNoEntryValue() ? -1L : timestamp - millis;
if (remaining > 0L)
{
player.sendMessage(ChatColor.RED + "Cannot use Jump 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 + "Jump Boost 4 activated for 7 seconds.");
this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_JUMP_EFFECT);
this.archerJumpCooldowns.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + ARCHER_JUMP_COOLDOWN_DELAY);
}
}
}
示例15: contains
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public boolean contains( int i, int i1 ) {
int j = 0;
for ( ItemStack item : items ) {
if( item != null && item.getTypeId() == i ) {
j += item.getAmount();
}
}
return j >= i1;
}