Strange Error Turning blocks into...

Discussion in 'Plugin Development' started by DatCookiez, Nov 17, 2013.

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

    DatCookiez

    Hello Guys!

    I have a piece of code that refreshes a players inventory to full durability every time they interact and for some strange reason, when ever the player interacts with say a black wool block, the black wool turns into white wool, same with any block that has multiple shapes, example, mossy stone, cracked stone, etc.

    NOTE: I get no errors

    Code:
    Code:java
    1. @EventHandler
    2. public void onPlayerItemBrake(PlayerInteractEvent evt){
    3. Player player = evt.getPlayer();
    4. for (ItemStack item : player.getInventory().getContents()){
    5. ItemStack item4 = player.getInventory().getChestplate();
    6. ItemStack item1 = player.getInventory().getHelmet();
    7. ItemStack item2 = player.getInventory().getLeggings();
    8. ItemStack item3 = player.getInventory().getBoots();
    9.  
    10. if (player.getFoodLevel() <= 19){
    11. player.setFoodLevel(20);
    12. }
    13.  
    14. if (player.getInventory().contains(item) || player.getInventory().contains(item1) || player.getInventory().contains(item2) || player.getInventory().contains(item3) || player.getInventory().contains(item4)){
    15. if (item != null){
    16. if (item.getDurability() > 0){
    17. item.setDurability((short) 0);
    18. player.updateInventory();
    19. }
    20. }
    21.  
    22. if (item1 != null){
    23. if (item1.getDurability() > 0){
    24. item1.setDurability((short) 0);
    25. player.updateInventory();
    26. }
    27. }
    28. if (item2 != null){
    29. if (item2.getDurability() > 0) {
    30. item2.setDurability((short) 0);
    31. player.updateInventory();
    32. }
    33. }
    34. if (item3 != null){
    35. if (item3.getDurability() > 0) {
    36. item3.setDurability((short) 0);
    37. player.updateInventory();
    38. }
    39. }
    40. if (item4 != null){
    41. if (item4.getDurability() > 0){
    42. item4.setDurability((short) 0);
    43. player.updateInventory();
    44. }
    45. }
    46. }
    47. }
    48. }


    The block of code which turns black wool into white etc.
    Code:java
    1. if (item != null){
    2. if (item.getDurability() > 0){
    3. item.setDurability((short) 0);
    4. player.updateInventory();
    5. }
    6. }



     
  2. Offline

    Syd

    Wool, Ink and so on use the durability to save their state. So if you set the durability of an Item, you'll reset it's state.
    (Also you repair the armor slots multiple times)
     
  3. Offline

    DatCookiez

    Syd Could you please help me fix this?
     
  4. Offline

    Syd

    realiez
    if(item.getType().getMaxDurability() != 0)

    should make sure it's an item that can break.
    Or you use the PlayerItemBreakEvent. ;)
     
Thread Status:
Not open for further replies.

Share This Page