Closed Srar-Git closed 5 months ago
I see your confusion. The onClick event is called only for GUI clicks. Because other ones are not its responsibility. Using this method, you cannot cancel clicks on the player's inventory. You have to use the Bukkit event handlers. But do not be sad I didn't forget these scenarios.
You can listen events with 'GuiPreClickEvent
'. It gets triggered when players click on a GUI. It is a more permitted version of the onClick and it works like you think. You can cancel this event using event.setCancelled(true);
You can check if the clicked inventory is a GUI inventory or the player's inventory with: https://github.com/hamza-cskn/obliviate-invs/blob/c0f3a4423ed7e27fc0540c8ae3120a52e121db66/core/src/main/java/mc/obliviate/inventory/InvListener.java#L40
It is true when the player clicks on the Gui. You can use another way to check it if you know. Let me know if your issue is solved or not.
hi, thanks for help, I solved the problem by this code, directly cancel the GuiPreClickEvent
event not work, need cancel the InventoryClickEvent in GuiPreClickEvent, maybe you could add this to wiki?
@EventHandler
public void onPreClick(GuiPreClickEvent e) {
InventoryClickEvent event = e.getEvent();
e.getEvent().setCancelled(true);
}
I agree that it does not work as it looks. I'll think about it. I am glad to hear you've solved it. I am closing this issue.
I am using the
onClick()
method to listen when player click their own inventory, but it seems i can't cancel the InventoryClickEvent, is there anyway to cancel the player click their own inventory? this is my code for the event, thereturn false;
andevent.setCancelled(true);
not work.Checklist
Ensure you've done everything in this list before submitting the issue. (Just put the 'X' char between brackets.)