PanelsAPI - Fixed ambiguous logic with the cancellation of the clickevent

This commit is contained in:
Florian CUNY 2018-01-01 00:55:53 +01:00
parent 5ea46aea29
commit 131a8affca
2 changed files with 6 additions and 8 deletions

View File

@ -88,7 +88,7 @@ public class PanelItem {
* This is executed when the icon is clicked * This is executed when the icon is clicked
* @param user * @param user
* @param click * @param click
* @return false if the event should be cancelled * @return true if the click event should be cancelled
*/ */
boolean onClick(User user, ClickType click); boolean onClick(User user, ClickType click);
} }

View File

@ -39,13 +39,11 @@ public class PanelListenerManager implements Listener {
// Check that they left clicked on it // Check that they left clicked on it
// TODO: in the future, we may want to support right clicking // TODO: in the future, we may want to support right clicking
if (panel.getItems().get(slot).getClickHandler().isPresent()) { if (panel.getItems().get(slot).getClickHandler().isPresent()) {
if(!panel.getItems().get(slot).getClickHandler().get().onClick(user, ClickType.LEFT)) { // Cancel the event if true was returned by the ClickHandler
event.setCancelled(true); event.setCancelled(panel.getItems().get(slot).getClickHandler().get().onClick(user, ClickType.LEFT));
} else { // If there is a listener, then run it.
// If there is a listener, then run it. if (panel.getListener().isPresent()) {
if (panel.getListener().isPresent()) { panel.getListener().get().onInventoryClick(user, inventory, event.getCurrentItem());
panel.getListener().get().onInventoryClick(user, inventory, event.getCurrentItem());
}
} }
} }
} }