Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[New API] Disable Receive chat messages

Comments in 'Plugin Development' started by Adaasi, Sep 21, 2014.

  1. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    I want to block chat. This is my code:
    PHP:
    public function onChat(PlayerChatEvent $evt){
                
    $evt->setCancelled(true);
            }
        }
    It blocks only a player to send message. What is the code to block full chat (Send/Receive)?
  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    $evt->setMessage("");?
  3. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    I already tried with setMessage(""); It didn't work
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    What exactly are you trying?
  5. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    i think his trying to mute broadcast channel.

    try the trick with permission nodes.
  6. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    Exact
  7. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    So you want a command like /mute where people cannot see chat?
  8. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    Yes, Exactly :)
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What about messages sent from commands? Kick messages? And other things? You want nothing?

    Code (discouraged to all servers):
    PHP:
    public function onPkSend(DataPacketSendEvent $evt){
        if(
    $evt->getPacket() instanceof MessagePacket){
            
    $evt->setCancelled();
        }
    }
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In this way, all messages including SimpleAuth authenticate messages and etc are blocked. The player will receive no messages at all, including those you send by sendMessage().
  11. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    how about to certain players only?
  12. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    I attempted to do this in my plugin iChat, but it doesn't do anything.

    PHP:
      /**
      * @param PlayerChatEvent $event
      *
      * @priority HIGHEST
      * @ignoreCancelled true
      */
      
    public function onChat(PlayerChatEvent $event) {
        
    $this->checkData();
        if(!isset(
    $this->data["mute"][strtolower($event->getPlayer()->getName())])) {
          if(
    $this->checkMessage($event->getMessage()) || ($event->getPlayer()->hasPermission("ichat") || $event->getPlayer()->hasPermission("ichat.*") || $event->getPlayer()->hasPermission("ichat.bypass"))) {
            if(!isset(
    $this->data["chat"][strtolower($event->getPlayer()->getName())])) {
              
    $r = array();
              foreach(
    $this->getServer()->getOnlinePlayers() as $p) {
                if(!isset(
    $this->data["chat"][strtolower($p->getName())])) {
                  
    $r[] = $p;
                }
              }
              
    $event->setRecipients($r);
            } else {
              
    $event->getPlayer()->sendMessage("[iChat] You disabled your chat.");
              
    $event->setCancelled();
            }
          } else {
            
    $event->getPlayer()->sendMessage("[iChat] Message blocked.");
            
    $event->setCancelled();
          }
        } else {
          
    $event->getPlayer()->sendMessage("[iChat] You are muted.");
          
    $event->setCancelled();
        }
      }
    EvolSoft likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Check $evt->getPlayer()
    Falk likes this.

Share This Page

Advertisement