Solved Unbreakable items (Item gets no damage)

Discussion in 'Plugin Development' started by juampi_92, Feb 20, 2013.

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

    juampi_92

    Hi, i was wondering if there is a way to make an item (preferable a weapon) unbreakable.
    for example, a sword that never gets damaged (the damage bar doesnt even appear), just like in the creative mod.

    I'm going crazy looking for this, so if you could help me, i'd really apreciate it.
     
  2. Offline

    RealDope

    There might be an event for durability loss, doubt it though.

    Just listen to all events that would cause damage and set the durability back to full.
     
  3. Offline

    juampi_92

    If someone knows some better way, it'd be nice :)

    Thanks btw
     
  4. Offline

    microgeek

    Add it to a list, loop the list in a task and set the durability?
     
  5. Offline

    juampi_92

    That seems a bit unefficient and unpractical, but it's a possibility...
     
  6. No, list is not good at all...
    Just listen to PlayerInteractEvent for left clicks and EntityDamageByEntity event and that should kinda cover it...
    But just to be sure it won't break you can also listen to PlayerItemBreakEvent, reset the damage to 0 and cancel it.
     
  7. Offline

    juampi_92

    Thanks Digi. I'll do that, and post it here in case someone needs it.
     
  8. Offline

    juampi_92

    Code:JAVA
    1. // Items Indestructibles
    2. @EventHandler
    3. public void noWeaponBreakDamage( EntityDamageByEntityEvent event){
    4. if( event.getDamager() instanceof Player )
    5. ((Player) event.getDamager()).getItemInHand().setDurability((short) 1);
    6. else
    7. if ( event.getEntity() instanceof Player ){
    8. ItemStack armor = ((Player) event.getEntity()).getInventory().getArmorContents();
    9. for(ItemStack i:armor) {
    10. i.setDurability((short) 0);
    11. }
    12. ((Player) event.getEntity()).getInventory().setArmorContents(armor);
    13. }
    14. }
    15. @EventHandler
    16. public void noWeaponBreakDamage( EntityShootBowEvent event){
    17. // Bow
    18. if( event.getEntity() instanceof Player )
    19. event.getBow().setDurability((short) 1);
    20. }
    21. @EventHandler
    22. public void noWeaponBreakDamage( PlayerItemBreakEvent event){
    23. ItemStack item = event.getBrokenItem().clone();
    24. item.setDurability((short)0);
    25. event.getPlayer().getInventory().addItem(item);
    26. }
     
    lekrosa likes this.
  9. juampi_92
    I was also going CRAZY looking for it. Thanks so much!
     
  10. Offline

    Lumynum

    Sorry for bumping a really old thread, but I would like to know, where do I paste this?
    Thanks in advance, and sorry if the question seems impractical or foolish, I'm pretty new to servers.
     
  11. Offline

    Minesuchtiiii

    in your main class maybe .. ?
    Or somewhere where it's gona used from the plugin and it won't show errors ..?!
     
  12. Offline

    Ironraptor3

    In your listener class… where else would you use even handler….?
     
    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page