Won't set resulting ItemStack in Anvil Inventory

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

      Won't let me set resulting ItemStack in anvil inventory. Also, a better way to customize the repair cost would be good.

      org.bukkit.craftbukkit.git-Bukkit-efe04b8.inventory.CraftContainer is not implemented properly. setupSlots lacks multiple inventory types.

      https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java#118

      Here is where it should set the resulting item...

      meta.setLore(Arrays.asList(two));
      result.setItemMeta(meta);
      anvil.setItem(2, result);
      

      Here is the rest of the class...

      public class Anvil implements Listener {
      
          String one = ChatColor.translateAlternateColorCodes('&', "&bSwift I");
          String two = ChatColor.translateAlternateColorCodes('&', "&eSwift II");
      
          @EventHandler
          public void onCombine(InventoryClickEvent e) {
              if (!(e.getWhoClicked() instanceof Player))
                  return;
              ClickType click = e.getClick();
              int slot = e.getSlot();
              SlotType stype = e.getSlotType();
              InventoryType inv = e.getInventory().getType();
              ItemStack current = e.getCurrentItem();
              ItemStack cursor = e.getCursor();
              if (click == ClickType.LEFT || click == ClickType.RIGHT) {
                  if (current.getType() == Material.AIR && cursor.getType() != Material.AIR) {
                      if (!(stype == SlotType.CRAFTING && inv == InventoryType.ANVIL))
                          return;
                      AnvilInventory anvil = (AnvilInventory) e.getInventory();
                      ItemStack[] items = anvil.getContents();
                      ItemStack item1 = items[0];
                      ItemStack item2 = items[1];
                      List<String> lore = cursor.getItemMeta().getLore();
                      Material book = Material.ENCHANTED_BOOK;
                      ItemStack result = new ItemStack(Material.ENCHANTED_BOOK);
                      ItemMeta meta = result.getItemMeta();
                      if (slot == 1 && item1 != null) {
                          if (!(cursor.getType() == book && item1.getType() == book))
                              return;
                          List<String> lore1 = item1.getItemMeta().getLore();
                          if (lore1.contains(one) && lore.contains(one)) {
                              meta.setLore(Arrays.asList(two));
                              result.setItemMeta(meta);
                              anvil.setItem(2, result);
                          }
                      } else if (item1 == null && item2 != null) {
                          if (!(cursor.getType() == book && item2.getType() == book))
                              return;
                          List<String> lore2 = item2.getItemMeta().getLore();
                          if (lore2.contains(one) && lore.contains(one)) {
                              meta.setLore(Arrays.asList(two));
                              result.setItemMeta(meta);
                              anvil.setItem(2, result);
                          }
                      }
                  }
              }
          }
      }
      

            Assignee:
            Unassigned
            Reporter:
            Braden Mitchell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: