@EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    try {
      final Player p = event.getPlayer();
      String message = event.getMessage().trim();

      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
      playerdata.incrementMsgCount();

      // Check for spam
      if (playerdata.getMsgCount() > 10) {
        TFM_Util.bcastMsg(
            p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
        TFM_Util.autoEject(p, "Kicked for spamming chat.");

        playerdata.resetMsgCount();

        event.setCancelled(true);
        return;
      }

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

      // Check for muted
      if (playerdata.isMuted()) {
        if (!TFM_SuperadminList.isUserSuperadmin(p)) {
          p.sendMessage(ChatColor.RED + "You are muted, STFU!");
          event.setCancelled(true);
          return;
        } else {
          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_Util.playerMsg(p, "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_Util.adminChatMessage(p, message, false);
        event.setCancelled(true);
        return;
      }

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

      // Set the tag
      if (playerdata.getTag() != null) {
        p.setDisplayName((playerdata.getTag() + " " + p.getDisplayName().replaceAll(" ", "")));
      }

    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerJoin(PlayerJoinEvent event) {
    try {
      final Player p = event.getPlayer();
      final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
      playerdata.setSuperadminIdVerified(null);

      TFM_UserList.getInstance(TotalFreedomMod.plugin).addUser(p);

      boolean superadmin_impostor = TFM_SuperadminList.isSuperadminImpostor(p);

      if (superadmin_impostor || TFM_SuperadminList.isUserSuperadmin(p)) {
        TFM_Util.bcastMsg(ChatColor.AQUA + p.getName() + " is " + TFM_Util.getRank(p));

        if (superadmin_impostor) {
          p.getInventory().clear();
          p.setOp(false);
          p.setGameMode(GameMode.SURVIVAL);
          TFM_Util.bcastMsg(
              "Warning: " + p.getName() + " has been flagged as an impostor!", ChatColor.RED);
        } else {
          if (TFM_SuperadminList.verifyIdentity(
              p.getName(), p.getAddress().getAddress().getHostAddress())) {
            playerdata.setSuperadminIdVerified(Boolean.TRUE);

            TFM_SuperadminList.updateLastLogin(p);
          } else {
            playerdata.setSuperadminIdVerified(Boolean.FALSE);

            TFM_Util.bcastMsg(
                "Warning: "
                    + p.getName()
                    + " is an admin, but is using a username not registered to one of their IPs.",
                ChatColor.RED);
          }

          p.setOp(true);
        }
      }

      if (TotalFreedomMod.adminOnlyMode) {
        new BukkitRunnable() {
          @Override
          public void run() {
            p.sendMessage(ChatColor.RED + "Server is currently closed to non-superadmins.");
          }
        }.runTaskLater(TotalFreedomMod.plugin, 20L * 3L);
      }
    } catch (Throwable ex) {
    }
  }
 // 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]");
   }
 }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onBlockBreak(BlockBreakEvent event) {
    Player p = event.getPlayer();
    Location block_pos = event.getBlock().getLocation();

    if (TotalFreedomMod.nukeMonitor) {
      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);

      Location player_pos = p.getLocation();

      boolean out_of_range = false;
      if (!player_pos.getWorld().equals(block_pos.getWorld())) {
        out_of_range = true;
      } else if (player_pos.distanceSquared(block_pos)
          > (TotalFreedomMod.nukeMonitorRange * TotalFreedomMod.nukeMonitorRange)) {
        out_of_range = true;
      }

      if (out_of_range) {
        playerdata.incrementFreecamDestroyCount();
        if (playerdata.getFreecamDestroyCount() > TotalFreedomMod.freecamTriggerCount) {
          TFM_Util.bcastMsg(
              p.getName() + " has been flagged for possible freecam nuking.", ChatColor.RED);
          TFM_Util.autoEject(
              p, "Freecam (extended range) block breaking is not permitted on this server.");

          playerdata.resetFreecamDestroyCount();

          event.setCancelled(true);
          return;
        }
      }

      playerdata.incrementBlockDestroyCount();
      if (playerdata.getBlockDestroyCount() > TotalFreedomMod.nukeMonitorCountBreak) {
        TFM_Util.bcastMsg(p.getName() + " is breaking blocks too fast!", ChatColor.RED);
        TFM_Util.autoEject(
            p, "You are breaking blocks too fast. Nukers are not permitted on this server.");

        playerdata.resetBlockDestroyCount();

        event.setCancelled(true);
        return;
      }
    }

    if (TotalFreedomMod.protectedAreasEnabled) {
      if (!TFM_SuperadminList.isUserSuperadmin(p)) {
        if (TFM_ProtectedArea.isInProtectedArea(block_pos)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }
  @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);
  }
 /*     */ 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;
   /*     */ }
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPlayerQuit(PlayerQuitEvent event) {
   Player p = event.getPlayer();
   if (TotalFreedomMod.fuckoffEnabledFor.containsKey(p)) {
     TotalFreedomMod.fuckoffEnabledFor.remove(p);
   }
   TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
   playerdata.disarmMP44();
   if (playerdata.isCaged()) {
     playerdata.regenerateHistory();
     playerdata.clearHistory();
   }
 }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPlayerKick(PlayerKickEvent event) {
    Player player = event.getPlayer();
    if (TotalFreedomMod.fuckoffEnabledFor.containsKey(player)) {
      TotalFreedomMod.fuckoffEnabledFor.remove(player);
    }
    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
    playerdata.disarmMP44();
    if (playerdata.isCaged()) {
      playerdata.regenerateHistory();
      playerdata.clearHistory();
    }

    TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true);
  }
  private void playerLeave(Player player) {
    if (TotalFreedomMod.fuckoffEnabledFor.containsKey(player)) {
      TotalFreedomMod.fuckoffEnabledFor.remove(player);
    }

    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    playerdata.disarmMP44();

    if (playerdata.isCaged()) {
      playerdata.regenerateHistory();
      playerdata.clearHistory();
    }

    TFM_PlayerList.removeEntry(player);
    TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true);
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerMove(PlayerMoveEvent event) {
    if (!TFM_AdminWorld.getInstance().validateMovement(event)) {
      return;
    }

    Player p = event.getPlayer();
    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);

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

      if (fuckoff_player.equals(p) || !fuckoff_player.isOnline()) {
        continue;
      }

      double fuckoff_range = fuckoff.getValue().doubleValue();

      Location mover_pos = p.getLocation();
      Location fuckoff_pos = fuckoff_player.getLocation();

      double distanceSquared;
      try {
        distanceSquared = mover_pos.distanceSquared(fuckoff_pos);
      } catch (IllegalArgumentException ex) {
        continue;
      }

      if (distanceSquared < (fuckoff_range * fuckoff_range)) {
        event.setTo(
            fuckoff_pos
                .clone()
                .add(
                    mover_pos
                        .subtract(fuckoff_pos)
                        .toVector()
                        .normalize()
                        .multiply(fuckoff_range * 1.1)));
        break;
      }
    }

    boolean do_freeze = false;
    if (TotalFreedomMod.allPlayersFrozen) {
      if (!TFM_SuperadminList.isUserSuperadmin(p)) {
        do_freeze = true;
      }
    } else {
      if (playerdata.isFrozen()) {
        do_freeze = true;
      }
    }

    if (do_freeze) {
      Location from = event.getFrom();
      Location to = event.getTo().clone();

      to.setX(from.getX());
      to.setY(from.getY());
      to.setZ(from.getZ());

      event.setTo(to);
    }

    if (playerdata.isCaged()) {
      Location target_pos = p.getLocation().add(0, 1, 0);

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

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

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

    if (TotalFreedomMod.landminesEnabled && TotalFreedomMod.allowExplosions) {
      Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
      while (landmines.hasNext()) {
        TFM_LandmineData landmine = landmines.next();

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

        if (!landmine.player.equals(p)) {
          if (p.getWorld().equals(landmine_pos.getWorld())) {
            if (p.getLocation().distanceSquared(landmine_pos)
                <= (landmine.radius * landmine.radius)) {
              landmine.landmine_pos.getBlock().setType(Material.AIR);

              TNTPrimed tnt1 = landmine_pos.getWorld().spawn(landmine_pos, TNTPrimed.class);
              tnt1.setFuseTicks(40);
              tnt1.setPassenger(p);
              tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));

              TNTPrimed tnt2 = landmine_pos.getWorld().spawn(p.getLocation(), TNTPrimed.class);
              tnt2.setFuseTicks(1);

              p.setGameMode(GameMode.SURVIVAL);
              landmines.remove();
            }
          }
        }
      }
    }
  }
