Return String from PlayerChatEvent

Discussion in 'Plugin Development' started by MiBB3L, Oct 5, 2020.

  1. Offline

    MiBB3L

    Hello! I want to get a message a specific user sends and use it in another method. How can I do it? This is my current code:
    Code:
    @EventHandler
         public String recieveAdMessage(AsyncPlayerChatEvent e, Player player) {
            
             if(e.getPlayer() == player) {
                 return e.getMessage();
             }else {
                 return null;
             }
    But I donĀ“t know how to use this message in another method.
     
  2. Offline

    KarimAKL

  3. Offline

    Ducyooo

    you can store it in a variable like this
    Code:
         public String playerMessage;
        
        @EventHandler
        public String recieveAdMessage(AsyncPlayerChatEvent e, Player player) {
    
            if(e.getPlayer() == player) {
                playerMessage = e.getMessage();
            }else {
                return null;
            }
     
  4. Offline

    KarimAKL

    That's also wrong. That's not even how you define the methods for events.
     
  5. Offline

    Strahan

    It would help if you better described what you are trying to do. Typically, if something requires a message from chat I either perform the functionality in the chat event (if it's minor) or call the appropriate method from the chat event.
     

Share This Page