Not sure what the problem is.

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

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

    DatCookiez

    Hello Guys,

    I've made something that repairs all the items in a players inventory and armour slots when they move and I was wanting it to NOT repair the armour that's enchanted, I have this code and I thought it was right, but it doesn't seem to be working -.-

    Code:
    Code:java
    1. @EventHandler
    2. public void onPlayerItemBrake(PlayerMoveEvent 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.getType().getMaxDurability() != 0)
    16. if (item != null){
    17. if (item.getDurability() > 10){
    18. item.setDurability((short) 0);
    19. player.updateInventory();
    20. }
    21. }
    22.  
    23. if (item1 != null){
    24. if (item1.getEnchantments().isEmpty()){
    25. if (item1.getDurability() > 10){
    26. item1.setDurability((short) 0);
    27. player.updateInventory();
    28. }
    29. }
    30. }
    31. if (item2 != null){
    32. if (item2.getEnchantments().isEmpty()){
    33. if (item2.getDurability() > 10) {
    34. item2.setDurability((short) 0);
    35. player.updateInventory();
    36. }
    37. }
    38. }
    39. if (item3 != null){
    40. if (item3.getEnchantments().isEmpty()){
    41. if (item3.getDurability() > 10) {
    42. item3.setDurability((short) 0);
    43. player.updateInventory();
    44. }
    45. }
    46. }
    47. if (item4 != null){
    48. if (item4.getEnchantments().isEmpty()){
    49. if (item4.getDurability() > 10){
    50. item4.setDurability((short) 0);
    51. player.updateInventory();
    52. }
    53. }
    54. }
    55. }
    56. }
    57. }
     
  2. Offline

    Mathias Eklund

    the enchantment check should be after the durability check or before. Not a different if statement.
     
Thread Status:
Not open for further replies.

Share This Page