1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Change/set player's chat message?

Discussion in 'Development' started by WinterBuild7074, Sep 3, 2017.

  1. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I'm trying to change/set the player's chat message to something else. I tried this plugin too.
    Can anyone help?

    PHP:
    public function onChat(PlayerChatEvent $event) {
            
    $message str_ireplace("hello""bye"$event->getMessage());
            
    $event->setMessage($message);
    }
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    did you make sure you registered your event listener?
     
  3. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
  4. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Try debugging your code.
     
  5. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I did already, but it didn't help me fix the problem.
     
  6. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Can you please share full plugin to give us more information about plugin?
     
    Karanpatel567 likes this.
  7. Aviv

    Aviv Baby Zombie

    Messages:
    156
    This problem might by caused by another plugin setting the message after your plugin
    PHP:
    /*
    * @param PlayerChatEvent $event
    * @priority HIGHEST
    */
    This code above your PlayerChatEvent function (the one that runs when PlayerChatEvent is called) will make the event run AFTER the event was called on other plugins,
    also, the priority goes from LOWEST to HIGHEST
    Try that and tell if it worked
     
  8. KYUMA

    KYUMA Silverfish

    Messages:
    16
    GitHub:
    Ky75
    Hi =), Error in Line 2 (str_ireplace)
    PHP:
    public function onChat(PlayerChatEvent $event){
      
    $message str_replace("hello""bye"$event->getMessage());
      
    $event->setMessage($message);
    }
    Solved?
     
  9. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    HIGHEST priority should actually make it be called second to last
     
    Muqsit likes this.
  10. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    But you shouldn't be changing anything once the priority reaches MONITOR. So HIGHEST is the last priority that is relevant here, as the OP is changing something.

    @KYUMA str_ireplace() is a PHP function, it's the case-insensitive version of str_replace().

    @WinterBuild7074 Any error messages? If you echo something when the event is called, do you see it on console?
     
    jasonwynn10 likes this.
  11. xZeroMCPE

    xZeroMCPE Witch

    Messages:
    67
    GitHub:
    xZeroMCPE
    I recommend you guys learn more about Priorities.. and how they work!

    Here's something that'll get your mind straight!
     
    Muqsit and jasonwynn10 like this.
  12. Aviv

    Aviv Baby Zombie

    Messages:
    156
    You learn new things every day :D
     
  13. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The priority is totally irrelevant with whether the event is cancelled, since you are not tracking @ignoreCancelled.
     
  14. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Wow, suddenly my started working.
     
  15. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    ID10T error
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.