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

Message

Comments in 'Plugin Development' started by VoBIs, Aug 29, 2016.

  1. VoBIs
    Offline

    VoBIs New Member

    Joined:
    Jun 20, 2015
    Posts:
    18
    Minecraft User:
    VoBIs
    Good time, I have a question: how to send a message to all except a certain player, for example, Steve?
  2. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    PHP:
    $this->getServer()->getPlayer("Steve")->sendMessage("BlaBla");
  3. VoBIs
    Offline

    VoBIs New Member

    Joined:
    Jun 20, 2015
    Posts:
    18
    Minecraft User:
    VoBIs
    To All except Steve
  4. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    This might help, it might wrong tho
    PHP:
    $list $this->getServer()->getOnlinePlayers();
    $name "Steve";

    if(
    $list[$name]->getName() == "Steve") { //sorry i have to get player object with name Steve and get it name, then compare with Steve :P
           
    return false;
       } else {
           
    $list->sendMessage("Bla?");
     }
  5. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    Better this:

    PHP:
    foreach($this->getServer()->getOnlinePlayers() as $p)
             if(
    $p->getName() !== "Steve")
                    
    $p->sendMessage("Hello!");
    CraftYourBukkit likes this.
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You can't send a message to an array.
    Primus likes this.
  7. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    He can does because it's an players array but he can't do $list[$name] because $name is a string not an integer index.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Please explain to me how this should work.
    PHP:
    $this->getServer()->getOnlinePlayers()->sendMessage("Doesn't work.");
    Code:
    [Server thread/CRITICAL]: Error: "Call to a member function sendMessage() on array" (EXCEPTION) 
    Gamecrafter and Primus like this.
  9. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Any idea CraftYourBukkit? Need it either :/
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    function broadcastMessage($playersstring $messagePlayer $except null) {
       
    $players $players instanceof Player ? [$players] : $players;
       foreach(
    $players as $player) {
          if(
    $player !== $except$player->sendMessage($message);
       }
    }
    MyNameIsTriXz and VoBIs like this.
  11. Mat
    Offline

    Mat Active Member Plugin Developer

    Joined:
    Jun 15, 2014
    Posts:
    179
    Plugins:
    1
    Minecraft User:
    matcracker
    I didn't mean this, I have seen now the error. He didn't use $list[index]->sendMessage ("Hello");

Share This Page

Advertisement