diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 1a32eeaca..27b29e6e8 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3398,6 +3398,75 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } + /** + * Adds a title text to the user's screen, with an optional subtitle. + * + * @param string $title + * @param string $subtitle + * @param int $fadeIn Duration in ticks for fade-in. If -1 is given, client-sided defaults will be used. + * @param int $stay Duration in ticks to stay on screen for + * @param int $fadeOut Duration in ticks for fade-out. + */ + public function addTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1){ + $this->setTitleDuration($fadeIn, $stay, $fadeOut); + $this->sendTitleText($title, SetTitlePacket::TYPE_SET_TITLE); + if($subtitle !== ""){ + $this->sendTitleText($subtitle, SetTitlePacket::TYPE_SET_SUBTITLE); + } + } + + /** + * Adds small text to the user's screen. + * + * @param string $message + */ + public function addActionBarMessage(string $message){ + $this->sendTitleText($message, SetTitlePacket::TYPE_SET_ACTIONBAR_MESSAGE); + } + + /** + * Removes the title from the client's screen. + */ + public function removeTitles(){ + $pk = new SetTitlePacket(); + $pk->type = SetTitlePacket::TYPE_CLEAR_TITLE; + $this->dataPacket($pk); + } + + /** + * Sets the title duration. + * + * @param int $fadeIn Title fade-in time in ticks. + * @param int $stay Title stay time in ticks. + * @param int $fadeOut Title fade-out time in ticks. + */ + public function setTitleDuration(int $fadeIn, int $stay, int $fadeOut){ + if($fadeIn >= 0 and $stay >= 0 and $fadeOut >= 0){ + $pk = new SetTitlePacket(); + $pk->type = SetTitlePacket::TYPE_SET_ANIMATION_TIMES; + $pk->fadeInTime = $fadeIn; + $pk->stayTime = $stay; + $pk->fadeOutTime = $fadeOut; + $this->dataPacket($pk); + } + } + + /** + * Internal function used for sending titles. + * + * @param string $title + * @param int $type + * @param int $fadeIn + * @param int $stay + * @param int $fadeOut + */ + protected function sendTitleText(string $title, int $type){ + $pk = new SetTitlePacket(); + $pk->type = $type; + $pk->text = $title; + $this->dataPacket($pk); + } + /** * Sends a direct chat message to a player *