mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 10:45:22 +01:00
Check if Optional click handler exists before getting it.
This commit is contained in:
parent
2c1d52761f
commit
d2098c3dbe
@ -38,12 +38,12 @@ public class PanelListenerManager implements Listener {
|
||||
if (slot == event.getRawSlot()) {
|
||||
// Check that they left clicked on it
|
||||
// TODO: in the future, we may want to support right clicking
|
||||
if (panel.getItems().get(slot).getClickHandler().isPresent()) {
|
||||
// Cancel the event if true was returned by the ClickHandler
|
||||
event.setCancelled(panel.getItems().get(slot).getClickHandler().get().onClick(user, ClickType.LEFT));
|
||||
panel.getItems().get(slot).getClickHandler().ifPresent(handler -> {
|
||||
// Execute the handler's onClick method and optionally cancel the event if the handler returns true
|
||||
event.setCancelled(handler.onClick(user, ClickType.LEFT));
|
||||
// If there is a listener, then run it.
|
||||
panel.getListener().ifPresent(l -> l.onInventoryClick(user, inventory, event.getCurrentItem()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user