@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event){
String msg = event.getMessage();
List<String> words = Main.plugin.getConfig().getStringList("swear-words");
for(int i = 0; i < words.size(); i++){
if(msg.contains(words.get(i))){
event.setCancelled(true);
event.getPlayer().sendMessage("You are not allowed to swear!");
}
}
}
he does give the message "You are not allowed to swear!" but he does not delete the chat message
I assume the error comes from an already cancelled event, so I'd do another thing next to rgnt's comment, I'd also ignore all the cancelled events:
Add @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)