Member
Posts: 422
Map<String, Long> lastMessageTime = new HashMap<String, Long>();
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event){
String playerName = event.getPlayer().getName();
if(this.lastMessageTime.containsKey(playerName)){
long lastMessage = this.lastMessageTime.get(playerName);
long currentMessage = System.currentTimeMillis();
long difference = currentMessage - lastMessage;
String convertlong = Long.toString(difference);
int getdifference = Integer.valueOf(convertlong);
if (getdifference < plugin.getConfig().getInt("AntiSpam.AllowedMessageInterval")){
event.getPlayer().sendMessage(ChatColor.DARK_RED + "Message cancelled due to chat spam");
event.setCancelled(true);
}