use of simplepets.brainsynder.menu.menuItems.base.MenuItemAbstract in project SimplePets by brainsynder-Dev.
the class DataListener method onClick.
@EventHandler
public void onClick(InventoryClickEvent e) {
if (e.getInventory().getHolder() == null)
return;
if (!(e.getInventory().getHolder() instanceof PetDataHolder))
return;
DataMenu menu = PetCore.get().getInvLoaders().PET_DATA;
if ((e.getWhoClicked() instanceof Player)) {
e.setCancelled(true);
e.setResult(Event.Result.DENY);
final Player p = (Player) e.getWhoClicked();
PetOwner owner = PetOwner.getPetOwner(p);
if (e.getCurrentItem() == null)
return;
if (e.getClick().isShiftClick()) {
e.setCancelled(true);
return;
}
Item item = PetCore.get().getItemLoaders().getLoader(e.getCurrentItem());
if (item != null) {
item.onClick(owner, menu);
return;
}
IStorage<MenuItem> menuItems = owner.getPet().getItems().copy();
if (!menuItems.isEmpty()) {
while (menuItems.hasNext()) {
MenuItemAbstract menuItem = (MenuItemAbstract) menuItems.next();
PetDataChangeEvent.ClickType type = PetDataChangeEvent.ClickType.LEFT_CLICK;
if (e.getClick().toString().toLowerCase().contains("right"))
type = PetDataChangeEvent.ClickType.RIGHT_CLICK;
if (menuItem.getItem().isSimilar(e.getCurrentItem())) {
PetDataChangeEvent event = new PetDataChangeEvent(menuItem, type);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (type == PetDataChangeEvent.ClickType.LEFT_CLICK) {
menuItem.onLeftClick();
e.getInventory().setItem(e.getSlot(), menuItem.getItem().build());
} else {
menuItem.onRightClick();
e.getInventory().setItem(e.getSlot(), menuItem.getItem().build());
}
e.getInventory().setItem(e.getSlot(), menuItem.getItem().build());
}
e.setCancelled(true);
return;
}
}
}
}
}
Aggregations