asyncplayerchatevent setcancelled不工作

tgabmvqs  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(232)
@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!");
              }
          }
      }

他确实传达了这样的信息:“你不能骂人!”但他没有删除聊天信息

zhte4eai

zhte4eai1#

我假设错误来自一个已经取消的事件,所以我会在rgnt的评论旁边做另一件事,我也会忽略所有取消的事件:
添加 @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)

相关问题