mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Player: reduce SetTitlePacket creation boilerplate
it's better to encapsulate all this logic in one place so that third party developers can more easily understand this, and also to reduce the amount of crap we have in Player.
This commit is contained in:
@ -69,4 +69,44 @@ class SetTitlePacket extends DataPacket implements ClientboundPacket{
|
||||
public function handle(SessionHandler $handler) : bool{
|
||||
return $handler->handleSetTitle($this);
|
||||
}
|
||||
|
||||
private static function type(int $type) : self{
|
||||
$result = new self;
|
||||
$result->type = $type;
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function text(int $type, string $text) : self{
|
||||
$result = self::type($type);
|
||||
$result->text = $text;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function title(string $text) : self{
|
||||
return self::text(self::TYPE_SET_TITLE, $text);
|
||||
}
|
||||
|
||||
public static function subtitle(string $text) : self{
|
||||
return self::text(self::TYPE_SET_SUBTITLE, $text);
|
||||
}
|
||||
|
||||
public static function actionBarMessage(string $text) : self{
|
||||
return self::text(self::TYPE_SET_ACTIONBAR_MESSAGE, $text);
|
||||
}
|
||||
|
||||
public static function clearTitle() : self{
|
||||
return self::type(self::TYPE_CLEAR_TITLE);
|
||||
}
|
||||
|
||||
public static function resetTitleOptions() : self{
|
||||
return self::type(self::TYPE_RESET_TITLE);
|
||||
}
|
||||
|
||||
public static function setAnimationTimes(int $fadeIn, int $stay, int $fadeOut) : self{
|
||||
$result = self::type(self::TYPE_SET_ANIMATION_TIMES);
|
||||
$result->fadeInTime = $fadeIn;
|
||||
$result->stayTime = $stay;
|
||||
$result->fadeOutTime = $fadeOut;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user