Solved Virtual Anvil GUI Cancles

Discussion in 'Plugin Development' started by Banjer_HD, Aug 2, 2017.

Thread Status:
Not open for further replies.
  1. Hey there!
    I am trying to make an anvil GUI but every time I use it to rename an item it cancels before I can run the code to check which item it is, my code:
    Code:
        @EventHandler
        public void onPlace(BlockPlaceEvent e) {
            if(e.getBlock().getType().equals(Material.BEACON)) {
               
                Inventory anvilinv = Bukkit.createInventory(e.getPlayer(), InventoryType.ANVIL);
               
                ItemStack nametag = new ItemStack(Material.NAME_TAG, 1);
                ItemMeta nametagmeta = nametag.getItemMeta();
               
                nametagmeta.setDisplayName("Name your item");
                nametag.setItemMeta(nametagmeta);
               
                anvilinv.setItem(0, nametag);
               
                e.getPlayer().openInventory(anvilinv);
               
            }
        }
       
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e) {
           
            if(e.getClickedInventory().getType().equals(InventoryType.ANVIL)) {
               
                Bukkit.broadcastMessage("Its the inv!");
               
               
               
                InventoryView view = e.getView();
                int rawSlot = e.getRawSlot();
               
                if(rawSlot == view.convertSlot(rawSlot) && rawSlot == 2) {
                   
                    Bukkit.broadcastMessage("Its the slot!");
                   
                   
                    ItemStack item = e.getCurrentItem();
                    Bukkit.broadcastMessage("Item is: " + item.getType().toString());
                   
               
                }
               
               
            }
           
        }
    
    It does reach 'Its the slot!' but it gives a NullPointerException on "Bukkit.broadcastMessage("Item is:" + item.getType().toString())".
    It does output the itemtype when I just use a normal anvil, so I think that the virtual anvil cancels the rename when I click the output item(It also doesn't rename it).

    Thanks for reading!
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Yes, and even if there is an item, it tells me it is null....
     
Thread Status:
Not open for further replies.

Share This Page