Reset Durability

Discussion in 'Plugin Development' started by SoS_Dylan, Jan 23, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    SoS_Dylan

    I can't get the axe to reset its durability. :'(
    Code:java
    1. ItemStack axe = new ItemStack(Material.STONE_AXE);
    2. ItemMeta name = axe.getItemMeta();
    3. name.setDisplayName(ChatColor.WHITE + "Jackhammer");
    4. axe.setItemMeta(name);
    5. if (player.getItemInHand().equals(axe)) {
    6. if (jackhammer.contains(player.getDisplayName()) && started == true) {
    7. ItemStack stack = player.getItemInHand();
    8. axe.setDurability((short) 0);
    9. // TODO
    10. World w = Bukkit.getServer().getWorld("world");
    11. Double y = event.getBlock().getLocation().getY() + 1;
    12. Location l = new Location(w, event.getBlock().getLocation()
    13. .getX(), y, event.getBlock().getLocation().getZ());
    14. Material block = event.getBlock().getType();
    15. while (l.getBlock().getType() == block) {
    16. l.getBlock().setType(Material.AIR);
    17. y++;
    18. l.setY(y);
    19. }
    20. }
    21. }
     
  2. Offline

    Woobie

    SoS_Dylan
    So what is the problem here? It's not resetting the durability? An error in the console?
     
  3. Offline

    Gungsu

    try:
    Code:java
    1. player.getItemInHand().setDurability((short)0);


    How i use tag code java?
    thanks, drtshock.
     
  4. SoS_Dylan
    Probably because you are creating an new item stack and then checking that? Maybe try checking individual meta values for each item in the players inventory?
     
  5. Offline

    drtshock

    syntax=java then /syntax in []
     
  6. Offline

    Zimbaway

    Sometimes when you change durability it wont update on the client try relogging or right clicking the item.
     
  7. Offline

    SoS_Dylan

    No error, It just won't reset.
     
  8. Offline

    lolwel21

    Are you trying to get it to go back to full or break?
     
  9. Offline

    Hedgehogs4Me

    Just a heads up if you're trying to reset its durability whenever it's used, EntityDamageByEntityEvent triggers before the item's damaged, meaning that it'll always be stuck with a damage bar. I'm not sure about BlockBreakEvent, though.

    If you want to make it always look pristine, you might have to use a scheduler.
     
Thread Status:
Not open for further replies.

Share This Page