本文整理汇总了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();
}
示例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;
}
示例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 ;
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
示例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();
}
示例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;
}
示例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 + '.');
}
}
}
示例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;
}
示例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));
}
示例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;
}
示例14: CraftFurnaceRecipe
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public CraftFurnaceRecipe(ItemStack result, ItemStack source) {
super(result, source.getType(), source.getDurability());
}
示例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);
}