/**
   * Handle a command sent.
   *
   * @param cmd
   * @param sender
   * @param console
   */
  public void handleCommand(String cmd, CommandSender sender, boolean console) {

    // If we're banning someone, file it
    if (cmd.startsWith("/ban ")) {
      if (sender.hasPermission("essentials.ban")) {
        String[] args = cmd.split(" ");
        if (args.length >= 3) {
          String banned_player = args[1];
          String reason = "";
          for (int i = 2; i < args.length; i = i + 1) {
            reason += args[i] + " ";
          }
          BanUtil.recordBan(plugin, banned_player, sender.getName(), reason);
        }
      }
    }

    // Record unbans
    if (cmd.startsWith("/unban ") || cmd.startsWith("/pardon ")) {
      if (sender.hasPermission("essentials.unban")) {
        try {
          BanUtil.unban(cmd.split(" ")[1], plugin);
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }

    if (!console) {
      Player player = (Player) sender;
      // Log the location
      double x = Math.floor(player.getLocation().getX());
      double y = Math.floor(player.getLocation().getY());
      double z = Math.floor(player.getLocation().getZ());
      plugin.log(
          "[Command] "
              + player.getName()
              + " "
              + cmd
              + " @"
              + player.getWorld().getName()
              + " "
              + x
              + " "
              + y
              + " "
              + z);
    } else {
      plugin.log("[Command] " + "CONSOLE " + cmd);
    }
  }
  /**
   * Save the timestamp and player data upon the JOIN event
   *
   * @throws RankingException
   * @throws ParseException
   */
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerJoin(final PlayerJoinEvent event) throws RankingException, ParseException {

    Player player = event.getPlayer();
    String username = player.getName();
    String ip = player.getAddress().getAddress().getHostAddress().toString();

    // If the player is new, check if they've joined before
    Rank rank = RankUtil.getPlayerRank(plugin, username);
    if (rank.getCurrentRank() == UserGroup.Player) {

      if (!SeenUtil.hasPlayerBeenSeen(plugin, username)) {

        // Give them a guide book
        Guide.giveToPlayer(player);

        List<Alts> alt_accts = JoinUtil.getPlayerAlts(plugin, username, ip);
        if (!alt_accts.isEmpty()) {
          String alts_list = "";
          int i = 1;
          for (Alts alt : alt_accts) {
            try {
              if (BanUtil.isBanned(alt.username, plugin))
                alts_list += ChatColor.DARK_RED + "(BANNED)";
            } catch (SQLException e) {
              e.printStackTrace();
            }
            alts_list +=
                RankUtil.getPlayerRank(plugin, alt.username).getRankColor()
                    + alt.username
                    + (i == alt_accts.size() ? "" : ", ");
            i++;
          }
          for (Player pl : plugin.getServer().getOnlinePlayers()) {
            if (pl.hasPermission("dhmcstats.warn")) {
              pl.sendMessage(plugin.playerMsg(username + "'s alts: " + alts_list));
            }
          }
        }
      }
    }

    // Save join date
    java.util.Date date = new java.util.Date();
    String ts = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date.getTime());
    JoinUtil.registerPlayerJoin(plugin, username, ts, ip, plugin.getOnlineCount());

    if (rank.getPlayerQualifiesForPromo()) {

      // auto promote
      plugin
          .permissions
          .getUser(username)
          .promote(plugin.permissions.getUser("viveleroi"), "default");

      // announce the promotion
      plugin.messageAllPlayers(
          plugin.playerMsg(
              "Congratulations, "
                  + ChatColor.AQUA
                  + username
                  + ChatColor.WHITE
                  + " on your promotion to "
                  + ChatColor.AQUA
                  + rank.getNextRank().getNiceName()));

      // log the promotion
      plugin.log("Auto promoted " + username + " to " + rank.getNextRank().getNiceName());
    }

    // If the user has three or more warnings, alert staff
    WarningUtil.alertStaffOnWarnLimit(plugin, username);
  }