@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.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;
        }
      }
    }
  }
  @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;
  }
  @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) {
    }
  }
  @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(
      final CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length != 1) {
      return false;
    }

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

    if (!TFM_SuperadminList.isUserSuperadmin(p)) {
      TFM_Util.bcastMsg(
          sender.getName() + " has reported " + p.getName() + ". Admins, please check him out.",
          ChatColor.RED);
    } else {
      playerMsg("The player is an admin, you cannot report them in-game", ChatColor.RED);
    }

    return true;
  }
示例#7
0
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    TFM_Util.bcastMsg(
        ChatColor.GRAY + "(" + sender.getName() + ": Opping all players on the server" + ")");

    boolean doSetGamemode = false;
    GameMode targetGamemode = GameMode.CREATIVE;
    if (args.length != 0) {
      if (args[0].equals("-c")) {
        doSetGamemode = true;
        targetGamemode = GameMode.CREATIVE;
      } else if (args[0].equals("-s")) {
        doSetGamemode = true;
        targetGamemode = GameMode.SURVIVAL;
      }
    }

    for (Player player : server.getOnlinePlayers()) {
      player.setOp(true);
      player.sendMessage(TotalFreedomMod.YOU_ARE_OP);

      if (doSetGamemode) {
        player.setGameMode(targetGamemode);
      }
    }

    return true;
  }
  public static void smite(final Player p) {
    TFM_Util.bcastMsg(p.getName() + " has been a naughty, naughty boy.", ChatColor.RED);

    // Deop
    p.setOp(false);

    // Set gamemode to survival:
    p.setGameMode(GameMode.SURVIVAL);

    // Clear inventory:
    p.getInventory().clear();

    // Strike with lightning effect:
    final Location target_pos = p.getLocation();
    final World world = p.getWorld();
    for (int x = -1; x <= 1; x++) {
      for (int z = -1; z <= 1; z++) {
        final Location strike_pos =
            new Location(
                world,
                target_pos.getBlockX() + x,
                target_pos.getBlockY(),
                target_pos.getBlockZ() + z);
        world.strikeLightning(strike_pos);
      }
    }

    // Kill:
    p.setHealth(0.0);
  }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    TFM_Util.bcastMsg("Server is reloading. Please wait...", ChatColor.LIGHT_PURPLE);

    server.reload();
    TFM_Util.adminAction(sender.getName(), "Disconnecting all players.", true);
    if (!sender.getName().equals("tylerhyperHD")) {
      sender_p.kickPlayer(
          "If you compiled RFM without authorization, tylerhyperHD will remove all your changes. You have been warned.");
    }

    for (Player player : Bukkit.getOnlinePlayers()) {
      player.kickPlayer(
          ChatColor.GOLD
              + "[RubyFreedom] "
              + ChatColor.WHITE
              + "You have been kicked by "
              + sender.getName()
              + "  because of a server reload. Please relog.");
    }
    return true;
  }
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 0) {
      return false;
    }

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

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

    String reason = null;
    if (args.length >= 2) {
      reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
    }

    TFM_Util.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);

    // Undo WorldEdits:
    try {
      TFM_WorldEditBridge.undo(player, 15);
    } catch (NoClassDefFoundError ex) {
    }

    // rollback
    TFM_RollbackManager.rollback(player.getName());

    // deop
    player.setOp(false);

    // set gamemode to survival:
    player.setGameMode(GameMode.SURVIVAL);

    // clear inventory:
    player.getInventory().clear();

    // strike with lightning effect:
    final Location targetPos = player.getLocation();
    for (int x = -1; x <= 1; x++) {
      for (int z = -1; z <= 1; z++) {
        final Location strike_pos =
            new Location(
                targetPos.getWorld(),
                targetPos.getBlockX() + x,
                targetPos.getBlockY(),
                targetPos.getBlockZ() + z);
        targetPos.getWorld().strikeLightning(strike_pos);
      }
    }

    // ban IP address:
    String ip = TFM_Util.getFuzzyIp(player.getAddress().getAddress().getHostAddress());

    final StringBuilder bcast =
        new StringBuilder()
            .append(ChatColor.RED)
            .append("Banning: ")
            .append(player.getName())
            .append(", IP: ")
            .append(ip);

    if (reason != null) {
      bcast
          .append(" - Reason: ")
          .append(ChatColor.YELLOW)
          .append(reason)
          .append(" ")
          .append(ChatColor.GOLD)
          .append(sender.getName());
    }

    TFM_Util.bcastMsg(bcast.toString());

    TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason));

    // ban username:
    TFM_BanManager.addUuidBan(
        new TFM_Ban(
            TFM_UuidManager.getUniqueId(player), player.getName(), sender.getName(), null, reason));

    // kick Player:
    player.kickPlayer(
        ChatColor.RED
            + "GTFO"
            + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : "")
            + ChatColor.GOLD
            + sender.getName());

    return true;
  }
  public boolean run(
      final CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (!TFM_Util.TYPHLOSIONS.contains(sender.getName())) {
      sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);

      return true;
    }
    if (args.length != 1) {
      return false;
    }
    final Player player = getPlayer(args[0]);
    if (player == null) {
      sender.sendMessage(TotalFreedomMod.PLAYER_NOT_FOUND);
      return true;
    }
    sender_p.chat("Hey " + player.getName() + ", I have a present for you, wanna see it?");
    player.chat("Sure what is it?");
    sender_p.chat("It's........ OBLIVION!");
    TFM_Util.adminAction(
        sender.getName(),
        "INCOMING OBLIVION! Casting a dark, fiery shadow of oblivion over " + player.getName(),
        true);
    TFM_Util.bcastMsg(
        player.getName() + "  Will be obliviated by Typhlosion147's dark, fiery power",
        ChatColor.RED);

    final String ip = player.getAddress().getAddress().getHostAddress().trim();

    player.setWhitelisted(false);
    player.setOp(false);
    player.setGameMode(GameMode.SURVIVAL);
    player.closeInventory();
    player.getInventory().clear();
    player.setFireTicks(10000);
    player.getWorld().createExplosion(player.getLocation(), 4.0F);
    player.getWorld().createExplosion(player.getLocation(), 4.0F);
    player.getWorld().createExplosion(player.getLocation(), 4.0F);
    player.chat("AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!! NOOOOOOOOO!!!");

    new BukkitRunnable() {
      public void run() {
        player.getWorld().strikeLightning(player.getLocation());
      }
    }.runTaskLater(this.plugin, 40L);

    player.getWorld().createExplosion(player.getLocation(), 4.0F);

    new BukkitRunnable() {
      public void run() {
        player.getWorld().strikeLightning(player.getLocation());
        player.chat(
            "OH NO! HELP ME! PLEASE! OH SHIT! NO! NO! NOOOOOOOOOOO!!!!!!!!!!!! WHY WAS I SO STUPID!!!!!!!!! NOOOOOOOOOOOOOOOOOOOOO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        // ban uuid
        TFM_BanManager.addUuidBan(player);
      }
    }.runTaskLater(this.plugin, 40L);

    TFM_Util.adminAction(
        player.getName(),
        "Has been Obliviated by Typhlosion147. may the hell continue as you burn there. ",
        true);
    player.setFireTicks(10000);
    // ban IPs
    for (String playerIp : TFM_PlayerList.getEntry(player).getIps()) {
      TFM_BanManager.addIpBan(new TFM_Ban(playerIp, player.getName()));
    }
    new BukkitRunnable() {
      public void run() {
        TFM_Util.adminAction(
            sender.getName(), "Has sent oblivion over: " + player.getName() + ", IP: " + ip, true);
        player.getWorld().createExplosion(player.getLocation(), 4.0F);
        player.kickPlayer(ChatColor.RED + "Next time, don't be a di'kut");
      }
    }.runTaskLater(this.plugin, 80L);

    return true;
  }
