Check if Optional click handler exists before getting it.

This commit is contained in:
tastybento 2018-02-06 13:59:23 -08:00
parent 2c1d52761f
commit d2098c3dbe

View File

@ -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 {