本文整理汇总了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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例12: fixDurability
import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public static void fixDurability(ItemStack item) {
if (item.getType().getMaxDurability() > 0)
item.setDurability((short) 0);
}
示例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);
}
示例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);
}
}
}
}
示例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:
}
}
}