Getting string from anvil doesn't work

Discussion in 'Spigot Plugin Development' started by iAmGio, Jun 18, 2016.

  1. Hi guys,
    I have to get a string from an anvil, my code is:

    Code (Text):
    if (e.getClickedInventory().equals(AnvilInv.anvil))
                {
                    int rawSlot = e.getRawSlot();
                    if (rawSlot == 2)
                    {
                        e.setCancelled(true);
                        ItemStack item = e.getCurrentItem();

                        if (item != null)
                        {
                            ItemMeta meta = item.getItemMeta();
                            String displayName = meta.getDisplayName();

                            p.closeInventory();

                            p.sendMessage(e.getCurrentItem().getItemMeta().getDisplayName());


                            return;
                        }
                    }
                    else
                    e.setCancelled(true);
    }

    But when I click the output slot it returns to the first slot.
    If I use if(rawSlot == 0) it works flawlessy.
     
  2. You want to get a string from an itemStack in anvil ?
     
    • Like Like x 1
  3. Yes
     
  4. @iAmGio I believe bukkit doesn't allow you to work with the result slot in anvils. If you create a custom anvil inventory using Bukkit.createInventory() you only get 2 slots instead of 3 to put items in. You would have to work with packets/some NMS stuff to get it to work properly.
     
    • Like Like x 1
  5. Look in my signature ;)