@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!");
}
}
}
他确实传达了这样的信息:“你不能骂人!”但他没有删除聊天信息
1条答案
按热度按时间zhte4eai1#
我假设错误来自一个已经取消的事件,所以我会在rgnt的评论旁边做另一件事,我也会忽略所有取消的事件:
添加
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)