當前位置: 首頁>>代碼示例>>Java>>正文


Java ItemStack.getDurability方法代碼示例

本文整理匯總了Java中org.bukkit.inventory.ItemStack.getDurability方法的典型用法代碼示例。如果您正苦於以下問題:Java ItemStack.getDurability方法的具體用法?Java ItemStack.getDurability怎麽用?Java ItemStack.getDurability使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.inventory.ItemStack的用法示例。


在下文中一共展示了ItemStack.getDurability方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: friendlySummarizeDrops

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public String friendlySummarizeDrops(List<ItemStack> items) {
	StringBuffer toString = new StringBuffer();
	for (ItemStack itemStack: items) {
		toString.append(" ");
		Material material = itemStack.getType();
		int amount = itemStack.getAmount();
		short durability = itemStack.getDurability();
				
		if (amount != 1) {
			toString.append(amount).append(" x ");
		}
		
		toString.append(itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() ? 
					itemStack.getItemMeta().getDisplayName() : material.toString());
		if (durability > 0) {
			toString.append(":").append(durability);
		}
	}
	return toString.toString();
}
 
開發者ID:DevotedMC,項目名稱:CropControl,代碼行數:21,代碼來源:CropControlEventHandler.java

示例2: serialize

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public static String serialize(ItemStack item) {
	String name = item.getType().name().toLowerCase();
	String data = "";
	if (item.getDurability() != (short) 0)
		data = ":" + item.getDurability();
	
	String amount = "";
	if (item.getAmount() > 1)
		amount = "," + item.getAmount();
	
	String ench = "";
	if (item.getEnchantments().size() > 0) {
		for (Entry<Enchantment, Integer> e : item.getEnchantments().entrySet()) {
			ench += e.getKey().getName().toLowerCase() + ":" + e.getValue() + ",";
		}
		ench = ench.substring(ench.length() - 1);
	}
	
	return name + data + amount + ench;		
}
 
開發者ID:thekeenant,項目名稱:mczone,代碼行數:21,代碼來源:ItemUtil.java

示例3: onClick

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public static void onClick(Player p, ItemStack item)
{
    if (item.getType() == Material.WOOD_DOOR)
        p.closeInventory();
    if (item.getType() != Material.WOOL)
        return ;
    for (TeamColor color : getColors(AgarMC.get().getGame().getGameType()))
        if (color.getData() == item.getDurability())
        {
            CPlayer cplayer = AgarMC.get().getGame().getCPlayer(p);
            if (cplayer != null)
            {
                cplayer.setColor(color.getChatColor());
                cplayer.updateColor();
                p.sendMessage(ChatColor.YELLOW + "Vous êtes maintenant" + (AgarMC.get().getGame().getGameType() == GameType.TEAMS ? " dans l'équipe" : "") + " : " + color.getDisplayName());
                return ;
            }
        }
}
 
開發者ID:SamaGames,項目名稱:AgarMC,代碼行數:20,代碼來源:TeamSelectorGui.java

