@EventHandler(priority = EventPriority.HIGH) 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).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); } command = command.toLowerCase().trim(); // Blocked commands if (TFM_CommandBlocker.getInstance().isCommandBlocked(command, event.getPlayer())) { // CommandBlocker handles messages and broadcasts event.setCancelled(true); } if (!TFM_AdminList.isSuperAdmin(player)) { for (Player pl : Bukkit.getOnlinePlayers()) { if (TFM_AdminList.isSuperAdmin(pl) && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled()) { TFM_Util.playerMsg(pl, player.getName() + ": " + command); } } } }
@EventHandler(priority = EventPriority.NORMAL) public void onPlayerChat(AsyncPlayerChatEvent event) { try { final Player player = event.getPlayer(); String message = event.getMessage().trim(); final TFM_PlayerData playerdata = TFM_PlayerData.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); } }