@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);
    }
  }
Пример #2
0
 @Override
 public boolean run(
     CommandSender sender,
     Player sender_p,
     Command cmd,
     String commandLabel,
     String[] args,
     boolean senderIsConsole) {
   sender_p.chat("Gonna apply! Doing /admininfo, or /ai!");
   TFM_Util.playerMsg(sender_p, "Really want to be admin?", ChatColor.BLUE);
   TFM_Util.playerMsg(
       sender_p, "Go to our forums at http://boomfreedom.boards.net/", ChatColor.GREEN);
   TFM_Util.playerMsg(
       sender_p,
       "Don't ask for admins to look at the application, it will lower your chances of being accepted.",
       ChatColor.RED);
   return true;
 }
Пример #3
0
  public static void gotoWorld(Player player, String targetWorld) {
    if (player == null) {
      return;
    }

    if (player.getWorld().getName().equalsIgnoreCase(targetWorld)) {
      playerMsg(player, "Going to main world.", ChatColor.GRAY);
      player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
      return;
    }

    for (World world : Bukkit.getWorlds()) {
      if (world.getName().equalsIgnoreCase(targetWorld)) {
        playerMsg(player, "Going to world: " + targetWorld, ChatColor.GRAY);
        player.teleport(world.getSpawnLocation());
        return;
      }
    }

    playerMsg(player, "World " + targetWorld + " not found.", ChatColor.GRAY);
  }
 // Disable GM/GOD PVP
 @EventHandler
 public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
   if (event.getEntity() instanceof Player) {
     if (event.getDamager() instanceof Player) {
       Player player = (Player) event.getDamager();
       if (player.getGameMode() == GameMode.CREATIVE || FOPM_TFM_Util.inGod(player)) {
         TFM_Util.playerMsg(player, "NO GM / GOD PVP!", ChatColor.DARK_RED);
         event.setCancelled(true);
       }
     }
     if (event.getDamager() instanceof Arrow) {
       Arrow arrow = (Arrow) event.getDamager();
       if (arrow.getShooter() instanceof Player) {
         Player player = (Player) arrow.getShooter();
         if (player.getGameMode() == GameMode.CREATIVE || FOPM_TFM_Util.inGod(player)) {
           TFM_Util.playerMsg(player, "NO GM / GOD PVP!", ChatColor.DARK_RED);
           event.setCancelled(true);
         }
       }
     }
   }
 }
Пример #5
0
 public static void reportAction(Player reporter, Player reported, String report) {
   for (Player player : Bukkit.getOnlinePlayers()) {
     if (TFM_AdminList.isSuperAdmin(player)) {
       playerMsg(
           player,
           ChatColor.RED
               + "[REPORTS] "
               + ChatColor.GOLD
               + reporter.getName()
               + " has reported "
               + reported.getName()
               + " for "
               + report);
     }
   }
 }
Пример #6
0
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length == 1) {
      if (!args[0].equals("reload")) {
        return false;
      }

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

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

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

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

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

    return true;
  }
  @EventHandler(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.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);
        }
      }
    }
  }
Пример #9
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.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.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 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.HIGHEST)
  @SuppressWarnings("null")
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String command = event.getMessage();
    final Player player = event.getPlayer();

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

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

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

      playerdata.resetMsgCount();

      TFM_Util.TFM_EntityWiper.wipeEntities(true, true);

      event.setCancelled(true);
      return;
    }

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

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

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

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

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

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

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

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

    CommandMode commandMode = null;

    if (args.length == 0) {
      commandMode = CommandMode.TELEPORT;
    } else if (args.length >= 2) {
      if ("guest".equalsIgnoreCase(args[0])) {
        commandMode = CommandMode.GUEST;
      } else if ("time".equalsIgnoreCase(args[0])) {
        commandMode = CommandMode.TIME;
      } else if ("weather".equalsIgnoreCase(args[0])) {
        commandMode = CommandMode.WEATHER;
      }
    }

    if (commandMode == null) {
      return false;
    }

    try {
      switch (commandMode) {
        case TELEPORT:
          {
            if (!(sender instanceof Player) || sender_p == null) {
              return true;
            }

            World adminWorld = null;
            try {
              adminWorld = TFM_AdminWorld.getInstance().getWorld();
            } catch (Exception ex) {
            }

            if (adminWorld == null || sender_p.getWorld() == adminWorld) {
              playerMsg("Going to the main world.");
              sender_p.teleport(server.getWorlds().get(0).getSpawnLocation());
            } else {
              if (TFM_AdminWorld.getInstance().canAccessWorld(sender_p)) {
                playerMsg("Going to the AdminWorld.");
                TFM_AdminWorld.getInstance().sendToWorld(sender_p);
              } else {
                playerMsg("You don't have permission to access the AdminWorld.");
              }
            }

            break;
          }
        case GUEST:
          {
            if (args.length == 2) {
              if ("list".equalsIgnoreCase(args[1])) {
                playerMsg(
                    "AdminWorld guest list: " + TFM_AdminWorld.getInstance().guestListToString());
              } else if ("purge".equalsIgnoreCase(args[1])) {
                assertCommandPerms(sender, sender_p);
                TFM_AdminWorld.getInstance().purgeGuestList();
                TFM_Util.adminAction(sender.getName(), "AdminWorld guest list purged.", false);
              } else {
                return false;
              }
            } else if (args.length == 3) {
              assertCommandPerms(sender, sender_p);

              if ("add".equalsIgnoreCase(args[1])) {
                final Player player = getPlayer(args[2]);

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

                if (TFM_AdminWorld.getInstance().addGuest(player, sender_p)) {
                  TFM_Util.adminAction(
                      sender.getName(), "AdminWorld guest added: " + player.getName(), false);
                } else {
                  playerMsg("Could not add player to guest list.");
                }
              } else if ("remove".equals(args[1])) {
                final Player player = TFM_AdminWorld.getInstance().removeGuest(args[2]);
                if (player != null) {
                  TFM_Util.adminAction(
                      sender.getName(), "AdminWorld guest removed: " + player.getName(), false);
                } else {
                  playerMsg("Can't find guest entry for: " + args[2]);
                }
              } else {
                return false;
              }
            }

            break;
          }
        case TIME:
          {
            assertCommandPerms(sender, sender_p);

            if (args.length == 2) {
              TFM_AdminWorld.TimeOfDay timeOfDay = TFM_AdminWorld.TimeOfDay.getByAlias(args[1]);
              if (timeOfDay != null) {
                TFM_AdminWorld.getInstance().setTimeOfDay(timeOfDay);
                playerMsg("AdminWorld time set to: " + timeOfDay.name());
              } else {
                playerMsg("Invalid time of day. Can be: sunrise, noon, sunset, midnight");
              }
            } else {
              return false;
            }

            break;
          }
        case WEATHER:
          {
            assertCommandPerms(sender, sender_p);

            if (args.length == 2) {
              TFM_AdminWorld.WeatherMode weatherMode =
                  TFM_AdminWorld.WeatherMode.getByAlias(args[1]);
              if (weatherMode != null) {
                TFM_AdminWorld.getInstance().setWeatherMode(weatherMode);
                playerMsg("AdminWorld weather set to: " + weatherMode.name());
              } else {
                playerMsg("Invalid weather mode. Can be: off, rain, storm");
              }
            } else {
              return false;
            }

            break;
          }
        default:
          {
            return false;
          }
      }
    } catch (PermissionDeniedException ex) {
      sender.sendMessage(ex.getMessage());
    }

    return true;
  }