示例4: testValidity

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
private boolean testValidity(ItemStack[] contents) {
    for (ItemStack stack : contents) {
        if (stack != null && stack.getType() == Material.POTION && stack.getDurability() != 0) {
            Potion potion = Potion.fromItemStack(stack);

            // Just to be safe, null check this.
            if (potion == null)
                continue;

            PotionType type = potion.getType();

            // Mundane potions etc, can return a null type
            if (type == null)
                continue;

            // is 33s poison, allow
            if (type == PotionType.POISON && !potion.hasExtendedDuration() && potion.getLevel() == 1) {
                continue;
            }

            if (potion.getLevel() > getMaxLevel(type)) {
                return false;
            }
        }
    }
    return true;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:28,代碼來源:PotionLimitListener.java

示例5: ItemStacks

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public ItemStacks(ItemStack sta){
    meta = new DefaultMeta(sta.getItemMeta());
    id = sta.getTypeId();
    durability = sta.getDurability();
    amount = sta.getAmount();
    array = new EnchantArray(sta);

}
 
開發者ID:DevCrafters,項目名稱:SaveableSerializing,代碼行數:9,代碼來源:ItemStacks.java

示例6: removeItem

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public static final boolean removeItem(ItemStack stack) {
	loadShop();
	for(ShopItem item : shopItems) {
		if(item.getStack().getType().equals(stack.getType())) {
			if(item.getStack().getDurability() == stack.getDurability()) {
				shopItems.remove(item);
				saveShop();
				return true;
			}
		}
	}
	return false;
}
 
開發者ID:cjburkey01,項目名稱:BurkeyShop,代碼行數:14,代碼來源:ShopHandler.java

示例7: isSame

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public static boolean isSame(ItemStack a, ItemStack b) {
    if (a == null || b == null) return false;

    boolean type = a.getType() == b.getType();
    boolean amount = a.getAmount() == b.getAmount();
    boolean dura = a.getDurability() == b.getDurability();
    boolean itemMeta = a.hasItemMeta() == b.hasItemMeta();

    return (type) &&
            (amount) &&
            (dura) &&
            (itemMeta) && isSameMeta(a.getItemMeta(), b.getItemMeta());
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:14,代碼來源:Util.java

示例8: 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();
}
 
開發者ID:ijoeleoli,項目名稱:ZorahPractice,代碼行數:39,代碼來源:InventoryUtils.java

示例9: InventoryToString

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public static String InventoryToString (Inventory invInventory)
{
    String serialization = invInventory.getSize() + ";";
    for (int i = 0; i < invInventory.getSize(); i++)
    {
        ItemStack is = invInventory.getItem(i);
        if (is != null)
        {
            String serializedItemStack = new String();
           
            String isType = String.valueOf(is.getType().getId());
            serializedItemStack += "[email protected]" + isType;
           
            if (is.getDurability() != 0)
            {
                String isDurability = String.valueOf(is.getDurability());
                serializedItemStack += ":[email protected]" + isDurability;
            }
           
            if (is.getAmount() != 1)
            {
                String isAmount = String.valueOf(is.getAmount());
                serializedItemStack += ":[email protected]" + isAmount;
            }
           
            Map<Enchantment,Integer> isEnch = is.getEnchantments();
            if (isEnch.size() > 0)
            {
                for (Entry<Enchantment,Integer> ench : isEnch.entrySet())
                {
                    serializedItemStack += ":[email protected]" + ench.getKey().getId() + "@" + ench.getValue();
                }
            }
           
            serialization += i + "#" + serializedItemStack + ";";
        }
    }
    return serialization;
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:41,代碼來源:InventoryStringDeSerializer.java

示例10: onPlayerConsume

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
    ItemStack stack = event.getItem();
    if (stack != null && stack.getType() == Material.GOLDEN_APPLE && stack.getDurability() == 1) {
        Player player = event.getPlayer();
        if (setCooldown(player, player.getUniqueId(), defaultCooldown, false, new Predicate<Long>() {
            @Override
            public boolean apply(@Nullable Long value) {
                return false;
            }
        })) {

            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588&e\u2588\u2588&c\u2588\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588\u2588\u2588&e\u2588&c\u2588\u2588\u2588\u2588 &6&l " + this.name + ": ")));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588 &7  Consumed"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&f\u2588&6\u2588&6\u2588\u2588&c\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588&f\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &6 Cooldown Remaining:"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', ("&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588 &7  " + DurationFormatter.getRemaining(getRemaining(player), true, false))));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588&6\u2588\u2588&6\u2588&6\u2588&6\u2588\u2588&c\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588&6\u2588\u2588\u2588\u2588&c\u2588\u2588"));
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c\u2588\u2588\u2588\u2588\u2588&c\u2588\u2588\u2588"));
        } else {
            event.setCancelled(true);
            player.sendMessage(ChatColor.RED + "You still have a " + getDisplayName() + ChatColor.RED + " cooldown for another " + ChatColor.BOLD
                    + DurationFormatter.getRemaining(getRemaining(player), true, false) + ChatColor.RED + '.');
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:30,代碼來源:GappleTimer.java

示例11: getItem

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public static boolean getItem(TOAUser p, ItemStack item) {
    Inventory i = getInventory(p);
    for (int x = 0; x < getInvSize(p); x++) {
        if (i.getItem(x) == null) {
            return false;
        }
        if ((item.getType() == i.getItem(x).getType()) && (item.getAmount() <= i.getItem(x).getAmount()) && (item.getDurability() == i.getItem(x).getDurability())) {
            itemSlot = x;
            return true;
        }
    }
    return false;
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:14,代碼來源:BagEvents.java

示例12: ItemBuilder

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public ItemBuilder(ItemStack item) {
    this(item.getType(), item.getAmount(), item.getDurability(), item.getData());

    ItemMeta meta = item.getItemMeta();
    itemProcessors.add(data -> data.setItemMeta(meta));
}
 
開發者ID:EntryPointKR,項目名稱:MCLibrary,代碼行數:7,代碼來源:ItemBuilder.java

示例13: 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

示例14: CraftFurnaceRecipe

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public CraftFurnaceRecipe(ItemStack result, ItemStack source) {
    super(result, source.getType(), source.getDurability());
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:4,代碼來源:CraftFurnaceRecipe.java

示例15: NBTWrapper

import org.bukkit.inventory.ItemStack; //導入方法依賴的package包/類
public NBTWrapper(ItemStack item) {
    this.type = item.getType();
    this.amt = item.getAmount();
    this.meta = item.getDurability();
    this.tag = loadTag(item);
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:7,代碼來源:NBTWrapper.java


注:本文中的org.bukkit.inventory.ItemStack.getDurability方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。