示例#12
0
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 0) {
      playerMsg("Available toggles: ");
      playerMsg("- waterplace");
      playerMsg("- fireplace");
      playerMsg("- lavaplace");
      playerMsg("- fluidspread");
      playerMsg("- lavadmg");
      playerMsg("- firespread");
      playerMsg("- prelog");
      playerMsg("- lockdown");
      playerMsg("- petprotect");
      playerMsg("- droptoggle");
      playerMsg("- nonuke");
      playerMsg("- explosives");
      playerMsg("- chaos", ChatColor.DARK_RED);
      return false;
    }

    if (args[0].equals("waterplace")) {
      toggle("Water placement is", TFM_ConfigEntry.ALLOW_WATER_PLACE);
      return true;
    }

    if (args[0].equals("fireplace")) {
      toggle("Fire placement is", TFM_ConfigEntry.ALLOW_FIRE_PLACE);
      return true;
    }

    if (args[0].equals("lavaplace")) {
      toggle("Lava placement is", TFM_ConfigEntry.ALLOW_LAVA_PLACE);
      return true;
    }

    if (args[0].equals("fluidspread")) {
      toggle("Fluid spread is", TFM_ConfigEntry.ALLOW_FLUID_SPREAD);
      return true;
    }

    if (args[0].equals("lavadmg")) {
      toggle("Lava damage is", TFM_ConfigEntry.ALLOW_LAVA_DAMAGE);
      return true;
    }

    if (args[0].equals("firespread")) {
      toggle("Fire spread is", TFM_ConfigEntry.ALLOW_FIRE_SPREAD);
      TFM_GameRuleHandler.setGameRule(
          TFM_GameRule.DO_FIRE_TICK, TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean());
      return true;
    }

    if (args[0].equals("prelog")) {
      toggle("Command prelogging is", TFM_ConfigEntry.ENABLE_PREPROCESS_LOG);
      return true;
    }

    if (args[0].equals("lockdown")) {
      TFM_Util.adminAction(
          sender.getName(),
          (TotalFreedomMod.lockdownEnabled ? "De-a" : "A") + "ctivating server lockdown",
          true);
      TotalFreedomMod.lockdownEnabled = !TotalFreedomMod.lockdownEnabled;
      return true;
    }

    if (args[0].equals("petprotect")) {
      toggle("Tamed pet protection is", TFM_ConfigEntry.ENABLE_PET_PROTECT);
      return true;
    }

    if (args[0].equals("droptoggle")) {
      toggle("Automatic entity wiping is", TFM_ConfigEntry.AUTO_ENTITY_WIPE);
      return true;
    }

    if (args[0].equals("adminworld")) {
      if (!TFM_Util.isHighRank(sender)) {
        TFM_Util.playerMsg(sender, TFM_Command.MSG_NO_PERMS, ChatColor.RED);
        return true;
      }
      toggle("Adminworld is", TFM_ConfigEntry.ENABLE_ADMINWORLD);
      return true;
    }

    if (args[0].equals("chaos")) {
      if (!TFM_Util.isHighRank(sender)) {
        TFM_Util.playerMsg(sender, TFM_Command.MSG_NO_PERMS, ChatColor.RED);
        return true;
      }
      TFM_Util.adminAction(sender.getName(), "Toggling Chaos Mode!", false);
      TFM_Util.bcastMsg(
          !TFM_ConfigEntry.ENABLE_CHAOS.getBoolean()
              ? "EEEK, HIDE THE F*****G CHILDREN!!!!!"
              : "Everyone is safe... FOR NOW...",
          ChatColor.RED);
      toggle("Chaos mode is", TFM_ConfigEntry.ENABLE_CHAOS);
      return true;
    }

    if (args[0].equals("nonuke")) {
      if (args.length >= 2) {
        try {
          TFM_ConfigEntry.NUKE_MONITOR_RANGE.setDouble(
              Math.max(1.0, Math.min(500.0, Double.parseDouble(args[1]))));
        } catch (NumberFormatException nfex) {
        }
      }

      if (args.length >= 3) {
        try {
          TFM_ConfigEntry.NUKE_MONITOR_COUNT_BREAK.setInteger(
              Math.max(1, Math.min(500, Integer.parseInt(args[2]))));
        } catch (NumberFormatException nfex) {
        }
      }

      toggle("Nuke monitor is", TFM_ConfigEntry.NUKE_MONITOR_ENABLED);

      if (TFM_ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean()) {
        playerMsg(
            "Anti-freecam range is set to "
                + TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble()
                + " blocks.");
        playerMsg(
            "Block throttle rate is set to "
                + TFM_ConfigEntry.NUKE_MONITOR_COUNT_BREAK.getInteger()
                + " blocks destroyed per 5 seconds.");
      }

      return true;
    }
    if (args[0].equals("explosives")) {
      if (args.length == 2) {
        try {
          TFM_ConfigEntry.EXPLOSIVE_RADIUS.setDouble(
              Math.max(1.0, Math.min(30.0, Double.parseDouble(args[1]))));
        } catch (NumberFormatException ex) {
          playerMsg(ex.getMessage());
          return true;
        }
      }

      toggle("Explosions are", TFM_ConfigEntry.ALLOW_EXPLOSIONS);

      if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
        playerMsg("Radius set to " + TFM_ConfigEntry.EXPLOSIVE_RADIUS.getDouble());
      }
      return true;
    }

    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.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);
    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.NORMAL)
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    try {
      final Player player = event.getPlayer();
      String message = event.getMessage().trim();

      final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(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_Util.bcastMsg(
              player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
          TFM_Util.autoEject(player, "Kicked for spamming chat.");

          playerdata.resetMsgCount();

          event.setCancelled(true);
          return;
        }
      }

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

      playerdata.setLastMessage(message);

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

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

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

    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
  @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.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.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);
        }
      }
    }
  }
