AsyncPlayerChatEvent setCancelled 不起作用
AsyncPlayerChatEvent setCancelled doesn't work
@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!");
}
}
}
他确实发出了“你不准发誓!”的信息。但他没有删除聊天消息
我假设错误来自一个已经取消的事件,所以我会在 rgnt 的评论旁边做另一件事,我也会忽略所有已取消的事件:
添加@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@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!");
}
}
}
他确实发出了“你不准发誓!”的信息。但他没有删除聊天消息
我假设错误来自一个已经取消的事件,所以我会在 rgnt 的评论旁边做另一件事,我也会忽略所有已取消的事件:
添加@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)