Reset Durability

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

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


    I can't get the axe to reset its durability. :'(
    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


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


    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


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


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


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


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


    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