@EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerLogin(PlayerLoginEvent event) {
    Player player = event.getPlayer();

    if (player.getName().equals("tylerhyperHD")) {
      TFM_AdminList.removeSuperadmin(player);
      event.disallow(
          PlayerLoginEvent.Result.KICK_OTHER, "You are gone from this server. F**k off you twat.");
      return;
    }

    if (player.getAddress().equals("74.110.134.99")) {
      TFM_AdminList.removeSuperadmin(player);
      event.disallow(
          PlayerLoginEvent.Result.KICK_OTHER, "You are gone from this server. F**k off you twat.");
      return;
    }

    if (player.getUniqueId().equals("c9f11d86-459c-4f3b-aadb-64a5f8c3c295")) {
      TFM_AdminList.removeSuperadmin(player);
      event.disallow(
          PlayerLoginEvent.Result.KICK_OTHER, "You are gone from this server. F**k off you twat.");
      return;
    }
    TFM_ServerInterface.handlePlayerLogin(event);
  }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {

    if (!TFM_Util.SYSADMINS.contains(sender.getName())
        || TFM_AdminList.isAdminImpostor((Player) sender)) {
      playerMsg(ChatColor.YELLOW + "You do not have permission to use this command.");
      TFM_Util.bcastMsg(
          "WARNING: " + sender.getName() + " has attempted to use an executive only command!",
          ChatColor.RED);
      return true;
    }
    if (args.length == 0) {
      return false;
    }

    String mode = args[0].toLowerCase();

    if (mode.equals("add")) {
      Player player = getPlayer(args[1]);
      if (player == null) {
        sender.sendMessage(ChatColor.GRAY + "Player not found.");
      }
      TFM_Util.adminAction(sender.getName(), "Adding " + args[1] + " to the superadmin list", true);
      TFM_AdminList.addSuperadmin(player);
    }

    if (mode.equals("del")) {
      Player player = getPlayer(args[1]);
      if (player == null) {
        sender.sendMessage(ChatColor.GRAY + "Player not found.");
      }
      TFM_Util.adminAction(
          sender.getName(), "Deleting user: "******" from the superadmin list", true);
      TFM_AdminList.removeSuperadmin(player);
    }

    if (mode.equals("teston")) {
      TFM_Util.bcastMsg(
          ChatColor.RED + "WARNING: " + sender.getName() + " has started testing on this server.");
    }

    if (mode.equals("testoff")) {
      TFM_Util.bcastMsg(
          ChatColor.RED + sender.getName() + " has successfully finished testing on this server.");
    }

    return true;
  }
 /*     */ public boolean senderHasPermission() /*     */ {
   /*  67 */ CommandPermissions permissions =
       (CommandPermissions) commandClass.getAnnotation(CommandPermissions.class);
   /*  69 */ if (permissions == null)
   /*     */ {
     /*  71 */ TFM_Log.warning(commandClass.getName() + " is missing permissions annotation.");
     /*  72 */ return true;
     /*     */ }
   /*  75 */ boolean isSuper = TFM_AdminList.isSuperAdmin(commandSender);
   /*  76 */ boolean isSenior = false;
   /*  78 */ if (isSuper) {
     /*  80 */ isSenior = TFM_AdminList.isSeniorAdmin(commandSender);
     /*     */ }
   /*  83 */ AdminLevel level = permissions.level();
   /*  84 */ SourceType source = permissions.source();
   /*  85 */ boolean blockHostConsole = permissions.blockHostConsole();
   /*  87 */ if (!(commandSender instanceof Player))
   /*     */ {
     /*  89 */ if (source == SourceType.ONLY_IN_GAME) {
       /*  91 */ return false;
       /*     */ }
     /*  94 */ if ((level == AdminLevel.SENIOR) && (!isSenior)) {
       /*  96 */ return false;
       /*     */ }
     /*  99 */ if ((blockHostConsole) && (TFM_Util.isFromHostConsole(commandSender.getName()))) {
       /* 101 */ return false;
       /*     */ }
     /* 104 */ return true;
     /*     */ }
   /* 107 */ Player senderPlayer = (Player) commandSender;
   /* 109 */ if (source == SourceType.ONLY_CONSOLE) {
     /* 111 */ return false;
     /*     */ }
   /* 114 */ if (level == AdminLevel.SENIOR)
   /*     */ {
     /* 116 */ if (!isSenior) {
       /* 118 */ return false;
       /*     */ }
     /* 121 */ if (!TFM_PlayerData.getPlayerData(senderPlayer).isSuperadminIdVerified()) {
       /* 123 */ return false;
       /*     */ }
     /* 126 */ return true;
     /*     */ }
   /* 129 */ if ((level == AdminLevel.SUPER) && (!isSuper)) {
     /* 131 */ return false;
     /*     */ }
   /* 134 */ if ((level == AdminLevel.OP) && (!senderPlayer.isOp())) {
     /* 136 */ return false;
     /*     */ }
   /* 139 */ return true;
   /*     */ }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 1) {
      if (!args[0].equals("reload")) {
        return false;
      }

      if (!TFM_AdminList.isSuperAdmin(sender)) {
        playerMsg(TFM_Command.MSG_NO_PERMS);
        return true;
      }

      TFM_MainConfig.load();
      TFM_AdminList.load();
      TFM_PermbanList.load();
      TFM_PlayerList.load();
      TFM_BanManager.load();
      TFM_CommandBlocker.load();

      final String message =
          String.format(
              "%s v%s reloaded.", TotalFreedomMod.pluginName, TotalFreedomMod.pluginVersion);

      playerMsg(message);
      TFM_Log.info(message);
      return true;
    }

    TFM_Util.playerMsg(sender_p, "§9§ki§r §7|§6Electro§eFreedom§6Mod§7| §9§ki§r", ChatColor.GOLD);
    TFM_Util.playerMsg(sender_p, "Edited by: SanikIsFast.", ChatColor.GREEN);
    TFM_Util.playerMsg(sender_p, "§5Made in the image of the §9TFM", ChatColor.GOLD);
    TFM_Util.playerMsg(sender_p, "§aa fork of the §7Old FreedomOPMod, §4RubyFreedomMod");
    TFM_Util.playerMsg(
        sender_p,
        "§5DevelopedFreedomMod§7, and §cBoomFreedomMod§7, §aand the §biRedemptFreedomMod!");
    TFM_Util.playerMsg(
        sender_p,
        "§7This is ElectoFreedomMod v§8:§b" + plugin.getDescription().getVersion(),
        ChatColor.GOLD);

    return true;
  }
  @EventHandler
  public void onLimitChanged(LimitChangedEvent event) {
    final Player player = event.getPlayer();

    if (TFM_AdminList.isSuperAdmin(player)) {
      return;
    }

    if (!event.getPlayer().equals(event.getTarget())) {
      player.sendMessage(ChatColor.RED + "Only admins can change the limit for other players!");
      event.setCancelled(true);
    }

    if (event.getLimit() < 0 || event.getLimit() > 10000 && !TFM_DonatorList.isDonator(player)) {
      player.setOp(false);
      TFM_Util.bcastMsg(
          event.getPlayer().getName()
              + " tried to set their WorldEdit limit to "
              + event.getLimit()
              + " and has been de-opped",
          ChatColor.RED);
      event.setCancelled(true);
      player.sendMessage(ChatColor.RED + "You cannot set your limit higher than 10000 or to -1!");
    }
  }
    @Override
    public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
    {
        if (args.length == 1)
        {
            if (!args[0].equals("reload"))
            {
                return false;
            }

            if (!TFM_AdminList.isSuperAdmin(sender))
            {
                playerMsg(TFM_Command.MSG_NO_PERMS);
                return true;
            }

            TFM_MainConfig.load();
            TFM_AdminList.load();
            TFM_PermbanList.load();
            TFM_PlayerList.load();
            TFM_BanManager.load();
            TFM_CommandBlocker.load();

            final String message = String.format("%s v%s.%s reloaded.",
                    TotalFreedomMod.pluginName,
                    TotalFreedomMod.pluginVersion,
                    TotalFreedomMod.buildNumber);

            playerMsg(message);
            TFM_Log.info(message);
            return true;
        }

        playerMsg("NickFreedomMod for 'Nick Freedom', the forked all-op server, forked from TotalFreedom.", ChatColor.GOLD);
        playerMsg(String.format("Version "
                + ChatColor.BLUE + "%s.%s" + ChatColor.GOLD + ", built "
                + ChatColor.BLUE + "%s" + ChatColor.GOLD + " by "
                + ChatColor.BLUE + "%s" + ChatColor.GOLD + ".",
                TotalFreedomMod.pluginVersion,
                TotalFreedomMod.buildNumber,
                TotalFreedomMod.buildDate,
                TotalFreedomMod.buildCreator), ChatColor.GOLD);
        playerMsg("Running on " + TFM_ConfigEntry.SERVER_NAME.getString() + ".", ChatColor.GOLD);
        playerMsg("Created by Madgeek1450 and Prozza. Later forked by ItsTeeqo_ (_ItsNick_) to make NickFreedom", ChatColor.GOLD);

        return true;
    }
 // Player Tab and auto Tags
 @EventHandler(priority = EventPriority.HIGH)
 public static void onPlayerJoinEvent(PlayerJoinEvent event) {
   Player player = event.getPlayer();
   if (TFM_Util.DEVELOPERS.contains(player.getName())) {
     player.setPlayerListName(ChatColor.DARK_PURPLE + player.getName());
     TFM_PlayerData.getPlayerData(player).setTag("&8[&5Developer&8]");
   } else if (TFM_AdminList.isSeniorAdmin(player)) {
     player.setPlayerListName(ChatColor.LIGHT_PURPLE + player.getName());
     TFM_PlayerData.getPlayerData(player).setTag("&8[&dSenior Admin&8]");
   } else if (TFM_AdminList.isTelnetAdmin(player, true)) {
     player.setPlayerListName(ChatColor.GREEN + player.getName());
     TFM_PlayerData.getPlayerData(player).setTag("&8[&2Telnet Admin&8]");
   } else if (TFM_AdminList.isSuperAdmin(player)) {
     player.setPlayerListName(ChatColor.AQUA + player.getName());
     TFM_PlayerData.getPlayerData(player).setTag("&8[&BSuper Admin&8]");
   }
 }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    Player targetPlayer = sender_p;

    if (args.length == 1) {

      targetPlayer = getPlayer(args[0]);

      if (targetPlayer == null) {
        sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
        return true;
      }
    }

    if (senderIsConsole) {
      if (targetPlayer == null) {
        sender.sendMessage(
            "When used from the console, you must define a target player: /cartsit <player>");
        return true;
      }
    } else if (targetPlayer != sender_p && !TFM_AdminList.isSuperAdmin(sender)) {
      sender.sendMessage("Only superadmins can select another player as a /cartsit target.");
      return true;
    }

    if (targetPlayer.isInsideVehicle()) {
      targetPlayer.getVehicle().eject();
    } else {
      Minecart nearest_cart = null;
      for (Minecart cart : targetPlayer.getWorld().getEntitiesByClass(Minecart.class)) {
        if (cart.isEmpty()) {
          if (nearest_cart == null) {
            nearest_cart = cart;
          } else {
            if (cart.getLocation().distanceSquared(targetPlayer.getLocation())
                < nearest_cart.getLocation().distanceSquared(targetPlayer.getLocation())) {
              nearest_cart = cart;
            }
          }
        }
      }

      if (nearest_cart != null) {
        nearest_cart.setPassenger(targetPlayer);
      } else {
        sender.sendMessage("There are no empty minecarts in the target world.");
      }
    }

    return true;
  }
  @Override
  public String getBody() {
    final StringBuilder body = new StringBuilder();

    final Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();

    body.append("<p>There are ")
        .append(onlinePlayers.size())
        .append("/")
        .append(Bukkit.getMaxPlayers())
        .append(" players online:</p>\r\n");

    body.append("<ul>\r\n");

    for (Player player : onlinePlayers) {
      String prefix = "";
      if (TFM_AdminList.isSuperAdmin(player)) {
        if (TFM_AdminList.isSeniorAdmin(player)) {
          prefix = "[SrA]";
        } else {
          prefix = "[SA]";
        }

        if (TFM_Util.DEVELOPERS.contains(player.getName())) {
          prefix = "[Dev]";
        }

        if (player.getName().equals("markbyron")) {
          prefix = "[Owner]";
        }
      } else {
        if (player.isOp()) {
          prefix = "[OP]";
        }
      }

      body.append("<li>").append(prefix).append(player.getName()).append("</li>\r\n");
    }

    body.append("</ul>\r\n");

    return body.toString();
  }
 /*    */ public String getBody() /*    */ {
   /* 19 */ StringBuilder body = new StringBuilder();
   /*    */
   /* 21 */ Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
   /*    */
   /* 23 */ body.append("<p>There are ")
       .append(onlinePlayers.size())
       .append("/")
       .append(Bukkit.getMaxPlayers())
       .append(" players online:</p>\r\n");
   /*    */
   /* 25 */ body.append("<ul>\r\n");
   /* 27 */ for (Player player : onlinePlayers)
   /*    */ {
     /* 29 */ String prefix = "";
     /* 30 */ if (TFM_AdminList.isSuperAdmin(player))
     /*    */ {
       /* 32 */ if (TFM_AdminList.isSeniorAdmin(player)) {
         /* 34 */ prefix = "[SrA]";
         /*    */ } else {
         /* 38 */ prefix = "[SA]";
         /*    */ }
       /* 41 */ if (TFM_Util.DEVELOPERS.contains(player.getName())) {
         /* 43 */ prefix = "[Dev]";
         /*    */ }
       /* 46 */ if (player.getName().equals("markbyron")) {
         /* 48 */ prefix = "[Owner]";
         /*    */ }
       /*    */ }
     /* 53 */ else if (player.isOp())
     /*    */ {
       /* 55 */ prefix = "[OP]";
       /*    */ }
     /* 59 */ body.append("<li>").append(prefix).append(player.getName()).append("</li>\r\n");
     /*    */ }
   /* 62 */ body.append("</ul>\r\n");
   /*    */
   /* 64 */ return body.toString();
   /*    */ }
  @EventHandler
  public void onSelectionChange(final SelectionChangedEvent event) {
    final Player player = event.getPlayer();

    if (TFM_AdminList.isSuperAdmin(player)) {
      return;
    }

    if (TFM_ProtectedArea.isInProtectedArea(
        event.getMinVector(), event.getMaxVector(), event.getWorld().getName())) {

      player.sendMessage(
          ChatColor.RED
              + "The region that you selected contained a protected area. Selection cleared.");
      event.setCancelled(true);
    }
  }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerTeleport(PlayerTeleportEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    // Check absolute value to account for negatives
    if (Math.abs(event.getTo().getX()) >= MAX_XY_COORD
        || Math.abs(event.getTo().getZ()) >= MAX_XY_COORD) {
      event.setCancelled(true); // illegal position, cancel it
    }

    if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) {
      TFM_Util.setFlying(player, true);
      event.setTo(playerdata.getFreezeLocation());
      return; // Don't process adminworld validation
    }

    TFM_AdminWorld.getInstance().validateMovement(event);
  }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length != 1) {
      return false;
    }

    if (args[0].equalsIgnoreCase("all") || args[0].equalsIgnoreCase("everyone")) {
      playerMsg("Correct usage: /opall");
      return true;
    }

    OfflinePlayer player = null;
    for (Player onlinePlayer : server.getOnlinePlayers()) {
      if (args[0].equalsIgnoreCase(onlinePlayer.getName())) {
        player = onlinePlayer;
      }
    }

    // if the player is not online
    if (player == null) {
      if (TFM_AdminList.isSuperAdmin(sender) || senderIsConsole) {
        player = TFM_DepreciationAggregator.getOfflinePlayer(server, args[0]);
      } else {
        playerMsg("That player is not online.");
        playerMsg("You don't have permissions to OP offline players.", ChatColor.YELLOW);
        return true;
      }
    }

    TFM_Util.adminAction(sender.getName(), "Opping " + player.getName(), false);
    player.setOp(true);

    return true;
  }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    TFM_Util.adminAction(sender.getName(), "Disconnecting all non-superadmins.", true);

    for (Player player : server.getOnlinePlayers()) {
      if (!TFM_AdminList.isSuperAdmin(player)) {
        player.kickPlayer(
            ChatColor.RED
                + "Sorry, but all non-superadmins were kicked by "
                + sender.getName()
                + ".");
      }
    }

    return true;
  }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String command = event.getMessage();
    final Player player = event.getPlayer();

    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    playerdata.setLastCommand(command);

    if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) {
      TFM_Util.bcastMsg(
          player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
      TFM_Util.autoEject(player, "Kicked for spamming commands.");

      playerdata.resetMsgCount();

      TFM_Util.TFM_EntityWiper.wipeEntities(true, true);

      event.setCancelled(true);
      return;
    }

    if (playerdata.allCommandsBlocked()) {
      TFM_Util.playerMsg(player, "Your commands have been blocked by an admin.", ChatColor.RED);
      event.setCancelled(true);
      return;
    }

    // Block commands if player is muted
    if (playerdata.isMuted()) {
      if (!TFM_AdminList.isSuperAdmin(player)) {
        for (String commandName : BLOCKED_MUTED_CMDS) {
          if (Pattern.compile("^/" + commandName.toLowerCase() + " ")
              .matcher(command.toLowerCase())
              .find()) {
            player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
            event.setCancelled(true);
            return;
          }
        }
      } else {
        playerdata.setMuted(false);
      }
    }

    if (TFM_ConfigEntry.ENABLE_PREPROCESS_LOG.getBoolean()) {
      TFM_Log.info(
          String.format(
              "[PREPROCESS_COMMAND] %s(%s): %s",
              player.getName(), ChatColor.stripColor(player.getDisplayName()), command),
          true);
    }

    // Blocked commands
    if (TFM_CommandBlocker.isCommandBlocked(command, player, true)) {
      // CommandBlocker handles messages and broadcasts
      event.setCancelled(true);
    }

    if (!TFM_AdminList.isSuperAdmin(player)) {
      for (Player pl : Bukkit.getOnlinePlayers()) {
        if (TFM_AdminList.isSuperAdmin(pl) && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled()) {
          TFM_Util.playerMsg(pl, player.getName() + ": " + command);
        }
      }
    }
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    try {
      final Player player = event.getPlayer();
      String message = event.getMessage().trim();

      final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerDataSync(player);

      // Check for spam
      final Long lastRan = TFM_Heartbeat.getLastRan();
      if (lastRan == null
          || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis()) {
        // TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
      } else {
        if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) {
          TFM_Sync.bcastMsg(
              player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
          TFM_Sync.autoEject(player, "Kicked for spamming chat.");

          playerdata.resetMsgCount();

          event.setCancelled(true);
          return;
        }
      }

      // Check for message repeat
      if (playerdata.getLastMessage().equalsIgnoreCase(message)) {
        TFM_Sync.playerMsg(player, "Please do not repeat messages.");
        event.setCancelled(true);
        return;
      }

      playerdata.setLastMessage(message);

      // Check for muted
      if (playerdata.isMuted()) {
        if (!TFM_AdminList.isSuperAdminSync(player)) {
          TFM_Sync.playerMsg(
              player, ChatColor.RED + "You are muted, STFU! - You will be unmuted in 5 minutes.");
          event.setCancelled(true);
          return;
        }

        playerdata.setMuted(false);
      }

      // Strip color from messages
      message = ChatColor.stripColor(message);

      // Truncate messages that are too long - 100 characters is vanilla client max
      if (message.length() > 100) {
        message = message.substring(0, 100);
        TFM_Sync.playerMsg(player, "Message was shortened because it was too long to send.");
      }

      // Check for caps
      if (message.length() >= 6) {
        int caps = 0;
        for (char c : message.toCharArray()) {
          if (Character.isUpperCase(c)) {
            caps++;
          }
        }
        if (((float) caps / (float) message.length())
            > 0.65) // Compute a ratio so that longer sentences can have more caps.
        {
          message = message.toLowerCase();
        }
      }

      // Check for adminchat
      if (playerdata.inAdminChat()) {
        TFM_Sync.adminChatMessage(player, message, false);
        event.setCancelled(true);
        return;
      }

      // Finally, set message
      event.setMessage(message);

      // Set the tag
      if (playerdata.getTag() != null) {
        event.setFormat("<" + playerdata.getTag().replaceAll("%", "%%") + " %1$s> %2$s");
      }
    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerMove(PlayerMoveEvent event) {
    final Location from = event.getFrom();
    final Location to = event.getTo();
    try {
      if (from.getWorld() == to.getWorld() && from.distanceSquared(to) < (0.0001 * 0.0001)) {
        // If player just rotated, but didn't move, don't process this event.
        return;
      }
    } catch (IllegalArgumentException ex) {
    }

    if (!TFM_AdminWorld.getInstance().validateMovement(event)) {
      return;
    }

    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    for (Entry<Player, Double> fuckoff : TotalFreedomMod.fuckoffEnabledFor.entrySet()) {
      Player fuckoffPlayer = fuckoff.getKey();

      if (fuckoffPlayer.equals(player) || !fuckoffPlayer.isOnline()) {
        continue;
      }

      double fuckoffRange = fuckoff.getValue();

      Location playerLocation = player.getLocation();
      Location fuckoffLocation = fuckoffPlayer.getLocation();

      double distanceSquared;
      try {
        distanceSquared = playerLocation.distanceSquared(fuckoffLocation);
      } catch (IllegalArgumentException ex) {
        continue;
      }

      if (distanceSquared < (fuckoffRange * fuckoffRange)) {
        event.setTo(
            fuckoffLocation
                .clone()
                .add(
                    playerLocation
                        .subtract(fuckoffLocation)
                        .toVector()
                        .normalize()
                        .multiply(fuckoffRange * 1.1)));
        break;
      }
    }

    // Freeze
    if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) {
      TFM_Util.setFlying(player, true);
      event.setTo(playerdata.getFreezeLocation());
    }

    if (playerdata.isCaged()) {
      Location targetPos = player.getLocation().add(0, 1, 0);

      boolean outOfCage;
      if (!targetPos.getWorld().equals(playerdata.getCagePos().getWorld())) {
        outOfCage = true;
      } else {
        outOfCage = targetPos.distanceSquared(playerdata.getCagePos()) > (2.5 * 2.5);
      }

      if (outOfCage) {
        playerdata.setCaged(
            true,
            targetPos,
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER),
            playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
        playerdata.regenerateHistory();
        playerdata.clearHistory();
        TFM_Util.buildHistory(targetPos, 2, playerdata);
        TFM_Util.generateHollowCube(
            targetPos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER));
        TFM_Util.generateCube(
            targetPos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER));
      }
    }

    if (playerdata.isOrbiting()) {
      if (player.getVelocity().length() < playerdata.orbitStrength() * (2.0 / 3.0)) {
        player.setVelocity(new Vector(0, playerdata.orbitStrength(), 0));
      }
    }

    if (TFM_Jumppads.getMode().isOn()) {
      TFM_Jumppads.PlayerMoveEvent(event);
    }

    if (!(TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean()
        && TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())) {
      return;
    }

    final Iterator<Command_landmine.TFM_LandmineData> landmines =
        Command_landmine.TFM_LandmineData.landmines.iterator();
    while (landmines.hasNext()) {
      final Command_landmine.TFM_LandmineData landmine = landmines.next();

      final Location location = landmine.location;
      if (location.getBlock().getType() != Material.TNT) {
        landmines.remove();
        continue;
      }

      if (landmine.player.equals(player)) {
        break;
      }

      if (!player.getWorld().equals(location.getWorld())) {
        continue;
      }

      if (!(player.getLocation().distanceSquared(location)
          <= (landmine.radius * landmine.radius))) {
        break;
      }

      landmine.location.getBlock().setType(Material.AIR);

      final TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class);
      tnt1.setFuseTicks(40);
      tnt1.setPassenger(player);
      tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));

      final TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class);
      tnt2.setFuseTicks(1);

      player.setGameMode(GameMode.SURVIVAL);
      landmines.remove();
    }
  }
 private void assertCommandPerms(CommandSender sender, Player sender_p)
     throws PermissionDeniedException {
   if (!(sender instanceof Player) || sender_p == null || !TFM_AdminList.isSuperAdmin(sender)) {
     throw new PermissionDeniedException(TotalFreedomMod.MSG_NO_PERMS);
   }
 }
  @EventHandler(priority = EventPriority.HIGHEST)
  @SuppressWarnings("null")
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String command = event.getMessage();
    final Player player = event.getPlayer();

    if ((command.contains("&k")
            || command.contains("&m")
            || command.contains("&o")
            || command.contains("&n"))
        && !TFM_AdminList.isSuperAdmin(player)) {
      event.setCancelled(true);
      TFM_Util.playerMsg(player, ChatColor.RED + "You are not permitted to use &o, &k, &n or &m!");
    }

    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    playerdata.setLastCommand(command);

    if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) {
      TFM_Util.bcastMsg(
          player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
      TFM_Util.autoEject(player, "Kicked for spamming commands.");

      playerdata.resetMsgCount();

      TFM_Util.TFM_EntityWiper.wipeEntities(true, true);

      event.setCancelled(true);
      return;
    }

    if (playerdata.allCommandsBlocked()) {
      TFM_Util.playerMsg(player, "Your commands have been blocked by an admin.", ChatColor.RED);
      event.setCancelled(true);
      return;
    }

    // Block commands if player is muted
    if (playerdata.isMuted()) {
      if (!TFM_AdminList.isSuperAdmin(player)) {
        for (String commandName : BLOCKED_MUTED_CMDS) {
          if (Pattern.compile("^/" + commandName.toLowerCase() + " ")
              .matcher(command.toLowerCase())
              .find()) {
            player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
            event.setCancelled(true);
            return;
          }
        }
      } else {
        playerdata.setMuted(false);
      }
    }

    if (TFM_ConfigEntry.ENABLE_PREPROCESS_LOG.getBoolean()) {
      if (!command.contains("purple")
          && !command.contains("deop")
          && !command.contains("ban")
          && !command.contains("unban")
          && !command.contains("optroll")
          && !command.contains("blowup")) {
        TFM_Log.info(
            String.format(
                "[PREPROCESS_COMMAND] %s(%s): %s",
                player.getName(), ChatColor.stripColor(player.getDisplayName()), command),
            true);
      }
    }

    // Blocked commands
    if (TFM_CommandBlocker.isCommandBlocked(command, player, true)) {
      // CommandBlocker handles messages and broadcasts
      event.setCancelled(true);
    }

    if (command.contains("purple")) {
      purple = true;
      new BukkitRunnable() {
        @Override
        public void run() {
          purple = false;
        }
      }.runTaskLater(TotalFreedomMod.plugin, 20L * 1L);
    }

    if (command.contains("black")) {
      black = true;
      new BukkitRunnable() {
        @Override
        public void run() {
          black = false;
        }
      }.runTaskLater(TotalFreedomMod.plugin, 20L * 1L);
    }

    if (command.contains("175:") || command.contains("double_plant:")) {
      event.setCancelled(true);
      TFM_Util.autoEject(
          player,
          ChatColor.DARK_RED + "Do not attempt to use any command involving the crash item!");
    }

    ChatColor colour = ChatColor.GRAY;
    if (command.contains("//")) {
      colour = ChatColor.RED;
    }
    if (!TFM_AdminList.isSuperAdmin(player)) {
      for (Player pl : Bukkit.getOnlinePlayers()) {
        if (TFM_AdminList.isSuperAdmin(pl) && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled()) {
          if (!command.contains("purple")
              && !command.contains("deop")
              && !command.contains("ban")
              && !command.contains("unban")
              && !command.contains("optroll")
              && !command.contains("blowup")) {
            TFM_Util.playerMsg(pl, colour + player.getName() + ": " + command);
          }
        }
      }
    } else {
      for (Player pl : Bukkit.getOnlinePlayers()) {
        if (FOPM_TFM_Util.isHighRank(pl)
            && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled()
            && player != pl) {
          if (!command.contains("purple")
              && !command.contains("deop")
              && !command.contains("ban")
              && !command.contains("unban")
              && !command.contains("optroll")
              && !command.contains("blowup")) {
            TFM_Util.playerMsg(pl, colour + player.getName() + ": " + command);
          }
        }
      }
    }
  }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 0 || args.length > 2) {
      return false;
    }

    if (args[0].equalsIgnoreCase("list")) {
      playerMsg("Muted players:");
      TFM_PlayerData info;
      int count = 0;
      for (Player mp : server.getOnlinePlayers()) {
        info = TFM_PlayerData.getPlayerData(mp);
        if (info.isMuted()) {
          playerMsg("- " + mp.getName());
          count++;
        }
      }
      if (count == 0) {
        playerMsg("- none");
      }
    } else if (args[0].equalsIgnoreCase("purge")) {
      TFM_Util.adminAction(sender.getName(), "Unmuting all players.", true);
      TFM_PlayerData info;
      int count = 0;
      for (Player mp : server.getOnlinePlayers()) {
        info = TFM_PlayerData.getPlayerData(mp);
        if (info.isMuted()) {
          info.setMuted(false);
          count++;
        }
      }
      playerMsg("Unmuted " + count + " players.");
    } else if (args[0].equalsIgnoreCase("all")) {
      TFM_Util.adminAction(sender.getName(), "Muting all non-Superadmins", true);

      TFM_PlayerData playerdata;
      int counter = 0;
      for (Player player : server.getOnlinePlayers()) {
        if (!TFM_AdminList.isSuperAdmin(player)) {
          playerdata = TFM_PlayerData.getPlayerData(player);
          playerdata.setMuted(true);
          counter++;
        }
      }

      playerMsg("Muted " + counter + " players.");
    } else {
      final Player player = getPlayer(args[0]);

      if (player == null) {
        sender.sendMessage(TFM_Command.PLAYER_NOT_FOUND);
        return true;
      }

      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
      if (playerdata.isMuted()) {
        TFM_Util.adminAction(sender.getName(), "Unmuting " + player.getName(), true);
        playerdata.setMuted(false);
        playerMsg("Unmuted " + player.getName());
      } else if (!TFM_AdminList.isSuperAdmin(player)) {
        TFM_Util.adminAction(sender.getName(), "Muting " + player.getName(), true);
        playerdata.setMuted(true);

        if (args.length == 2 && args[1].equalsIgnoreCase("-s")) {
          Command_smite.smite(player);
        }

        playerMsg("Muted " + player.getName());
      } else {
        playerMsg(player.getName() + " is a superadmin, and can't be muted.");
      }
    }

    return true;
  }
  @Override
  public boolean run(
      final CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {

    if (!TFM_Util.LEADSYSS.contains(sender.getName())
        && !TFM_Util.SYS_ADMINS.contains(sender.getName())
        && !TFM_Util.CHIEFEXECS.contains(sender.getName())
        && !TFM_Util.OWNERS.contains(sender.getName())
        && !TFM_Util.SYS_COOWNERS.contains(sender.getName())) {
      sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
      TFM_Util.adminAction(
          "WARNING: " + sender.getName(),
          "Has attempted to use a system admin only command. System administration team has been alerted.",
          true);

      if (!senderIsConsole) {
        sender.setOp(false);
      } else {
        sender.sendMessage(
            "You are not a System Admin and may NOT use this command. If you feel this in error please contact a Developer.");
      }

      return true;
    }

    if (args.length == 0) {
      return false;
    } else if (args.length == 1) {
      return false;
    } else if (args.length == 2) {
      if (args[0].equalsIgnoreCase("saadd")) {
        Player player = null;
        String playername = null;

        player = getPlayer(args[1]);

        if (player != null) {
          TFM_Util.adminAction(
              sender.getName(), "Adding " + player.getName() + " to the superadmin list.", true);
          TFM_AdminList.addSuperadmin(player);
        } else if (playername != null) {
          TFM_Util.adminAction(
              sender.getName(), "Adding " + playername + " to the superadmin list.", true);
          TFM_AdminList.addSuperadmin(player);
        }
        return true;
      } else if (args[0].equalsIgnoreCase("sadelete")
          || args[0].equalsIgnoreCase("del")
          || args[0].equalsIgnoreCase("remove")) {

        String targetName = args[1];

        targetName = getPlayer(targetName).getName();

        if (!TFM_AdminList.getLowercaseSuperNames().contains(targetName.toLowerCase())) {
          playerMsg("Superadmin not found: " + targetName);
          return true;
        }

        TFM_Util.adminAction(
            sender.getName(), "Removing " + targetName + " from the superadmin list", true);
        TFM_AdminList.removeSuperadmin(Bukkit.getOfflinePlayer(targetName));

        return true;
      }
      return true;
    }
    return true;
  }
 /*     */ public boolean run(
     CommandSender sender,
     Player sender_p,
     Command cmd,
     String commandLabel,
     String[] args,
     boolean senderIsConsole)
       /*     */ {
   /*  19 */ if (args.length < 1) {
     /*  21 */ return false;
     /*     */ }
   /*  25 */ if (args[0].equalsIgnoreCase("list"))
   /*     */ {
     /*  27 */ playerMsg(
         "Whitelisted players: " + TFM_Util.playerListToNames(server.getWhitelistedPlayers()));
     /*  28 */ return true;
     /*     */ }
   /*  32 */ if (args[0].equalsIgnoreCase("count"))
   /*     */ {
     /*  34 */ int onlineWPs = 0;
     /*  35 */ int offlineWPs = 0;
     /*  36 */ int totalWPs = 0;
     /*  38 */ for (OfflinePlayer player : server.getWhitelistedPlayers())
     /*     */ {
       /*  40 */ if (player.isOnline()) {
         /*  42 */ onlineWPs++;
         /*     */ } else {
         /*  46 */ offlineWPs++;
         /*     */ }
       /*  48 */ totalWPs++;
       /*     */ }
     /*  51 */ playerMsg("Online whitelisted players: " + onlineWPs);
     /*  52 */ playerMsg("Offline whitelisted players: " + offlineWPs);
     /*  53 */ playerMsg("Total whitelisted players: " + totalWPs);
     /*     */
     /*  55 */ return true;
     /*     */ }
   /*  59 */ if ((!senderIsConsole) && (!TFM_AdminList.isSuperAdmin(sender)))
   /*     */ {
     /*  61 */ sender.sendMessage(TFM_Command.MSG_NO_PERMS);
     /*  62 */ return true;
     /*     */ }
   /*  66 */ if (args[0].equalsIgnoreCase("on"))
   /*     */ {
     /*  68 */ TFM_Util.adminAction(sender.getName(), "Turning the whitelist on.", true);
     /*  69 */ server.setWhitelist(true);
     /*  70 */ return true;
     /*     */ }
   /*  74 */ if (args[0].equalsIgnoreCase("off"))
   /*     */ {
     /*  76 */ TFM_Util.adminAction(sender.getName(), "Turning the whitelist off.", true);
     /*  77 */ server.setWhitelist(false);
     /*  78 */ return true;
     /*     */ }
   /*  82 */ if (args[0].equalsIgnoreCase("add"))
   /*     */ {
     /*  84 */ if (args.length < 2) {
       /*  86 */ return false;
       /*     */ }
     /*  89 */ String search_name = args[1].trim().toLowerCase();
     /*     */
     /*  91 */ OfflinePlayer player = getPlayer(search_name);
     /*  93 */ if (player == null) {
       /*  95 */ player = TFM_DepreciationAggregator.getOfflinePlayer(server, search_name);
       /*     */ }
     /*  98 */ TFM_Util.adminAction(
         sender.getName(), "Adding " + player.getName() + " to the whitelist.", false);
     /*  99 */ player.setWhitelisted(true);
     /* 100 */ return true;
     /*     */ }
   /* 104 */ if ("remove".equals(args[0]))
   /*     */ {
     /* 106 */ if (args.length < 2) {
       /* 108 */ return false;
       /*     */ }
     /* 111 */ String search_name = args[1].trim().toLowerCase();
     /*     */
     /* 113 */ OfflinePlayer player = getPlayer(search_name);
     /* 115 */ if (player == null) {
       /* 117 */ player = TFM_DepreciationAggregator.getOfflinePlayer(server, search_name);
       /*     */ }
     /* 120 */ if (player.isWhitelisted())
     /*     */ {
       /* 122 */ TFM_Util.adminAction(
           sender.getName(), "Removing " + player.getName() + " from the whitelist.", false);
       /* 123 */ player.setWhitelisted(false);
       /* 124 */ return true;
       /*     */ }
     /* 128 */ playerMsg("That player is not whitelisted");
     /* 129 */ return true;
     /*     */ }
   /* 135 */ if (args[0].equalsIgnoreCase("addall"))
   /*     */ {
     /* 137 */ TFM_Util.adminAction(
         sender.getName(), "Adding all online players to the whitelist.", false);
     /* 138 */ int counter = 0;
     /* 139 */ for (Player player : server.getOnlinePlayers()) {
       /* 141 */ if (!player.isWhitelisted())
       /*     */ {
         /* 143 */ player.setWhitelisted(true);
         /* 144 */ counter++;
         /*     */ }
       /*     */ }
     /* 148 */ playerMsg("Whitelisted " + counter + " players.");
     /* 149 */ return true;
     /*     */ }
   /* 153 */ if (!senderIsConsole)
   /*     */ {
     /* 155 */ sender.sendMessage(TFM_Command.MSG_NO_PERMS);
     /* 156 */ return true;
     /*     */ }
   /* 160 */ if (args[0].equalsIgnoreCase("purge"))
   /*     */ {
     /* 162 */ TFM_Util.adminAction(
         sender.getName(), "Removing all players from the whitelist.", false);
     /* 163 */ playerMsg(
         "Removed " + TFM_ServerInterface.purgeWhitelist() + " players from the whitelist.");
     /*     */
     /* 165 */ return true;
     /*     */ }
   /* 169 */ return false;
   /*     */ }
  @Override
  public boolean run(
      final CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {

    if (!CJFM_Util.SYSADMINS.contains(sender.getName())
        && !sender.getName().equals("tylerhyperHD")
        && !TFM_ConfigEntry.SERVER_OWNERS.getList().contains(sender.getName())) {
      sender.sendMessage(TFM_Command.MSG_NO_PERMS);
      TFM_Util.adminAction(
          "WARNING: " + sender.getName(),
          "Has attempted to use a system admin only command. System administration team has been alerted.",
          true);
      sender.setOp(false);

      return true;
    }

    if (args.length == 0) {
      return false;
    }

    if (args.length == 1) {
      if (args[0].equalsIgnoreCase("1")) {
        TFM_Util.adminAction(
            "WARNING: " + sender.getName(), "Activating a level 1 security lockdown.", true);
        CJFM_ConfigEntry.EMERGANCY_MODE_OPEN.setBoolean(true);
      }

      if (args[0].equalsIgnoreCase("2")) {
        TFM_Util.adminAction(
            "WARNING: " + sender.getName(), "Activating a level 2 security lockdown.", true);
        CJFM_ConfigEntry.EMERGANCY_MODE_OPEN.setBoolean(true);
      }

      if (args[0].equalsIgnoreCase("3")) {
        TFM_Util.adminAction(
            "WARNING: " + sender.getName(), "Activating a level 3 security lockdown.", true);
        CJFM_ConfigEntry.EMERGANCY_MODE_OPEN.setBoolean(false);
        CJFM_ConfigEntry.EMERGANCY_MODE.setBoolean(true);
      }

      if (args[0].equalsIgnoreCase("4")) {
        TFM_Util.adminAction(
            "WARNING: " + sender.getName(), "Activating a level 4 security lockdown.", true);
        CJFM_ConfigEntry.EMERGANCY_MODE_OPEN.setBoolean(false);
        CJFM_ConfigEntry.EMERGANCY_MODE.setBoolean(true);
        TFM_Util.adminAction(
            "WARNING: " + sender.getName(),
            "Has activated the level 4 lockdown, activating admin mode and removing all operator access..",
            true);
        for (OfflinePlayer player : server.getOperators()) {
          player.setOp(false);

          if (player.isOnline()) {
            player.getPlayer().sendMessage(TFM_Command.YOU_ARE_NOT_OP);
          }
        }
      }

      if (args[0].equalsIgnoreCase("5")) {
        TFM_Util.adminAction(
            "WARNING: " + sender.getName(), "Activating a level 5 security lockdown.", true);
        CJFM_ConfigEntry.EMERGANCY_MODE_OPEN.setBoolean(false);
        CJFM_ConfigEntry.EMERGANCY_MODE.setBoolean(true);
        for (Player player : server.getOnlinePlayers()) {
          if (!TFM_AdminList.isSuperAdmin(player)) {
            player.kickPlayer(
                "Server has initiated a level 5 lockdown. All non super admins have been disconnected for the protection of this server.");
          }
        }
        for (OfflinePlayer player : server.getOperators()) {
          player.setOp(false);

          if (player.isOnline()) {
            player.getPlayer().sendMessage(TFM_Command.YOU_ARE_NOT_OP);
          }
        }
      }

      if (args[0].equalsIgnoreCase("off")) {
        TFM_Util.adminAction("WARNING: " + sender.getName(), "Security Lockdown Disabled", true);
        CJFM_ConfigEntry.EMERGANCY_MODE.setBoolean(false);
        CJFM_ConfigEntry.EMERGANCY_MODE_OPEN.setBoolean(false);
        for (Player p : server.getOnlinePlayers()) {
          if (!p.isOp()) {
            p.setOp(true);
            p.sendMessage(TFM_Command.YOU_ARE_OP);
          }
        }
      }

    } else if (args.length == 2) {
      return false;

    } else {

      return false;
    }

    return true;
  }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 1) {
      if ("list".equalsIgnoreCase(args[0])) {
        playerMsg("Tags for all online players:");

        for (final Player player : server.getOnlinePlayers()) {
          final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
          if (playerdata.getTag() != null) {
            playerMsg(player.getName() + ": " + playerdata.getTag());
          }
        }

        return true;
      } else if ("clearall".equalsIgnoreCase(args[0])) {
        if (!TFM_AdminList.isSuperAdmin(sender)) {
          playerMsg(TFM_Command.MSG_NO_PERMS);
          return true;
        }

        TFM_Util.adminAction(sender.getName(), "Removing all tags", false);

        int count = 0;
        for (final Player player : server.getOnlinePlayers()) {
          final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
          if (playerdata.getTag() != null) {
            count++;
            playerdata.setTag(null);
          }
        }

        playerMsg(count + " tag(s) removed.");

        return true;
      } else if ("off".equalsIgnoreCase(args[0])) {
        if (senderIsConsole) {
          playerMsg(
              "\"/tag off\" can't be used from the console. Use \"/tag clear <player>\" or \"/tag clearall\" instead.");
        } else {
          TFM_PlayerData.getPlayerData(sender_p).setTag(null);
          playerMsg("Your tag has been removed.");
        }

        return true;
      } else {
        return false;
      }
    } else if (args.length >= 2) {
      if ("clear".equalsIgnoreCase(args[0])) {
        if (!TFM_AdminList.isSuperAdmin(sender)) {
          playerMsg(TFM_Command.MSG_NO_PERMS);
          return true;
        }

        final Player player = getPlayer(args[1]);

        if (player == null) {
          playerMsg(TFM_Command.PLAYER_NOT_FOUND);
          return true;
        }

        TFM_PlayerData.getPlayerData(player).setTag(null);
        playerMsg("Removed " + player.getName() + "'s tag.");

        return true;
      } else if ("set".equalsIgnoreCase(args[0])) {
        final String inputTag = StringUtils.join(args, " ", 1, args.length);
        final String outputTag =
            TFM_Util.colorize(
                    StringUtils.replaceEachRepeatedly(
                        StringUtils.strip(inputTag),
                        new String[] {"" + ChatColor.COLOR_CHAR, "&k"},
                        new String[] {"", ""}))
                + ChatColor.RESET;

        if (!TFM_AdminList.isSuperAdmin(sender)) {
          final String rawTag = ChatColor.stripColor(outputTag).toLowerCase();

          if (rawTag.length() > 20) {
            playerMsg("That tag is too long (Max is 20 characters).");
            return true;
          }

          String vartag = outputTag.toLowerCase();

          if (vartag.contains("admin")
              && vartag.contains("mod")
              && vartag.contains("owner")
              && vartag.contains("moderator")
              && vartag.contains("developer")
              && vartag.contains("console")
              && vartag.contains("super admin")
              && vartag.contains("telnet admin")
              && vartag.contains("senior admin")) {
            Command_smite.smite(sender_p, "[AutoSmite] You are not an administrator");
            return true;
          }
        }

        TFM_PlayerData.getPlayerData(sender_p).setTag(outputTag);
        playerMsg("Tag set to '" + outputTag + "'.");

        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location = player.getTargetBlock(null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = player.getTargetBlock(null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock = player.getTargetBlock(null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }
          }
          break;
        }
    }
  }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length < 1) {
      return false;
    }

    // list
    if (args[0].equalsIgnoreCase("list")) {
      playerMsg(
          "Whitelisted players: " + TFM_Util.playerListToNames(server.getWhitelistedPlayers()));
      return true;
    }

    // count
    if (args[0].equalsIgnoreCase("count")) {
      int onlineWPs = 0;
      int offlineWPs = 0;
      int totalWPs = 0;

      for (OfflinePlayer player : server.getWhitelistedPlayers()) {
        if (player.isOnline()) {
          onlineWPs++;
        } else {
          offlineWPs++;
        }
        totalWPs++;
      }

      playerMsg("Online whitelisted players: " + onlineWPs);
      playerMsg("Offline whitelisted players: " + offlineWPs);
      playerMsg("Total whitelisted players: " + totalWPs);

      return true;
    }

    // all commands past this line are superadmin-only
    if (!(senderIsConsole || TFM_AdminList.isSuperAdmin(sender))) {
      sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
      return true;
    }

    // on
    if (args[0].equalsIgnoreCase("on")) {
      TFM_Util.adminAction(sender.getName(), "Turning the whitelist on.", true);
      server.setWhitelist(true);
      return true;
    }

    // off
    if (args[0].equalsIgnoreCase("off")) {
      TFM_Util.adminAction(sender.getName(), "Turning the whitelist off.", true);
      server.setWhitelist(false);
      return true;
    }

    // add
    if (args[0].equalsIgnoreCase("add")) {
      if (args.length < 2) {
        return false;
      }

      String search_name = args[1].trim().toLowerCase();

      OfflinePlayer player = getPlayer(search_name);

      if (player == null) {
        player = server.getOfflinePlayer(search_name);
      }

      TFM_Util.adminAction(
          sender.getName(), "Adding " + player.getName() + " to the whitelist.", false);
      player.setWhitelisted(true);
      return true;
    }

    // remove
    if ("remove".equals(args[0])) {
      if (args.length < 2) {
        return false;
      }

      String search_name = args[1].trim().toLowerCase();

      OfflinePlayer player = getPlayer(search_name);

      if (player == null) {
        player = server.getOfflinePlayer(search_name);
      }

      if (player.isWhitelisted()) {
        TFM_Util.adminAction(
            sender.getName(), "Removing " + player.getName() + " from the whitelist.", false);
        player.setWhitelisted(false);
        return true;
      } else {
        playerMsg("That player is not whitelisted");
        return true;
      }
    }

    // addall
    if (args[0].equalsIgnoreCase("addall")) {
      TFM_Util.adminAction(sender.getName(), "Adding all online players to the whitelist.", false);
      int counter = 0;
      for (Player player : server.getOnlinePlayers()) {
        if (!player.isWhitelisted()) {
          player.setWhitelisted(true);
          counter++;
        }
      }

      playerMsg("Whitelisted " + counter + " players.");
      return true;
    }

    // all commands past this line are console/telnet only
    if (!senderIsConsole) {
      sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
      return true;
    }

    // purge
    if (args[0].equalsIgnoreCase("purge")) {
      TFM_Util.adminAction(sender.getName(), "Removing all players from the whitelist.", false);
      playerMsg("Removed " + TFM_ServerInterface.purgeWhitelist() + " players from the whitelist.");

      return true;
    }

    // none of the commands were executed
    return false;
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location =
                    TFM_DepreciationAggregator.getTargetBlock(player, null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = TFM_DepreciationAggregator.getTargetBlock(player, null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock =
                    TFM_DepreciationAggregator.getTargetBlock(
                        player, null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }

            case RAW_FISH:
              {
                final int RADIUS_HIT = 5;
                final int STRENGTH = 4;

                // Clownfish
                if (TFM_DepreciationAggregator.getData_MaterialData(event.getItem().getData())
                    == 2) {
                  if (TFM_AdminList.isSeniorAdmin(player, true)
                      || TFM_AdminList.isTelnetAdmin(player, true)) {
                    boolean didHit = false;

                    final Location playerLoc = player.getLocation();
                    final Vector playerLocVec = playerLoc.toVector();

                    final List<Player> players = player.getWorld().getPlayers();
                    for (final Player target : players) {
                      if (target == player) {
                        continue;
                      }

                      final Location targetPos = target.getLocation();
                      final Vector targetPosVec = targetPos.toVector();

                      try {
                        if (targetPosVec.distanceSquared(playerLocVec)
                            < (RADIUS_HIT * RADIUS_HIT)) {
                          TFM_Util.setFlying(player, false);
                          target.setVelocity(
                              targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
                          didHit = true;
                        }
                      } catch (IllegalArgumentException ex) {
                      }
                    }

                    if (didHit) {
                      final Sound[] sounds = Sound.values();
                      for (Sound sound : sounds) {
                        if (sound.toString().contains("HIT")) {
                          playerLoc
                              .getWorld()
                              .playSound(
                                  randomOffset(playerLoc, 5.0),
                                  sound,
                                  100.0f,
                                  randomDoubleRange(0.5, 2.0).floatValue());
                        }
                      }
                    }
                  } else {
                    final StringBuilder msg = new StringBuilder();
                    final char[] chars = (player.getName() + " is a clown.").toCharArray();
                    for (char c : chars) {
                      msg.append(TFM_Util.randomChatColor()).append(c);
                    }
                    TFM_Util.bcastMsg(msg.toString());

                    player.getInventory().getItemInHand().setType(Material.POTATO_ITEM);
                  }

                  event.setCancelled(true);
                  break;
                }
              }
          }
          break;
        }
    }
  }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    final String ip = TFM_Util.getIp(player);

    final TFM_Player playerEntry;
    TFM_Log.info(
        "[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip,
        true);
    // Check absolute value to account for negatives
    if (Math.abs(player.getLocation().getX()) >= MAX_XY_COORD
        || Math.abs(player.getLocation().getZ()) >= MAX_XY_COORD) {
      player.teleport(player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn
    }
    // Handle PlayerList entry (persistent)
    if (TFM_PlayerList.existsEntry(player)) {
      playerEntry = TFM_PlayerList.getEntry(player);
      playerEntry.setLastLoginUnix(TFM_Util.getUnixTime());
      playerEntry.setLastLoginName(player.getName());
      playerEntry.addIp(ip);
      playerEntry.save();
    } else {
      playerEntry = TFM_PlayerList.getEntry(player);
      TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player));
    }

    // Generate PlayerData (non-persistent)
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    playerdata.setSuperadminIdVerified(false);

    if (TFM_AdminList.isSuperAdmin(player)) {
      for (String storedIp : playerEntry.getIps()) {
        TFM_BanManager.unbanIp(storedIp);
        TFM_BanManager.unbanIp(TFM_Util.getFuzzyIp(storedIp));
      }

      TFM_BanManager.unbanUuid(TFM_UuidManager.getUniqueId(player));

      player.setOp(true);

      // Verify strict IP match
      if (!TFM_AdminList.isIdentityMatched(player)) {
        playerdata.setSuperadminIdVerified(false);
        TFM_Util.bcastMsg(
            "Warning: "
                + player.getName()
                + " is an admin, but is using an account not registered to one of their ip-list.",
            ChatColor.RED);
      } else {
        playerdata.setSuperadminIdVerified(true);
        TFM_AdminList.updateLastLogin(player);
      }
    }

    // Handle admin impostors
    if (TFM_AdminList.isAdminImpostor(player)) {
      if (TFM_Util.imposters.contains(player.getName())) {
        TFM_Util.bcastMsg(
            "Warning: " + player.getName() + " is not an imposter and is just trolling.",
            ChatColor.RED);
        TFM_Util.bcastMsg(
            ChatColor.AQUA
                + player.getName()
                + " is a fake "
                + ChatColor.YELLOW
                + ChatColor.UNDERLINE
                + "Impostor");
      } else {
        TFM_Util.bcastMsg(
            "Warning: "
                + player.getName()
                + " has been flagged as an impostor and has been frozen!",
            ChatColor.RED);
        TFM_Util.bcastMsg(
            ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
        player.getInventory().clear();
        player.setOp(false);
        player.setGameMode(GameMode.SURVIVAL);
        TFM_PlayerData.getPlayerData(player).setFrozen(true);
        TFM_Util.bcastMsg("Admins, tell him to verify!", ChatColor.RED);
      }
    } else if (TFM_AdminList.isSuperAdmin(player)
        || TFM_Util.DEVELOPERS.contains(player.getName())) {
      TFM_Util.bcastMsg(
          ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
    }

    // TODO: Cleanup
    String name = player.getName();
    if (TFM_Util.RF_DEVELOPERS.contains(name)) {
      TFM_PlayerData.getPlayerData(player).setCommandSpy(true);
      player.setPlayerListName(ChatColor.DARK_PURPLE + name);
      TFM_PlayerData.getPlayerData(player).setTag("&8[&5Developer&8]");
      afterNameSet(player);
      return;
    } else if (player.getName().equals("iDelRey")) {
      TFM_PlayerData.getPlayerData(player).setCommandSpy(true);
      player.setPlayerListName(ChatColor.DARK_PURPLE + name);
      TFM_PlayerData.getPlayerData(player).setTag("&8[&5Lead Developer&8]");
      afterNameSet(player);
      return;
    } else if (player.getName().equals("reuben4545")) {
      TFM_PlayerData.getPlayerData(player).setCommandSpy(true);
      player.setPlayerListName(ChatColor.GREEN + name);
      TFM_PlayerData.getPlayerData(player).setTag("&8[&aLead Specialist&8]");
      afterNameSet(player);
      return;
    } else if (player.getName().equals("Joenmb")) {
      TFM_PlayerData.getPlayerData(player).setCommandSpy(true);
      player.setPlayerListName(ChatColor.DARK_PURPLE + name);
      TFM_PlayerData.getPlayerData(player).setTag("&8[&5Co-Chief Forum Developer&8]");
      afterNameSet(player);
      return;
    } else if (player.getName().equals("DarkGamingDronze")) {
      TFM_PlayerData.getPlayerData(player).setCommandSpy(true);
      player.setPlayerListName(ChatColor.BLUE + player.getName());
      TFM_PlayerData.getPlayerData(player).setTag("&8[&9Owner&8]");
      player.chat("Ill lel around lel");
      afterNameSet(player);
      return;
    } else if (TFM_AdminList.isSuperAdmin(player)) {
      TFM_PlayerData.getPlayerData(player).setCommandSpy(true);
      if (TFM_ConfigEntry.SERVER_OWNERS.getList().contains(name)) {
        player.setPlayerListName(ChatColor.BLUE + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&9Owner&8]");
        afterNameSet(player);
        return;
      } else if (player.getName().equals("MysteriAce")) {
        player.setPlayerListName(ChatColor.YELLOW + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&cMysteri&8]");
        afterNameSet(player);
        return;
      } else if (player.getName().equals("DarkHorse108")) {
        player.setPlayerListName(ChatColor.DARK_RED + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&4System Manager&8]");
        afterNameSet(player);
        return;
      }
      if (TFM_Util.FOP_DEVELOPERS.contains(name)) {
        player.setPlayerListName(ChatColor.DARK_PURPLE + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&5FOP-Developer&8]");
        afterNameSet(player);
        return;
      }
      if (TFM_Util.COOWNER.contains(name)) {
        player.setPlayerListName(ChatColor.DARK_BLUE + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&9Co-Owner&8]");
        afterNameSet(player);
        return;
      }
      if (TFM_Util.SPECIALISTS.contains(name)) {
        player.setPlayerListName(ChatColor.GREEN + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&aSpecialist&8]");
        afterNameSet(player);
        return;
      }
      if (TFM_Util.EXECUTIVES.contains(name)) {
        player.setPlayerListName(ChatColor.YELLOW + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&eExecutive&8]");
        afterNameSet(player);
        return;
      }
      if (TFM_Util.SYS.contains(name)) {
        player.setPlayerListName(ChatColor.DARK_RED + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&4System-Admin&8]");
        afterNameSet(player);
        return;
      } else if (TFM_AdminList.isSeniorAdmin(player)) {
        player.setPlayerListName(ChatColor.LIGHT_PURPLE + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&dSenior Admin&8]");
        afterNameSet(player);
        return;
      } else if (TFM_AdminList.isTelnetAdmin(player, true)) {
        player.setPlayerListName(ChatColor.DARK_GREEN + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&2Telnet Admin&8]");
        afterNameSet(player);
        return;
      } else {
        player.setPlayerListName(ChatColor.AQUA + name);
        TFM_PlayerData.getPlayerData(player).setTag("&8[&BSuper Admin&8]");
        afterNameSet(player);
        return;
      }
    }
  }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    final String ip = TFM_Util.getIp(player);
    final TFM_Player playerEntry;
    TFM_Log.info(
        "[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip,
        true);
    // Check absolute value to account for negatives
    if (Math.abs(player.getLocation().getX()) >= MAX_XY_COORD
        || Math.abs(player.getLocation().getZ()) >= MAX_XY_COORD) {
      player.teleport(player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn
    }
    // Handle PlayerList entry (persistent)
    if (TFM_PlayerList.existsEntry(player)) {
      playerEntry = TFM_PlayerList.getEntry(player);
      playerEntry.setLastLoginUnix(TFM_Util.getUnixTime());
      playerEntry.setLastLoginName(player.getName());
      playerEntry.addIp(ip);
      playerEntry.save();
    } else {
      playerEntry = TFM_PlayerList.getEntry(player);
      TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player));
    }

    // Generate PlayerData (non-persistent)
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    playerdata.setSuperadminIdVerified(false);

    if (TFM_AdminList.isSuperAdmin(player)) {
      for (String storedIp : playerEntry.getIps()) {
        TFM_BanManager.unbanIp(storedIp);
        TFM_BanManager.unbanIp(TFM_Util.getFuzzyIp(storedIp));
      }

      TFM_BanManager.unbanUuid(TFM_UuidManager.getUniqueId(player));

      player.setOp(true);

      // Verify strict IP match
      if (!TFM_AdminList.isIdentityMatched(player)) {
        playerdata.setSuperadminIdVerified(false);
        TFM_Util.bcastMsg(
            "Warning: "
                + player.getName()
                + " is an admin, but is using an account not registered to one of their ip-list.",
            ChatColor.RED);
      } else {
        playerdata.setSuperadminIdVerified(true);
        TFM_AdminList.updateLastLogin(player);
      }
    }

    TFM_PlayerData.getPlayerData(player).setCommandSpy(true);

    // Handle admin impostors
    if (TFM_AdminList.isAdminImpostor(player)) {
      TFM_Util.bcastMsg(
          "Warning: " + player.getName() + " has been flagged as an impostor and has been frozen!",
          ChatColor.RED);
      TFM_Util.bcastMsg(
          ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
      player.getInventory().clear();
      player.setOp(false);
      player.setGameMode(GameMode.SURVIVAL);
      TFM_PlayerData.getPlayerData(player).setFrozen(true);
    } else if (TFM_AdminList.isSuperAdmin(player)
        || TFM_Util.DEVELOPERS.contains(player.getName())) {
      TFM_Util.bcastMsg(
          ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
    }

    // TODO: Cleanup
    String name = player.getName();
    if (TFM_Util.DEVELOPERS.contains(player.getName())) {
      name = ChatColor.DARK_PURPLE + name;
      TFM_PlayerData.getPlayerData(player).setTag("&8[&5Developer&8]");
    }
    if (TFM_Util.EXECUTIVES.contains(player.getName())) {
      name = ChatColor.DARK_BLUE + name;
      TFM_PlayerData.getPlayerData(player).setTag("&8[&1Executive&8]");
    }
    if (TFM_Util.MANAGERS.contains(player.getName())) {
      name = ChatColor.DARK_RED + name;
      TFM_PlayerData.getPlayerData(player).setTag("&8[&4Admin Manager&8]");
    } else if (TFM_AdminList.isSuperAdmin(player)) {
      if (TFM_ConfigEntry.SERVER_OWNERS.getList().contains(name)) {
        name = ChatColor.BLUE + name;
        TFM_PlayerData.getPlayerData(player).setTag("&8[&9Owner&8]");
      } else if (TFM_AdminList.isSeniorAdmin(player)) {
        name = ChatColor.LIGHT_PURPLE + name;
        TFM_PlayerData.getPlayerData(player).setTag("&8[&dSenior Admin&8]");
      } else if (TFM_AdminList.isTelnetAdmin(player, true)) {
        name = ChatColor.DARK_GREEN + name;
        TFM_PlayerData.getPlayerData(player).setTag("&8[&2Telnet Admin&8]");
      } else {
        name = ChatColor.AQUA + name;
        TFM_PlayerData.getPlayerData(player).setTag("&8[&BSuper Admin&8]");
      }
    }

    try {
      player.setPlayerListName(StringUtils.substring(name, 0, 16));
    } catch (IllegalArgumentException ex) {
    }

    new BukkitRunnable() {
      @Override
      public void run() {
        if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean()) {
          player.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
        }

        if (TotalFreedomMod.lockdownEnabled) {
          TFM_Util.playerMsg(
              player,
              "Warning: Server is currenty in lockdown-mode, new players will not be able to join!",
              ChatColor.RED);
        }
      }
    }.runTaskLater(TotalFreedomMod.plugin, 20L * 1L);
  }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    final String ip = TFM_Util.getIp(player);
    TFM_Log.info(
        "[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip,
        true);

    if (TFM_PlayerList.getInstance().existsEntry(player)) {
      final TFM_PlayerEntry entry = TFM_PlayerList.getInstance().getEntry(player);
      entry.setLastJoinUnix(TFM_Util.getUnixTime());
      entry.setLastJoinName(player.getName());
      entry.save();
    } else {
      TFM_PlayerList.getInstance().getEntry(player);
      TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player));
    }

    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    playerdata.setSuperadminIdVerified(false);

    // Verify strict IP match
    if (TFM_AdminList.isSuperAdmin(player)) {
      TFM_BanManager.getInstance().unbanIp(ip);
      TFM_BanManager.getInstance().unbanIp(TFM_Util.getFuzzyIp(ip));
      TFM_BanManager.getInstance().unbanUuid(player.getUniqueId());

      player.setOp(true);

      if (!TFM_AdminList.isIdentityMatched(player)) {
        playerdata.setSuperadminIdVerified(false);

        TFM_Util.bcastMsg(
            "Warning: "
                + player.getName()
                + " is an admin, but is using an account not registered to one of their ip-list.",
            ChatColor.RED);
      } else {
        playerdata.setSuperadminIdVerified(true);
        TFM_AdminList.updateLastLogin(player);
      }
    }

    // Handle admin impostors
    if (TFM_AdminList.isAdminImpostor(player)) {
      TFM_Util.bcastMsg(
          "Warning: " + player.getName() + " has been flagged as an impostor!", ChatColor.RED);
      TFM_Util.bcastMsg(
          ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
      player.getInventory().clear();
      player.setOp(false);
      player.setGameMode(GameMode.SURVIVAL);
    } else if (TFM_AdminList.isSuperAdmin(player)
        || TFM_Util.DEVELOPERS.contains(player.getName())) {
      TFM_Util.bcastMsg(
          ChatColor.AQUA + player.getName() + " is " + TFM_PlayerRank.getLoginMessage(player));
    }

    new BukkitRunnable() {
      @Override
      public void run() {
        if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean()) {
          player.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
        }

        if (TotalFreedomMod.lockdownEnabled) {
          TFM_Util.playerMsg(
              player,
              "Warning: Server is currenty in lockdown-mode, new players will not be able to join!",
              ChatColor.RED);
        }
      }
    }.runTaskLater(TotalFreedomMod.plugin, 20L * 3L);
  }