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

PlayerChatEvent and setRecipients

Comments in 'Plugin Development' started by EvolSoft, Jan 15, 2016.

  1. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Hi all,
    I've got a simple question about PlayerChatEvent and its function setRecipients. I want to prevent a player from sending and receiving messages. How can I do this? How does setRecipients work and how should I use it in this case?
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    applqpak and PEMapModder like this.
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    For sending, just cancel the PlayerChatEvent.
    PlayerChatEvent::setRecipients($array);
    while $array is an array out of Player Objects. For Example:
    PHP:
    $array = array();
    foreach(
    $this->getServer()->getOnlinePlayers() as $pl){
      if(
    strpos(strtolower($pl->getName()), "a"){
        
    array_push($array$pl);
      }
    }
    $event->setRecipients($array);
    in PlayerChatEvent will put every Player with an "a" in his name as a Recipient. Every Player that is not in the array $array, will not recieve the message.
    applqpak likes this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1. Get all recipients.
    2. For each $i as $recipient, if you want to block $recipient, unset $recipients[$i]
    3. Set all recipients to your array, after iteration.
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Wouldn't you need to substract 1 of the count?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Nevermind, misread it. Thought you wanted to count() the array and use for(), sorry I was brain AFK.
  8. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Thanks for all replies :)
    Now I understand how it works. Maybe it was a simple English grammar related thing (I didn't know that recipients in English are same as receivers or "destinatari" in Italian so I didn't know what that function was used for :p)

Share This Page

Advertisement