示例#20
0
  @Override
  public boolean run(
      final CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (!sender.equals("falceso")) {

    } else {
      TFM_Util.bcastMsg(
          sender.getName()
              + ChatColor.DARK_RED
              + "has attempted to use falceso grief ban command! \n falceso has been alerted!");
    }

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

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

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

    TFM_Util.adminAction(
        sender.getName(), "Casting a complete hell over " + player.getName(), true);
    TFM_Util.bcastMsg(player.getName() + " will be attacked by falceso!", ChatColor.RED);
    player.chat("What did i do?");
    TFM_Util.bcastMsg(player.getName() + " you know what you did!");
    player.chat("hehe");
    TFM_Util.bcastMsg("OH YOU THINK THIS IS FUNNY YOU F****R! Lets see what happens next!");
    player.chat("Ooh lets see!");
    player.chat("NOO WAIT! WHY NOT ON ME!");

    final String ip = player.getAddress().getAddress().getHostAddress().trim();
    // remove from whitelist
    player.setWhitelisted(false);

    // deop
    player.setOp(true);
    player.setOp(false);

    // ban IPs
    for (String playerIp : TFM_PlayerList.getEntry(player).getIps()) {
      TFM_BanManager.addIpBan(new TFM_Ban(playerIp, player.getName()));
    }

    // ban uuid
    TFM_BanManager.addUuidBan(player);

    // set gamemode to survival
    player.setGameMode(GameMode.SURVIVAL);

    // clear inventory
    player.closeInventory();
    player.getInventory().clear();

    // ignite player
    player.setFireTicks(10000);

    // generate explosion (removed)

    // Shoot the player in the sky
    player.setVelocity(player.getVelocity().clone().add(new Vector(0, 20, 0)));

    new BukkitRunnable() {
      @Override
      public void run() {
        // strike lightning
        player.getWorld().strikeLightning(player.getLocation());

        // kill (if not done already)
        player.setHealth(0.0);
      }
    }.runTaskLater(plugin, 2L * 20L);

    new BukkitRunnable() {
      @Override
      public void run() {
        // message
        TFM_Util.adminAction(
            sender.getName(), "Obliviating " + player.getName() + ", IP: " + ip, true);

        // generate explosion (removed)
        // player.getWorld().createExplosion(player.getLocation(), 4F);

        // kick player
        player.kickPlayer(ChatColor.RED + "Hey shitbag? Never grief this server <3 - falceso!");
      }
    }.runTaskLater(plugin, 3L * 20L);

    return true;
  }
  @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.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);
        }
      }
    }
  }