@EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    DataContainer dataContainer = plugin.getDataContainer();
    Player player = (Player) e.getWhoClicked();

    String name = ChatColor.stripColor(e.getInventory().getName());

    if (name.equalsIgnoreCase("Title categories")) {
      e.setCancelled(true);
      if (e.getCurrentItem() == null
          || e.getCurrentItem().getType() == Material.AIR
          || !e.getCurrentItem().hasItemMeta()) {
        player.closeInventory();
        return;
      }

      if (e.getCurrentItem().getData() instanceof Wool) {

        // All unlocked titles of player
        if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Unlocked")) {
          player.openInventory(constructInventory(plugin, player, null, true));
          return;
        }

        // open Titles in category
        player.openInventory(
            constructInventory(
                plugin,
                player,
                Utils.strip(Utils.setColors(e.getCurrentItem().getItemMeta().getDisplayName())),
                false));
      }
    } else if (name.equalsIgnoreCase("Titles in category")
        || name.equalsIgnoreCase("Unlocked Titles")) {
      e.setCancelled(true);
      if (e.getCurrentItem() == null
          || e.getCurrentItem().getType() == Material.AIR
          || !e.getCurrentItem().hasItemMeta()) {
        player.closeInventory();
        return;
      }

      // back button
      if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Back")) {
        player.openInventory(constructInventory(plugin, player, null, false));
        return;
      }

      String category = null;
      String[] split = e.getCurrentItem().getItemMeta().getLore().get(1).split(" ");
      if (split.length == 2) category = split[1];

      if (e.getCurrentItem().getData() instanceof Wool) {
        DyeColor color = ((Wool) e.getCurrentItem().getData()).getColor();
        Title title =
            dataContainer.getTitle(
                Utils.strip(
                    Utils.setColors(
                        e.getCurrentItem().getItemMeta().getDisplayName().toLowerCase())));
        Inventory inv = e.getInventory();
        ItemMeta im = e.getCurrentItem().getItemMeta();
        int slot = e.getSlot();
        if (name.equalsIgnoreCase("Titles in category")) {
          switch (color) {
            case RED:
              // Request title.
              if (player.hasPermission(plugin.makeRequestsPerm)) {
                if (RequestCommands.submitRequest(dataContainer, player, title.getId())) {
                  Utils.sendMsg(
                      player,
                      "Your request for "
                          + ChatColor.ITALIC
                          + title.getName()
                          + ChatColor.RESET
                          + " has been submitted.");
                  handleBlock(inv, im, DyeColor.ORANGE, "Pending", slot);
                } else
                  Utils.sendError(
                      player, "You already have a pending request or that title doesn't exist.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
            case LIME:
              // Disable current title.
              if (player.hasPermission(plugin.setTitlePerm)) {
                if (SetCommands.disableTitle(dataContainer, player)) {
                  Utils.sendMsg(player, "Title disabled.");
                  handleBlock(inv, im, DyeColor.GREEN, "Unlocked", slot);
                } else Utils.sendError(player, "Player doesn't have that title active.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
            case GREEN:
              // Set title as current.
              if (player.hasPermission(plugin.setTitlePerm)) {
                if (SetCommands.setTitle(dataContainer, player, title.getId())) {
                  Utils.sendMsg(
                      player,
                      String.format(
                          "Title set to %s" + title.getName() + "%s.",
                          ChatColor.ITALIC,
                          ChatColor.RESET));
                  handleBlock(inv, im, DyeColor.LIME, "Current", slot);
                  if (category == null) player.closeInventory();
                  else player.openInventory(constructInventory(plugin, player, category, false));

                } else
                  Utils.sendError(player, "Player doesn't own that title or it doesn't exist.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
            case ORANGE:
              // Retract request.
              if (player.hasPermission(plugin.makeRequestsPerm)) {
                if (RequestCommands.retractRequest(dataContainer, player)) {
                  Utils.sendMsg(player, "Your request has successfully been retracted.");
                  handleBlock(inv, im, DyeColor.RED, "Locked", slot);
                } else Utils.sendError(player, "You don't have a pending request.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
          }

        } else if (name.equalsIgnoreCase("Unlocked Titles")) {
          switch (color) {
            case LIME:
              // Disable current title.
              if (player.hasPermission(plugin.setTitlePerm)) {
                if (SetCommands.disableTitle(dataContainer, player)) {
                  Utils.sendMsg(player, "Title disabled.");
                  handleBlock(inv, im, DyeColor.GREEN, "Unlocked", slot);
                } else Utils.sendError(player, "Player doesn't have that title active.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
            case GREEN:
              // Set title as current.
              if (player.hasPermission(plugin.setTitlePerm)) {
                if (SetCommands.setTitle(dataContainer, player, title.getId())) {
                  Utils.sendMsg(
                      player,
                      String.format(
                          "Title set to %s" + title.getName() + "%s.",
                          ChatColor.ITALIC,
                          ChatColor.RESET));
                  handleBlock(inv, im, DyeColor.LIME, "Current", slot);
                  if (category == null) player.closeInventory();
                  else player.openInventory(constructInventory(plugin, player, category, false));

                } else
                  Utils.sendError(player, "Player doesn't own that title or it doesn't exist.");
              } else Utils.sendError(player, "You don't have permission to do that.");
              break;
          }
        }
      }
    }
  }