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

Solved Disable chat in specific world

Discussion in 'Development' started by KHAV, Sep 1, 2017.

  1. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Hello

    Is there any way to prevent chatting in a specific world? Not only writing but even messages sent by players from other worlds.
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Yes, there is. You might want to look in some chat mute plugins that already do this, although not per world.
    Basically do the same as here https://github.com/survanetwork/Bad...urva/badwordblocker/EventListener.php#L68-L77 just with a world check in place.
    Should look like:
    PHP:
    <?php
    /**
     * @author robske_110
     * @license GPLv3
     */
    class SomeClass implements Listener{
        
    /** @var array */
        
    public $chatDisabledLevelNames = [];
       
        public function 
    onPlayerChat(PlayerChatEvent $event){
            
    $player $event->getPlayer();
            if(
    in_array($player->getLevel()->getName(), $this->chatDisabledLevelNames)){
                
    $event->setCancelled();
            }
           
            
    $recipients $event->getRecipients();
            foreach(
    $recipients as $id => $recipient){
                if(
    in_array($recipient->getLevel()->getName(), $this->chatDisabledLevelNames)){
                    unset(
    $recipients[$id]);
                }
            }
            
    $event->setRecipients($recipients);
        }
    }
     
  3. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    I will tried this
     
  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.