Solved Bow Durability

Discussion in 'Plugin Development' started by Javlin, Mar 13, 2016.

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

    Javlin

    So I've been trying to make bows unbreakable, but it appears that although the server realizes the bow is still at the max durability, the client doesn't. The durability for the client only updates when there is an change in that person's inventory. EX: https://gyazo.com/0fbe3a98a9af26557de5d295c6af2a31
    My current code is:
    Code:
    @EventHandler
        public void onItemDamage(PlayerItemDamageEvent e) {
            if(e.getItem().getType() == Material.BOW) {
                    e.setCancelled(true);
            }
        }
     
  2. Offline

    Scorpionvssub

    maybe try Instanceof not sure how much difference there is btween == and instance but it did solve issues sometimes that ive had
     
  3. @Javlin
    You can use Player#updateInventory to update their inventory.
     
  4. Offline

    87pen

    Why don't you just give the bow unbreakable?
     
  5. Offline

    Javlin

    As in the enchantment? Well, I didn't want it to appear enchanted, and since this is global, I still want people to be able to enchant it without an anvil.
    This works, but is there a quick flash of the durability bar before it switches back. Is it possible to do it without this flash?
     
  6. @Javlin
    Perhaps try setting the item's durability?
    Code:
    e.getItem().setDurability(e.getItem().getType().getMaxDurability());
     
  7. Offline

    Javlin

    This still requires an inventory update :/
     
  8. Offline

    87pen

    @Javlin No Give it the metadata Unbreakable. Unbreakable isn't an enchantment. And then using ItemFlags hide it.
     
  9. Try without cancelling the event. If that doesn't work, I'd recommend @87pen 's suggestion, although I'm fairly sure hiding the ItemFlag will not hide the glow.

    Edit: I was thinking about unbreaking too, my bad :p
     
  10. Offline

    Javlin

    Oh, I was thinking unbreaking. Trying now.
    EDIT: Works. Thank you all.
     
    Last edited: Mar 13, 2016
  11. Offline

    87pen

    @Assist ... It won't glow because unbreakable is not an enchantment. Unbreakable is a metadata [​IMG] This is unbreakable tag, and it can be hidden with ItemFlags.
    Edit: nvm saw your edit.
     
Thread Status:
Not open for further replies.

Share This Page