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

Broadcast message after commande was used

Comments in 'Plugin Development' started by GuddaJ, Apr 9, 2016.

  1. GuddaJ
    Offline

    GuddaJ New Member

    Joined:
    Aug 18, 2015
    Posts:
    47
    Minecraft User:
    YoungRichNigger9
    i have sean some tutorial on how to start codding plugins and i also taked onligne class to have more better knoledge of php so i started to code my first plugin and it works but i want when you type de commande /heal
    that it broadcast a mesage what should i add bellow thisto broadcas a message like " you have been healed"

    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args){
    if(
    strtolower($cmd->getName()) === "heal"){
    $sender->setHealth($sender->getMaxHealth());

    return 
    true;
    }

    return 
    false;
    }

    }
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You did not make sure that $sender is a Player. Not every type of CommandSender has a setHealth() function. Learn OOP better ;)

    Anyway, the function you asked for is CommandSender->sendMessage($message)
    applqpak likes this.
  3. GuddaJ
    Offline

    GuddaJ New Member

    Joined:
    Aug 18, 2015
    Posts:
    47
    Minecraft User:
    YoungRichNigger9
    You say learn OOP better? im just new to codding can you give me a link to learn that
  4. GuddaJ
    Offline

    GuddaJ New Member

    Joined:
    Aug 18, 2015
    Posts:
    47
    Minecraft User:
    YoungRichNigger9
    And how to make the sender the player?
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You don't make the sender a player. You make sure the sender is a player. You check if a command sender is a player (not console) using `$sender instanceof Player`, where Player is the alias for pocketmine\Player.
    applqpak likes this.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    And for sending a message (It's not broadcasting if only one player sees it)
    PHP:
    Player::sendMessage($message)
    Still no idea?
    PHP:
    $player->sendMessage("You've been healed");
    applqpak likes this.
  7. GuddaJ
    Offline

    GuddaJ New Member

    Joined:
    Aug 18, 2015
    Posts:
    47
    Minecraft User:
    YoungRichNigger9
    im not actualy good with codding its my first project
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Seems like you are trying to code a plugin with little to no programming knowledge. Please learn PHP and OOP better and what @PEMapModder is saying will make more sense to you.
    applqpak likes this.
  9. GuddaJ
    Offline

    GuddaJ New Member

    Joined:
    Aug 18, 2015
    Posts:
    47
    Minecraft User:
    YoungRichNigger9
    where can i learn OOP? give me a link please
  10. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    applqpak likes this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    applqpak likes this.

Share This Page

Advertisement