Added basic API for working with titles

This commit is contained in:
Dylan K. Taylor 2017-03-29 20:02:16 +01:00
parent 3e76c3a6dd
commit 6b747f9272

View File

@ -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
*