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


Java ItemStack.setDurability方法代码示例

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


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

示例1: onBlockBreak

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
 * Damage the diamond pickage if an obsidian block is broken
 *
 * @param event Event
 */
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event)
{
    if (event.getBlock().getType() == Material.OBSIDIAN)
    {
        ItemStack item = event.getPlayer().getItemInHand();
        item.setDurability((short) (item.getDurability() + 500));

        if (item.getDurability() > item.getType().getMaxDurability())
        {
            event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ITEM_BREAK, 1, 1);
            event.getPlayer().getInventory().setItemInHand(new ItemStack(Material.AIR));
        }
        else
        {
            event.getPlayer().getInventory().setItemInHand(item);
        }
    }
}
 
开发者ID:SamaGames,项目名称:SurvivalAPI,代码行数:25,代码来源:HardObsidianModule.java

示例2: build

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
 * Get the final {@link ItemStack} with all the attributes you have been adding
 *
 * @return the {@link ItemStack} out of this {@link ItemBuilder}
 */
public ItemStack build() {
    ItemStack s = new ItemStack(material);
    s.setAmount(amount);
    s.setDurability(damage);
    ItemMeta m = s.getItemMeta();

    for (ItemFlag iflag : itemflags)
        m.addItemFlags(iflag);
    m.setDisplayName(name);
    m.setLore(lore);
    s.setItemMeta(m);
    for (Map.Entry<Enchantment, Integer> temp : enchantments.entrySet())
        s.addUnsafeEnchantment(temp.getKey(), temp.getValue());

    for (ItemData id : getAllData())
        try {
            id.applyOn(s);
        } catch (WrongDataException e) {
            e.printStackTrace();
        }

    return s;
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:29,代码来源:ItemBuilder.java

示例3: toItemStack

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private ItemStack toItemStack(VillagerTrade trade, Player player, Game game) {
	ItemStack tradeStack = trade.getRewardItem().clone();
	Method colorable = Utils.getColorableMethod(tradeStack.getType());
	ItemMeta meta = tradeStack.getItemMeta();
	ItemStack item1 = trade.getItem1();
	ItemStack item2 = trade.getItem2();
	if ((tradeStack.getType().equals(Material.STAINED_GLASS))
			|| (tradeStack.getType().equals(Material.WOOL))
			|| (tradeStack.getType().equals(Material.STAINED_CLAY))) {
		tradeStack.setDurability((short) game.getPlayerTeam(player)
				.getColor().getDyeColor().getData());
	} else if (colorable != null) {
		colorable.setAccessible(true);
		try {
			colorable.invoke(meta, new Object[] { game
					.getPlayerTeam(player).getColor().getColor() });
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	List<String> lores = meta.getLore();
	if (lores == null) {
		lores = new ArrayList<String>();
	}
	if (trade instanceof XPVillagerTrade) {
		lores.add("��a" + ((XPVillagerTrade) trade).getXP() + " ����");
	} else {
		lores.add(ChatColor.WHITE + String.valueOf(item1.getAmount()) + " "
				+ item1.getItemMeta().getDisplayName());
		if (item2 != null) {
			lores.add(ChatColor.WHITE + String.valueOf(item2.getAmount())
					+ " " + item2.getItemMeta().getDisplayName());
		}
	}
	meta.setLore(lores);
	tradeStack.setItemMeta(meta);
	return tradeStack;
}
 
开发者ID:Ldcr993519867,项目名称:BedwarsXP,代码行数:39,代码来源:XPItemShop.java

示例4: handleLuckyRepair

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void handleLuckyRepair(BlockBreakEvent event) {
	ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
	if(Utility.getRandom(1, 10000) > 2 || item == null ||!ItemStackGenerator.isRepairable(item)) {
		return;
	}
	item.setDurability((short)0);
}
 
开发者ID:benNek,项目名称:AsgardAscension,代码行数:8,代码来源:AbilityListener.java

示例5: onAttack

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
	{
		Player player = (Player)event.getDamager();
		ItemStack item = player.getItemInHand();
		if(item.getType() == Material.WOOD_SPADE)
		{
			item.setDurability((short)(item.getDurability() - 2));
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:16,代码来源:FirestrikerClick.java

示例6: build

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
 * Creates a new itemStack from this
 *
 * @return itemStack
 */
public ItemStack build() {
    final ItemStack itemStack = new ItemStack(this.getType());
    itemStack.setAmount(this.getAmount());
    itemStack.setData(this.getData());
    itemStack.setDurability(this.getDurability());
    itemStack.setItemMeta(this.getItemMeta());
    return itemStack;
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:14,代码来源:ItemStackBuilder.java

示例7: repairGun

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
/**
 * Very basic repair of railgun, just resets durability.
 * 
 * @return the Railgun, or item if not a railgun.
 */
@Override
public ItemStack repairGun(ItemStack toRepair) {
	if (isGun(toRepair)) {
		toRepair.setDurability(this.gunExample.getDurability());
	}
	return toRepair;
}
 
开发者ID:ProgrammerDan,项目名称:AddGun,代码行数:13,代码来源:RailGun.java

示例8: tick

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
protected void tick(Block b) {
	if (isProcessing(b)) {
		int timeleft = progress.get(b);
		if (timeleft > 0) {
			ItemStack item = getProgressBar().clone();
	        item.setDurability(MachineHelper.getDurability(item, timeleft, processing.get(b).getTicks()));
			ItemMeta im = item.getItemMeta();
			im.setDisplayName(" ");
			List<String> lore = new ArrayList<String>();
			lore.add(MachineHelper.getProgress(timeleft, processing.get(b).getTicks()));
			lore.add("");
			lore.add(MachineHelper.getTimeLeft(timeleft / 2));
			im.setLore(lore);
			item.setItemMeta(im);
			
			BlockStorage.getInventory(b).replaceExistingItem(22, item);
			
			if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return;
			ChargableBlock.addCharge(b, -getEnergyConsumption());
			
			progress.put(b, timeleft - 1);
		}
		else {
			BlockStorage.getInventory(b).replaceExistingItem(22, new CustomItem(new MaterialData(Material.STAINED_GLASS_PANE, (byte) 15), " "));
			pushItems(b, processing.get(b).getOutput());
			
			progress.remove(b);
			processing.remove(b);
		}
	}
	else if (OreGenSystem.getSupplies(OreGenSystem.getResource("Milky Quartz"), b.getChunk(), false) > 0) {
		MachineRecipe r = new MachineRecipe(24, new ItemStack[0], new ItemStack[] {ChestTerminal.quartz});
		if (!fits(b, r.getOutput())) return;
		processing.put(b, r);
		progress.put(b, r.getTicks());
		OreGenSystem.setSupplies(OreGenSystem.getResource("Milky Quartz"), b.getChunk(), OreGenSystem.getSupplies(OreGenSystem.getResource("Milky Quartz"), b.getChunk(), false) - 1);
	}
}
 
开发者ID:TheBusyBiscuit,项目名称:ChestTerminal,代码行数:40,代码来源:QuartzDrill.java

示例9: placeBlock

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public ArmorStand placeBlock(Location l) {
	ArmorStand block = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
	block.setSmall(true);
	block.setGravity(false);
	block.setCustomName("CustomBlock");
	block.setCustomNameVisible(false);
	block.setInvulnerable(true);
	block.setVisible(false);
	block.setMarker(true);
	block.setSilent(true);
	
	ItemStack a = new ItemStack(Material.LEATHER_BOOTS);
	a.setDurability((short) primary.getTexture());
	LeatherArmorMeta am = (LeatherArmorMeta) a.getItemMeta();
	am.setColor(primary.getColor());
	am.setUnbreakable(true);
	if (primary.isGlowing()) {
		am.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 3, true);
	}
	a.setItemMeta(am);
	block.setHelmet(a);
	
	if (secondary != null) {
		ItemStack b = new ItemStack(Material.LEATHER_BOOTS);
		b.setDurability((short) secondary.getTexture());
		LeatherArmorMeta bm = (LeatherArmorMeta) b.getItemMeta();
		bm.setColor(secondary.getColor());
		bm.setUnbreakable(true);
		if (secondary.isGlowing()) {
			System.out.println("H");
			bm.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 3, true);
		}
		b.setItemMeta(bm);
		block.getEquipment().setItemInMainHand(b);
	}
	
	return block;
}
 
开发者ID:GigaGamma,项目名称:SuperiorCraft,代码行数:39,代码来源:CustomBlockTexture.java

示例10: CustomItemTexture

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public CustomItemTexture(int texture) {
	item = new ItemStack(Material.DIAMOND_SWORD);
	item.setDurability((short) 2);
   	ItemMeta im = item.getItemMeta();
   	im.setUnbreakable(true);
   	item.setItemMeta(im);
}
 
开发者ID:GigaGamma,项目名称:SuperiorCraft,代码行数:8,代码来源:CustomItemTexture.java

示例11: doRepair

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
private void doRepair(PlayerPickupItemEvent event, ItemStack stack) {
    ItemStack pickup = event.getItem().getItemStack();

    int hitsLeft = pickup.getType().getMaxDurability() - pickup.getDurability() + 1;
    stack.setDurability((short) Math.max(stack.getDurability() - hitsLeft, 0));

    event.setCancelled(true);
    event.getItem().remove();
    event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.5f, 1f);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:11,代码来源:ToolRepairMatchModule.java

示例12: fixDurability

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static void fixDurability(ItemStack item) {
    if (item.getType().getMaxDurability() > 0)
        item.setDurability((short) 0);
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:5,代码来源:ItemManager.java

示例13: onItemClick

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler
public void onItemClick(PlayerInteractEvent event)
{
	Player player = event.getPlayer();
	ItemStack mainItem = player.getInventory().getItemInMainHand();
	
	Score score_dualWieldMsg = tech_dualWieldMsg.getScore(player);
	
	if(mainItem.getType() == Material.GOLD_AXE)
	{
		if(dualWield.getScore(player).getScore() == 0)
		{
			if(event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR)
			{
				if(spin.getScore(player).getScore() == 0)
				{
					if(player.getFoodLevel() > 6)
					{
						Random rand = new Random();
						
						Spin(player);
						
						if(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)
							player.setFoodLevel(player.getFoodLevel() - 1);
						
						int chance_reduceDur = rand.nextInt(10) + 1;
						switch(chance_reduceDur)
						{
							case 1:
								mainItem.setDurability((short)(mainItem.getDurability() + 1));
								break;
							default:
						}
						
						if(mainItem.getDurability() >= 32)
						{
							player.getLocation().getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
							player.getInventory().setItemInMainHand(null);
						}
						player.updateInventory();
					}
					else
					{
						player.sendMessage(ChatColor.RED + Survival.Words.get("Lack of energy, unable to spin"));
					}
				}
			}
		}
		else 
		{
			if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
				score_dualWieldMsg.setScore(score_dualWieldMsg.getScore() + 1);
			else if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)
				score_dualWieldMsg.setScore(score_dualWieldMsg.getScore() + 2);
			if(score_dualWieldMsg.getScore() == 2)
			{
				player.sendMessage(ChatColor.RED + Survival.Words.get("Unable to dual-wield with Valkyrie's Axe"));
			}
		}
	}
	score_dualWieldMsg.setScore(0);
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:64,代码来源:Valkyrie.java

示例14: onAttack

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getEntity() instanceof Player)
	{
		Player player = (Player)event.getEntity();
		ItemStack offItem = player.getInventory().getItemInOffHand();

		if(dualWield.getScore(player).getScore() == 1)
		{
			event.setCancelled(true);
			return;
		}
		
		Random rand = new Random();
		
		if(offItem.getType() == Material.GOLD_HOE)
		{
			if(event.getDamager() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
			{
				LivingEntity enemy = (LivingEntity)event.getDamager();
				enemy.damage(event.getDamage() * 40 / 100, player);
			}
			
			int chance_reduceDur = rand.nextInt(10) + 1;
			switch(chance_reduceDur)
			{
				case 1:
					offItem.setDurability((short)(offItem.getDurability() + 1));
					break;
				default:
			}

			if(offItem.getDurability() >= 32)
			{
				player.getLocation().getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
				player.getInventory().setItemInOffHand(null);
			}
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:44,代码来源:GiantBlade.java

示例15: onBreakSnow

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onBreakSnow(BlockBreakEvent e)
{
	if(e.isCancelled()) return;
	Player player = e.getPlayer();
	if(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)
	{
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		switch(mainItem.getType())
		{
			case WOOD_SPADE:
			case GOLD_SPADE:
			case STONE_SPADE:
			case DIAMOND_SPADE:
			case IRON_SPADE:
				Block block = e.getBlock();
				switch(block.getType())
				{
					case SNOW:
						e.setCancelled(true);
						mainItem.setDurability((short) (mainItem.getDurability() + 1));
						if(mainItem.getDurability() >= mainItem.getType().getMaxDurability() + 1)
							player.getInventory().setItemInMainHand(null);
			            player.updateInventory();
			            block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.SNOW_BALL, block.getData() + 1));
			            block.setType(Material.AIR);
						break;
					case SNOW_BLOCK:
						e.setCancelled(true);
						mainItem.setDurability((short) (mainItem.getDurability() + 1));
						if(mainItem.getDurability() >= mainItem.getType().getMaxDurability() + 1)
							player.getInventory().setItemInMainHand(null);
			            player.updateInventory();
			            block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(Material.SNOW_BALL, 8));
			            block.setType(Material.AIR);
			            break;
					default:
				}
				break;
			default:
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:45,代码来源:SnowballThrow.java


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