示例#11
0
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 0) {
      return false;
    }

    if (TFM_Util.isStopCommand(args[0]) && sender instanceof Player) {
      TFM_Util.adminAction(sender.getName(), "Uncaging " + sender.getName(), true);
      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(sender_p);

      playerdata.setCaged(false);
      playerdata.regenerateHistory();
      playerdata.clearHistory();

      return true;
    } else if ("purge".equalsIgnoreCase(args[0])) {
      TFM_Util.adminAction(sender.getName(), "Uncaging all players.", true);

      for (Player player : server.getOnlinePlayers()) {
        TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
        playerdata.setCaged(false);
        playerdata.regenerateHistory();
        playerdata.clearHistory();
      }

      return true;
    }

    Player player;
    try {
      player = getPlayer(args[0]);
    } catch (PlayerNotFoundException ex) {
      sender.sendMessage(ex.getMessage());
      return true;
    }

    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    Material outerMaterial = Material.GLASS;
    Material innerMaterial = Material.AIR;

    if (args.length >= 2) {
      if (TFM_Util.isStopCommand(args[1])) {
        TFM_Util.adminAction(sender.getName(), "Uncaging " + player.getName(), true);

        playerdata.setCaged(false);
        playerdata.regenerateHistory();
        playerdata.clearHistory();

        return true;
      } else {
        if ("bloop".equalsIgnoreCase(args[1])) {
          outerMaterial = Material.SKULL;
        } else if (Material.matchMaterial(args[1]) != null) {
          outerMaterial = Material.matchMaterial(args[1]);
        }
      }
    }

    if (args.length >= 3) {
      if (args[2].equalsIgnoreCase("water")) {
        innerMaterial = Material.STATIONARY_WATER;
      } else if (args[2].equalsIgnoreCase("lava")) {
        innerMaterial = Material.STATIONARY_LAVA;
      }
    }

    Location targetPos = player.getLocation().clone().add(0, 1, 0);
    playerdata.setCaged(true, targetPos, outerMaterial, innerMaterial);
    playerdata.regenerateHistory();
    playerdata.clearHistory();
    TFM_Util.buildHistory(targetPos, 2, playerdata);
    TFM_Util.generateHollowCube(targetPos, 2, outerMaterial);
    TFM_Util.generateCube(targetPos, 1, innerMaterial);

    player.setGameMode(GameMode.SURVIVAL);

    if (outerMaterial != Material.SKULL) {
      TFM_Util.adminAction(sender.getName(), "Caging " + player.getName(), true);
    } else {
      TFM_Util.adminAction(
          sender.getName(), "Caging " + player.getName() + " in PURE_BLOOPEH", true);
    }

    return true;
  }
  @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(
      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.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);
          }
        }
      }
    }
  }
  @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 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();
    }
  }
  @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);
    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);
  }
  @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;
        }
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockPlace(BlockPlaceEvent event) {
    Player p = event.getPlayer();
    Location block_pos = event.getBlock().getLocation();

    if (TotalFreedomMod.nukeMonitor) {
      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);

      Location player_pos = p.getLocation();

      boolean out_of_range = false;
      if (!player_pos.getWorld().equals(block_pos.getWorld())) {
        out_of_range = true;
      } else if (player_pos.distanceSquared(block_pos)
          > (TotalFreedomMod.nukeMonitorRange * TotalFreedomMod.nukeMonitorRange)) {
        out_of_range = true;
      }

      if (out_of_range) {
        playerdata.incrementFreecamPlaceCount();
        if (playerdata.getFreecamPlaceCount() > TotalFreedomMod.freecamTriggerCount) {
          TFM_Util.bcastMsg(
              p.getName() + " has been flagged for possible freecam building.", ChatColor.RED);
          TFM_Util.autoEject(
              p, "Freecam (extended range) block building is not permitted on this server.");

          playerdata.resetFreecamPlaceCount();

          event.setCancelled(true);
          return;
        }
      }

      playerdata.incrementBlockPlaceCount();
      if (playerdata.getBlockPlaceCount() > TotalFreedomMod.nukeMonitorCountPlace) {
        TFM_Util.bcastMsg(p.getName() + " is placing blocks too fast!", ChatColor.RED);
        TFM_Util.autoEject(p, "You are placing blocks too fast.");

        playerdata.resetBlockPlaceCount();

        event.setCancelled(true);
        return;
      }
    }

    if (TotalFreedomMod.protectedAreasEnabled) {
      if (!TFM_SuperadminList.isUserSuperadmin(p)) {
        if (TFM_ProtectedArea.isInProtectedArea(block_pos)) {
          event.setCancelled(true);
          return;
        }
      }
    }

    switch (event.getBlockPlaced().getType()) {
      case LAVA:
      case STATIONARY_LAVA:
        {
          if (TotalFreedomMod.allowLavaPlace) {
            TFM_Log.info(
                String.format(
                    "%s placed lava @ %s",
                    p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));

            p.getInventory().clear(p.getInventory().getHeldItemSlot());
          } else {
            p.getInventory()
                .setItem(p.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
            p.sendMessage(ChatColor.GRAY + "Lava placement is currently disabled.");

            event.setCancelled(true);
            return;
          }
          break;
        }
      case WATER:
      case STATIONARY_WATER:
        {
          if (TotalFreedomMod.allowWaterPlace) {
            TFM_Log.info(
                String.format(
                    "%s placed water @ %s",
                    p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));

            p.getInventory().clear(p.getInventory().getHeldItemSlot());
          } else {
            p.getInventory()
                .setItem(p.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
            p.sendMessage(ChatColor.GRAY + "Water placement is currently disabled.");

            event.setCancelled(true);
            return;
          }
          break;
        }
      case FIRE:
        {
          if (TotalFreedomMod.allowFirePlace) {
            TFM_Log.info(
                String.format(
                    "%s placed fire @ %s",
                    p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));

            p.getInventory().clear(p.getInventory().getHeldItemSlot());
          } else {
            p.getInventory()
                .setItem(p.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
            p.sendMessage(ChatColor.GRAY + "Fire placement is currently disabled.");

            event.setCancelled(true);
            return;
          }
          break;
        }
      case TNT:
        {
          if (TotalFreedomMod.allowExplosions) {
            TFM_Log.info(
                String.format(
                    "%s placed TNT @ %s",
                    p.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));

            p.getInventory().clear(p.getInventory().getHeldItemSlot());
          } else {
            p.getInventory()
                .setItem(p.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));

            p.sendMessage(ChatColor.GRAY + "TNT is currently disabled.");
            event.setCancelled(true);
            return;
          }
          break;
        }
    }
  }
  @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.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (!TotalFreedomMod.allowWaterPlace) {
                  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 (!TotalFreedomMod.allowLavaPlace) {
                  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 (!TotalFreedomMod.allowTntMinecarts) {
                  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:
              {
                TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
                if (playerdata.mobThrowerEnabled()) {
                  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:
              {
                TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
                if (playerdata.isMP44Armed()) {
                  if (playerdata.toggleMP44Firing()) {
                    playerdata.startArrowShooter(TotalFreedomMod.plugin);
                  } else {
                    playerdata.stopArrowShooter();
                  }

                  event.setCancelled(true);
                }
                break;
              }
            case BLAZE_ROD:
              {
                if (TotalFreedomMod.allowExplosions) {
                  if (TFM_SuperadminList.isSeniorAdmin(player, true)) {
                    Block target_block;

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

                    if (target_block != null) {
                      player.getWorld().createExplosion(target_block.getLocation(), 4F, true);
                      player.getWorld().strikeLightning(target_block.getLocation());
                    } else {
                      player.sendMessage("Can't resolve target block.");
                    }

                    event.setCancelled(true);
                  }
                }
                break;
              }
            case CARROT:
              {
                if (TotalFreedomMod.allowExplosions) {
                  if (TFM_SuperadminList.isSeniorAdmin(player, true)) {
                    Location player_location = player.getLocation().clone();

                    Vector player_pos = player_location.toVector().add(new Vector(0.0, 1.65, 0.0));
                    Vector player_dir = player_location.getDirection().normalize();

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

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

                    Block last_block = null;
                    for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                      Block test_block =
                          player_pos
                              .clone()
                              .add(player_dir.clone().multiply(offset))
                              .toLocation(player.getWorld())
                              .getBlock();

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

                      last_block = test_block;
                    }

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

                    event.setCancelled(true);
                  }
                }
                break;
              }
          }
          break;
        }
    }
  }
  @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.HIGH)
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String command = event.getMessage();
    Player p = event.getPlayer();

    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
    playerdata.incrementMsgCount();
    playerdata.setLastCommand(command);

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

      playerdata.resetMsgCount();

      TFM_Util.TFM_EntityWiper.wipeEntities(true, true);

      event.setCancelled(true);
      return;
    }

    if (playerdata.allCommandsBlocked()) {
      TFM_Util.playerMsg(p, "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_SuperadminList.isUserSuperadmin(p)) {
        for (String test_command : BLOCKED_MUTED_CMDS) {
          if (Pattern.compile("^/" + test_command.toLowerCase() + " ").matcher(command).find()) {
            p.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
            event.setCancelled(true);
            return;
          }
        }
      } else {
        playerdata.setMuted(false);
      }
    }

    if (TotalFreedomMod.preprocessLogEnabled) {
      TFM_Log.info(
          String.format(
              "[PREPROCESS_COMMAND] %s(%s): %s",
              p.getName(), ChatColor.stripColor(p.getDisplayName()), command),
          true);
    }

    command = command.toLowerCase().trim();

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

    if (!TFM_SuperadminList.isUserSuperadmin(p)) {
      for (Player pl : Bukkit.getOnlinePlayers()) {
        if (TFM_SuperadminList.isUserSuperadmin(pl)
            && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled()) {
          TFM_Util.playerMsg(pl, p.getName() + ": " + command);
        }
      }
    }
  }
  @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);
  }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (!TFM_ConfigEntry.TOSSMOB_ENABLED.getBoolean()) {
      playerMsg("Tossmob is currently disabled.");
      return true;
    }

    TFM_PlayerData playerData = TFM_PlayerData.getPlayerData(sender_p);

    EntityType creature = EntityType.PIG;
    if (args.length >= 1) {
      if ("off".equals(args[0])) {
        playerData.disableMobThrower();
        playerMsg("MobThrower is disabled.", ChatColor.GREEN);
        return true;
      }

      if (args[0].equalsIgnoreCase("list")) {
        playerMsg(
            "Supported mobs: " + StringUtils.join(TFM_Util.mobtypes.keySet(), ", "),
            ChatColor.GREEN);
        return true;
      }

      try {
        creature = TFM_Util.getEntityType(args[0]);
      } catch (Exception ex) {
        playerMsg(args[0] + " is not a supported mob type. Using a pig instead.", ChatColor.RED);
        playerMsg(
            "By the way, you can type /tossmob list to see all possible mobs.", ChatColor.RED);
        creature = EntityType.PIG;
      }
    }

    double speed = 1.0;
    if (args.length >= 2) {
      try {
        speed = Double.parseDouble(args[1]);
      } catch (NumberFormatException nfex) {
      }
    }

    if (speed < 1.0) {
      speed = 1.0;
    } else if (speed > 5.0) {
      speed = 5.0;
    }

    playerData.enableMobThrower(creature, speed);
    playerMsg(
        "MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + ".",
        ChatColor.GREEN);
    playerMsg(
        "Left click while holding a " + Material.BONE.toString() + " to throw mobs!",
        ChatColor.GREEN);
    playerMsg("Type '/tossmob off' to disable.  -By Madgeek1450", ChatColor.GREEN);

    sender_p.setItemInHand(new ItemStack(Material.BONE, 1));

    return true;
  }