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

Solved Send a message to all players in a specific level

Comments in 'Plugin Development' started by Legoboy0215, Jul 5, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    How do I send a message to players in a specific level called hub?
    Last edited: Jul 5, 2015
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Iterate a foreach loop in the Player array returned by Level->getPlayers() and sendMessage every player in the array.

    PHP:
    foreach($server->getLevelByName("hub")->getPlayers()  as $p) {
      
    $p->sendMessage($message) ;
    }
    Last edited: Jul 5, 2015
    Andrey Nazarchuk likes this.
  3. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    I think :
    PHP:
    $this->getServer()->getPlayer("playername")->sendMessage("");
    You did not specify when the message is to be sent.
    Sorry for my bad english :p
  4. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    he said to a specific player
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think he means the thing in the title.
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Good?
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    BTW, what does foreach do?
  8. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    We want to know :
    1-if you need to send a message to all players in the level or only to a specific player.
    2-when you need to send that message

    Google is your friend http://php.net/manual/en/control-structures.foreach.php
    Last edited: Jul 5, 2015
    PEMapModder and Legoboy0215 like this.
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    No need... @PEMapModder was right..
    BTW, I changed the contents so...

Share This Page

Advertisement