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

Chating

Comments in 'Plugin Development' started by TryoneLegendZzz, Dec 23, 2015.

  1. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    ok so i am trying to make it where if a player is in a game it sends it to the player in the game here is my code
    PHP:
    public function onChat(PlayerChatEvent $ev){
         
    $p $ev->getPlayer();
         if(isset(
    $this->players[$p->getName()])){
             foreach(
    $this->players as $pl){
                 
    $pls=$this->getServer()->getPlayer($pl["id"]);
                 
    $ev->setRecipients($pls);
            
         }
    }
    }
    but i get this error
    Code:
     Server>  InvalidArgumentException: "Argument 1 passed to pocketmine\event\player\PlayerChatEvent::setRecipients() must be of the type array, object given, called in /plugins/TeamDeathMatch2/src/TDM2/Main.php on line 1847 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/event/player/PlayerChatEvent" at line 101
    any help?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Read.
    Code:
    PlayerChatEvent::setRecipients() must be of the type array, object given
    How is $pls an array?
    KubixQ likes this.
  3. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    still not understanding i even did
    PHP:
    $ev->setRecipients($this->players);
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    What's
    PHP:
    $this->players
    ?
  5. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    PHP:
    $pls=$this->getServer()->getPlayer($pl["id"]);
    ?

    »
    PHP:
    $pls $this->getServer()->getPlayer($pl["id"]);
    does that make differences?
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Is that a serious question? :/ No, it doesn't. The Problem is, that
    PHP:
    PlayerChatEvent::setRecipients(array $recipients)
    needs an array, not an object.
  7. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    What is he trying to do tho ? xD [ Why does she using PlayerChatEvent? Is he making prefixes or something ]
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    He wants to set the Recipients of a message.
  9. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    // No clues what need for but I have no clue of code either lol
  10. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
  11. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    Code:
    $this->players
    is an array of players in the game i am trying to make the messages send to the players in the game so pretty much PerGameChat
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes you are executing it for each player. But setRecipients is not addRecipient. Executing it multiple times (foreach) will just overwrite the value each time.
    PHP:
    public function onChat(PlayerChatEvent $ev){
      
    $p $ev->getPlayer();
      if(isset(
    $this->players[$p->getName()])){
        
    $players = [];
        foreach(
    $this->players as $pl){
          
    $players[] = $this->getServer()->getPlayer($pl["id"]);
        }
        
    $ev->setRecipients($players);
      }
    }
    Server::getPlayer() only returns one player. You have to add it to an array to make it become an array of players to pass to setRecipients.

Share This Page

Advertisement