mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-01 05:57:54 +01:00
Tweaks due to work on Challenges addon.
Enabled the overall panel listener to work.
This commit is contained in:
parent
023a68546c
commit
44ed33bb26
@ -1,7 +1,7 @@
|
||||
package us.tastybento.bskyblock.api.panels;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
|
||||
@ -12,11 +12,8 @@ public interface PanelListener {
|
||||
*/
|
||||
void setup();
|
||||
|
||||
/**
|
||||
* Called when the panel is clicked
|
||||
* @param user - the User
|
||||
* @param inventory
|
||||
* @param clicked
|
||||
*/
|
||||
void onInventoryClick(User user, Inventory inventory, ItemStack clicked);
|
||||
void onInventoryClose(InventoryCloseEvent event);
|
||||
|
||||
void onInventoryClick(User user, InventoryClickEvent event);
|
||||
|
||||
}
|
||||
|
@ -41,11 +41,12 @@ public class PanelListenerManager implements Listener {
|
||||
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()));
|
||||
});
|
||||
}
|
||||
}
|
||||
// If there is a listener, then run it.
|
||||
panel.getListener().ifPresent(l -> l.onInventoryClick(user, event));
|
||||
|
||||
} else {
|
||||
// Wrong name - delete this panel
|
||||
openPanels.remove(user.getUniqueId());
|
||||
@ -56,6 +57,8 @@ public class PanelListenerManager implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
if (openPanels.containsKey(event.getPlayer().getUniqueId())) {
|
||||
// Run any close inventory methods
|
||||
openPanels.get(event.getPlayer().getUniqueId()).getListener().ifPresent(l -> l.onInventoryClose(event));
|
||||
openPanels.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user