Solved AsyncPlayerChatEvent does not cancel

Discussion in 'Plugin Development' started by james137137, Feb 2, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    james137137

    ok I was using PlayerChatEvent but I notice that we should be using AsyncPlayerChatEvent

    when i use the method event.setCancelled(true); it doesn't cancel
    if i use the method event.setMessage(); it doesn't work

    it seems that it the chat event will run notmater what. It was working perfectly fine with PlayerChatEvent with event.setCancelled. So i have no idea what i'm doing wrong

    Thanks

    James137137


    my code
    Code:
    @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent event) {
         
           
          if (event.isCancelled()) {
                return;
            }
           
         
         
          ChatChannel channel = new ChatChannel();
          Player talkingPlayer = event.getPlayer();
          String msg = event.getMessage();
          //FPlayer me = (FPlayer)FPlayers.i.get(talkingPlayer);
          String chatmode = ChatMode.getChatMode(talkingPlayer);
          if (!chatmode.equalsIgnoreCase("PUBLIC"))
                  {
                     
                      if (chatmode.equalsIgnoreCase("ALLY"))
                      {
                          event.setCancelled(true);
                          channel.fchata(talkingPlayer, msg);
                         
                      } else if (chatmode.equalsIgnoreCase("FACTION"))
                      {
                          event.setCancelled(true);
                          channel.fchat(talkingPlayer, msg);
                         
                      } else if (chatmode.equalsIgnoreCase("MOD"))
                      {
                          event.setCancelled(true);
                          channel.modChat(talkingPlayer, msg);
                         
                      } else if (chatmode.equalsIgnoreCase("ADMIN"))
                      {
                          event.setCancelled(true);
                          channel.adminChat(talkingPlayer, msg);
                         
                      }
                  }
                 
     
      }
    Code:
     public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new FactionChatListener(this), this);
            ChatMode.initialize();
            log.info("FactionChat: enabled");
            // Updater updater = new Updater(this, "factionchat", this.getFile(), Updater.UpdateType.DEFAULT, false); //do not uncomment until added a config file
            // see PM message
           
        }
     
  2. Offline

    chasechocolate

    What ChatMode are you in?
     
Thread Status:
Not open for further replies.

Share This Page