EnchantmentTarget not set for every Enchantment

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor
    • None
    • Affects Version/s: None

      In NMS there is a new EnchantmentSlotType called BREAKABLE. In the method that maps these to Bukkit it is missing. This causes enchantments like Mending to not have a EnchantmentTarget.

      org.bukkit.craftbukkit.enchantments.CraftEnchantment.java:

          @Override
          public EnchantmentTarget getItemTarget() {
              switch (target.itemTarget) {
              case ALL:
                  return EnchantmentTarget.ALL;
              case ARMOR:
                  return EnchantmentTarget.ARMOR;
              case ARMOR_FEET:
                  return EnchantmentTarget.ARMOR_FEET;
              case ARMOR_HEAD:
                  return EnchantmentTarget.ARMOR_HEAD;
              case ARMOR_LEGS:
                  return EnchantmentTarget.ARMOR_LEGS;
              case ARMOR_CHEST:
                  return EnchantmentTarget.ARMOR_TORSO;
              case DIGGER:
                  return EnchantmentTarget.TOOL;
              case WEAPON:
                  return EnchantmentTarget.WEAPON;
              case BOW:
                  return EnchantmentTarget.BOW;
              case FISHING_ROD:
                  return EnchantmentTarget.FISHING_ROD;
              default:
                  return null;
              }
          }
      

      is missing:

              case BREAKABLE:
                  return EnchantmentTarget.BREAKABLE; //<- also needs to be added
      

      This causes even more errors as it seems that this part is not recompiled somehow. (could also be a decompilation error) As switch case with enums goes over the ordinals of the enum, some of the ordinals are out of sync.

      Decompiled code builded 10 minutes ago with --rev 1.10.2 :

        public EnchantmentTarget getItemTarget()
        {
          switch (this.target.itemTarget)
          {
          case ALL: 
            return EnchantmentTarget.ALL;
          case ARMOR: 
            return EnchantmentTarget.ARMOR;
          case ARMOR_CHEST: 
            return EnchantmentTarget.ARMOR_FEET;
          case ARMOR_LEGS: 
            return EnchantmentTarget.ARMOR_HEAD;
          case ARMOR_FEET: 
            return EnchantmentTarget.ARMOR_LEGS;
          case ARMOR_HEAD: 
            return EnchantmentTarget.ARMOR_TORSO;
          case BREAKABLE: 
            return EnchantmentTarget.TOOL;
          case BOW: 
            return EnchantmentTarget.WEAPON;
          case WEAPON: 
            return EnchantmentTarget.BOW;
          case DIGGER: 
            return EnchantmentTarget.FISHING_ROD;
          }
          return null;
        }
      

            Assignee:
            Unassigned
            Reporter:
            sirati97
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: