Solved InventoryClickEvent help

Discussion in 'Plugin Development' started by SmallDesk, Jan 6, 2018.

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

    SmallDesk

    So I am developing an RGP plugin, and I have a problem with item level requirements.
    So far, if an item has the lore "Level 70" and your EXP level is not 70, you can't drag the item into your armor slots. What you can do however is, you can ShiftClick the item into your armor slots or you can HotBar Swap them. Can anyone help me prevent that?

    Code:
    Code:
    @EventHandler
        public void onArmorEquip(InventoryClickEvent e) {
            if(e.getCursor().hasItemMeta()) {
                Player player = (Player) e.getWhoClicked();
                List<String> b = e.getCursor().getItemMeta().getLore();
                String str = ChatColor.stripColor(String.valueOf(b));
                if(str.contains("Level 70")){
                    if(player.getLevel() != 70){
                    e.setResult(Result.DENY);
                    player.sendMessage(ChatColor.RED + "You must be level 70 to equip that item!");
                }
            }
          
              
              
            }
    
              
            }
          
        {
    }
    }
    
    e.setCancelled(true); and e.setResult(Result.DENY); work the same for me.
     
    Last edited by a moderator: Jan 7, 2018
  2. Offline

    srspore

    Maybe check
    Code:
    if (event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT)
    and cancel the event if the other conditions are also met?
     
  3. Offline

    SmallDesk

    Hey! Thank you, I tried to do that, but now it does nothing.. lol if I do the e.getCursor.hasItemMeta(); it generates an NPE. Here is my current code for you to look at.

    Code:
    @EventHandler
        public void onArmorEquip(InventoryClickEvent e) {
            if (e.getClick() == ClickType.SHIFT_LEFT || e.getClick() == ClickType.SHIFT_RIGHT) {
                Player player = (Player) e.getWhoClicked();
                List<String> b = e.getCursor().getItemMeta().getLore();
                String str = ChatColor.stripColor(String.valueOf(b));
                if(str.contains("Level 70")){
                    if(player.getLevel() != 70){
                    e.setResult(Result.DENY);
                    player.sendMessage(ChatColor.RED + "You must be level 70 to equip that item!");
                }
            }
            }
            }
    
     
    Last edited by a moderator: Jan 9, 2018
  4. Online

    timtower Administrator Administrator Moderator

    @SmallDesk Because e.getCursor() can return null.
     
  5. Offline

    SmallDesk

    But what I have above is not working either. xp
    It doesn't return any error/exception but does nothing either.
     
  6. The code only gets triggered if you shift click now because
    it’s looking for etiher of those clicks to start it.
    You can simply put the code you had at the beginning after this check and it should work.
     
Thread Status:
Not open for further replies.

Share This Page