Apply botspam to chat messages as well

This commit is contained in:
Shaun Bennett 2015-10-13 17:41:25 -04:00
parent a292fdb3c5
commit cb0d82174e

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
@ -54,6 +55,27 @@ public class BotSpamManager extends MiniPlugin
} }
} }
@EventHandler
public void onChatMessage(final AsyncPlayerChatEvent event)
{
for (final SpamText spamText : _spam)
{
if (spamText.isEnabled() && spamText.isSpam(event.getMessage()))
{
runSync(new Runnable()
{
@Override
public void run()
{
punishBot(event.getPlayer(), spamText);
}
});
event.setCancelled(true);
}
}
}
public void punishBot(Player player, final SpamText botText) public void punishBot(Player player, final SpamText botText)
{ {
_punish.AddPunishment(player.getName(), Category.Other, "Bot Spam #" + botText.getId(), "Chiss", 1, true, -1, true); _punish.AddPunishment(player.getName(), Category.Other, "Bot Spam #" + botText.getId(), "Chiss", 1, true, -1, true);