Solved How to stop people from putting specific items in GUI?

Discussion in 'Plugin Development' started by Tim_M, Aug 8, 2021.

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

    Tim_M

    At the moment I listen for InventoryClickEvent and check if the event.getCurrentItem has a specific name (like an item that opens options) we cancel the event. There are still ways to get the item in. For example: if you put your cursor over any empty slot in the GUI and press the number (on your keyboard) that corresponds with the slot the item is, the item will go into the GUI, and then it will become impossible to get it out. Any ideas?
     
  2. Offline

    rudraksha007

    umm,.. idk if there is any other way than just checking if the click was keyboard click and cancelling it right away coz i don't think it is possible to get the key that player pressed, but one other thing u can do is check if the player's inventory contains the item that u want not to be placed then only cancel the event
    If i m wrong, don't judge... i m not a pro developer :)
     
  3. Offline

    Tim_M

    Seems like a good idea. I'll try it right away.
    Edit:
    @rudraksha007 thank you for your response, however it wouldn't work, since I still want other items to be put in the GUI, just not the options one.
     
  4. Offline

    rudraksha007

    hold on!!! i said this:
    if(event.getClick().isKeyboardClick()){
    event.setCancelled(true);
    }
    now got it? they can't put by number keys but can by clicking or shift clicking
     
  5. Offline

    Tim_M

    Hmmmm. This would work, but for tryhards this might a bit inconvinient. If there's no other way then sure, I'll do it.
    Strange that keyboard clicks don't set the currentItem of the event

    EDIT:
    I just came up with a solution. I'll listen for InventoryCloseEvent, and if the item is in there it will be removed and given to the player. Marking Solved.
     
  6. Offline

    KarimAKL

    That is just a hotbar swap; it is pretty easy to fix.
    You can get the button pressed using #getHotbarButton(). It will return -1 if it is a normal click.
     
Thread Status:
Not open for further replies.

Share This Page