Inventory Get Action not working

Discussion in 'Plugin Development' started by Vex102, Apr 8, 2020.

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

    Vex102

    Inventory action not working
    Here is my code:


    Code:
    public class AgilityBook implements Listener
    {
    
      
        @EventHandler
        public void InventoryClick(InventoryClickEvent e)
        {
            if(e.getAction() == InventoryAction.SWAP_WITH_CURSOR)
            {
                if(e.getCursor().hasItemMeta())
                {
                    if(e.getCursor().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.WHITE + "Agility I"))
                    {
                        if(e.getCurrentItem().getType().equals(Material.DIAMOND_BOOTS))
                        {
                            e.getWhoClicked().sendMessage(ChatColor.GREEN + "Test");
                            e.setCancelled(true);
                            e.getWhoClicked().setItemOnCursor(null);
                            ItemStack item = e.getCurrentItem();
                            ItemMeta meta = item.getItemMeta();
                            meta.setDisplayName("Test");
                            if(meta.hasLore())
                            {
                                List<String> lore = meta.getLore();
                                lore.add(ChatColor.LIGHT_PURPLE + "Test");
                                meta.setLore(lore);
                            }else {
                                ArrayList<String> lore = new ArrayList<String>();
                                lore.add(ChatColor.LIGHT_PURPLE + "Test");
                                meta.setLore(lore);
                            }
                          
                            item.setItemMeta(meta);
                            e.setCurrentItem(item);
                            ((Player) e.getWhoClicked()).updateInventory();
                        }
                    }
                }
              
            }
        }
      
    }
     
    Last edited by a moderator: Apr 8, 2020
  2. Offline

    timtower Administrator Administrator Moderator

    @Vex102 Tried printing what the action is?
     
  3. Offline

    Vex102

    Alright so I fixed it but now it put's two lores on it instead of one is there any fix
     
  4. Offline

    timtower Administrator Administrator Moderator

    What is your new code?
     
  5. Offline

    Vex102

    Code:java
    1. public class AgilityBook implements Listener
    2. {
    3.  
    4.  
    5. @EventHandler
    6. public void InventoryClick(InventoryClickEvent e)
    7. {
    8. if(e.getAction() == InventoryAction.PLACE_ALL)
    9. {
    10. if(e.getCursor().hasItemMeta())
    11. {
    12. if(e.getCursor().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.WHITE + "Agility I"))
    13. {
    14. if(e.getCurrentItem().getType().equals(Material.DIAMOND_BOOTS))
    15. {
    16. e.getWhoClicked().sendMessage(e.getAction() + "");
    17. e.getWhoClicked().sendMessage(ChatColor.GREEN + "Test");
    18. e.setCancelled(true);
    19. e.getWhoClicked().setItemOnCursor(null);
    20. ItemStack item = e.getCurrentItem();
    21. ItemMeta meta = item.getItemMeta();
    22. if(meta.hasLore())
    23. {
    24. List<String> lore = meta.getLore();
    25. lore.add(ChatColor.LIGHT_PURPLE + "Agility 1");
    26. meta.setLore(lore);
    27.  
    28. }else {
    29. ArrayList<String> lore = new ArrayList<String>();
    30. lore.add(ChatColor.LIGHT_PURPLE + "Agility 1");
    31. meta.setLore(lore);
    32. }
    33.  
    34. item.setItemMeta(meta);
    35. e.setCurrentItem(item);
    36.  
    37. }
    38. }
    39. }
    40.  
    41. }
    42. }
    43. }
     
    Last edited by a moderator: Apr 9, 2020
  6. Offline

    timtower Administrator Administrator Moderator

    @Vex102 Are you getting two lores at the same time or on separate clicks?
     
  7. Offline

    Vex102

    Nvm it works now Thank you <3
     
Thread Status:
Not open for further replies.

Share This Page