Rename TranslationContainer -> Translatable

This commit is contained in:
Dylan K. Taylor 2021-08-15 16:17:46 +01:00
parent 5bdcc0339f
commit 789a669395
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
16 changed files with 757 additions and 757 deletions

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\build\generate_known_translation_apis; namespace pocketmine\build\generate_known_translation_apis;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use Webmozart\PathUtil\Path; use Webmozart\PathUtil\Path;
use function array_map; use function array_map;
use function count; use function count;
@ -132,7 +132,7 @@ HEADER;
$parameterRegex = '/{%(.+?)}/'; $parameterRegex = '/{%(.+?)}/';
$translationContainerClass = (new \ReflectionClass(TranslationContainer::class))->getShortName(); $translationContainerClass = (new \ReflectionClass(Translatable::class))->getShortName();
foreach($languageDefinitions as $key => $value){ foreach($languageDefinitions as $key => $value){
$parameters = []; $parameters = [];
if(preg_match_all($parameterRegex, $value, $matches) > 0){ if(preg_match_all($parameterRegex, $value, $matches) > 0){

View File

@ -46,7 +46,7 @@ use pocketmine\event\server\QueryRegenerateEvent;
use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\KnownTranslationFactory;
use pocketmine\lang\Language; use pocketmine\lang\Language;
use pocketmine\lang\LanguageNotFoundException; use pocketmine\lang\LanguageNotFoundException;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\nbt\BigEndianNbtSerializer; use pocketmine\nbt\BigEndianNbtSerializer;
use pocketmine\nbt\NbtDataException; use pocketmine\nbt\NbtDataException;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
@ -1121,7 +1121,7 @@ class Server{
/** /**
* @param CommandSender[]|null $recipients * @param CommandSender[]|null $recipients
*/ */
public function broadcastMessage(TranslationContainer|string $message, ?array $recipients = null) : int{ public function broadcastMessage(Translatable|string $message, ?array $recipients = null) : int{
$recipients = $recipients ?? $this->getBroadcastChannelSubscribers(self::BROADCAST_CHANNEL_USERS); $recipients = $recipients ?? $this->getBroadcastChannelSubscribers(self::BROADCAST_CHANNEL_USERS);
foreach($recipients as $recipient){ foreach($recipients as $recipient){

View File

@ -29,7 +29,7 @@ namespace pocketmine\command;
use pocketmine\command\utils\CommandException; use pocketmine\command\utils\CommandException;
use pocketmine\console\ConsoleCommandSender; use pocketmine\console\ConsoleCommandSender;
use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\KnownTranslationFactory;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\permission\PermissionManager; use pocketmine\permission\PermissionManager;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\timings\Timings; use pocketmine\timings\Timings;
@ -230,7 +230,7 @@ abstract class Command{
$this->usageMessage = $usage; $this->usageMessage = $usage;
} }
public static function broadcastCommandMessage(CommandSender $source, TranslationContainer|string $message, bool $sendToSource = true) : void{ public static function broadcastCommandMessage(CommandSender $source, Translatable|string $message, bool $sendToSource = true) : void{
$users = $source->getServer()->getBroadcastChannelSubscribers(Server::BROADCAST_CHANNEL_ADMINISTRATIVE); $users = $source->getServer()->getBroadcastChannelSubscribers(Server::BROADCAST_CHANNEL_ADMINISTRATIVE);
$result = KnownTranslationFactory::chat_type_admin($source->getName(), $message); $result = KnownTranslationFactory::chat_type_admin($source->getName(), $message);
$colored = $result->prefix(TextFormat::GRAY . TextFormat::ITALIC); $colored = $result->prefix(TextFormat::GRAY . TextFormat::ITALIC);

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command; namespace pocketmine\command;
use pocketmine\lang\Language; use pocketmine\lang\Language;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\permission\Permissible; use pocketmine\permission\Permissible;
use pocketmine\Server; use pocketmine\Server;
@ -32,7 +32,7 @@ interface CommandSender extends Permissible{
public function getLanguage() : Language; public function getLanguage() : Language;
public function sendMessage(TranslationContainer|string $message) : void; public function sendMessage(Translatable|string $message) : void;
public function getServer() : Server; public function getServer() : Server;

View File

@ -29,7 +29,7 @@ use pocketmine\item\enchantment\EnchantmentInstance;
use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\enchantment\VanillaEnchantments;
use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\KnownTranslationFactory;
use pocketmine\lang\KnownTranslationKeys; use pocketmine\lang\KnownTranslationKeys;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\permission\DefaultPermissionNames; use pocketmine\permission\DefaultPermissionNames;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
use function count; use function count;
@ -86,7 +86,7 @@ class EnchantCommand extends VanillaCommand{
$item->addEnchantment(new EnchantmentInstance($enchantment, $level)); $item->addEnchantment(new EnchantmentInstance($enchantment, $level));
$player->getInventory()->setItemInHand($item); $player->getInventory()->setItemInHand($item);
self::broadcastCommandMessage($sender, new TranslationContainer(KnownTranslationKeys::COMMANDS_ENCHANT_SUCCESS, [$player->getName()])); self::broadcastCommandMessage($sender, new Translatable(KnownTranslationKeys::COMMANDS_ENCHANT_SUCCESS, [$player->getName()]));
return true; return true;
} }
} }

View File

@ -28,7 +28,7 @@ use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\KnownTranslationFactory;
use pocketmine\lang\KnownTranslationKeys; use pocketmine\lang\KnownTranslationKeys;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\permission\DefaultPermissionNames; use pocketmine\permission\DefaultPermissionNames;
use pocketmine\player\GameMode; use pocketmine\player\GameMode;
use pocketmine\player\Player; use pocketmine\player\Player;
@ -81,7 +81,7 @@ class GamemodeCommand extends VanillaCommand{
if($target === $sender){ if($target === $sender){
Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_gamemode_success_self($gameMode->getTranslationKey())); Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_gamemode_success_self($gameMode->getTranslationKey()));
}else{ }else{
$target->sendMessage(new TranslationContainer(KnownTranslationKeys::GAMEMODE_CHANGED, [$gameMode->getTranslationKey()])); $target->sendMessage(new Translatable(KnownTranslationKeys::GAMEMODE_CHANGED, [$gameMode->getTranslationKey()]));
Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_gamemode_success_other($gameMode->getTranslationKey(), $target->getName())); Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_gamemode_success_other($gameMode->getTranslationKey(), $target->getName()));
} }
} }

View File

@ -27,7 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\KnownTranslationKeys; use pocketmine\lang\KnownTranslationKeys;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
use function is_numeric; use function is_numeric;
use function substr; use function substr;
@ -83,11 +83,11 @@ abstract class VanillaCommand extends Command{
$v = (int) $input; $v = (int) $input;
if($v > $max){ if($v > $max){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%" . KnownTranslationKeys::COMMANDS_GENERIC_NUM_TOOBIG, [$input, (string) $max])); $sender->sendMessage(new Translatable(TextFormat::RED . "%" . KnownTranslationKeys::COMMANDS_GENERIC_NUM_TOOBIG, [$input, (string) $max]));
return null; return null;
} }
if($v < $min){ if($v < $min){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%" . KnownTranslationKeys::COMMANDS_GENERIC_NUM_TOOSMALL, [$input, (string) $min])); $sender->sendMessage(new Translatable(TextFormat::RED . "%" . KnownTranslationKeys::COMMANDS_GENERIC_NUM_TOOSMALL, [$input, (string) $min]));
return null; return null;
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\console;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\lang\Language; use pocketmine\lang\Language;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\permission\DefaultPermissions; use pocketmine\permission\DefaultPermissions;
use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissibleBase;
use pocketmine\permission\PermissibleDelegateTrait; use pocketmine\permission\PermissibleDelegateTrait;
@ -58,9 +58,9 @@ class ConsoleCommandSender implements CommandSender{
return $this->language; return $this->language;
} }
public function sendMessage(TranslationContainer|string $message) : void{ public function sendMessage(Translatable|string $message) : void{
$server = $this->getServer(); $server = $this->getServer();
if($message instanceof TranslationContainer){ if($message instanceof Translatable){
$message = $this->getLanguage()->translate($message); $message = $this->getLanguage()->translate($message);
}else{ }else{
$message = $this->getLanguage()->translateString($message); $message = $this->getLanguage()->translateString($message);

View File

@ -31,23 +31,23 @@ use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDeathEvent; use pocketmine\event\entity\EntityDeathEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\KnownTranslationFactory;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\player\Player; use pocketmine\player\Player;
class PlayerDeathEvent extends EntityDeathEvent{ class PlayerDeathEvent extends EntityDeathEvent{
/** @var Player */ /** @var Player */
protected $entity; protected $entity;
/** @var TranslationContainer|string */ /** @var Translatable|string */
private $deathMessage; private $deathMessage;
/** @var bool */ /** @var bool */
private $keepInventory = false; private $keepInventory = false;
/** /**
* @param Item[] $drops * @param Item[] $drops
* @param string|TranslationContainer|null $deathMessage Null will cause the default vanilla message to be used * @param string|Translatable|null $deathMessage Null will cause the default vanilla message to be used
*/ */
public function __construct(Player $entity, array $drops, int $xp, TranslationContainer|string|null $deathMessage){ public function __construct(Player $entity, array $drops, int $xp, Translatable|string|null $deathMessage){
parent::__construct($entity, $drops, $xp); parent::__construct($entity, $drops, $xp);
$this->deathMessage = $deathMessage ?? self::deriveMessage($entity->getDisplayName(), $entity->getLastDamageCause()); $this->deathMessage = $deathMessage ?? self::deriveMessage($entity->getDisplayName(), $entity->getLastDamageCause());
} }
@ -63,11 +63,11 @@ class PlayerDeathEvent extends EntityDeathEvent{
return $this->entity; return $this->entity;
} }
public function getDeathMessage() : TranslationContainer|string{ public function getDeathMessage() : Translatable|string{
return $this->deathMessage; return $this->deathMessage;
} }
public function setDeathMessage(TranslationContainer|string $deathMessage) : void{ public function setDeathMessage(Translatable|string $deathMessage) : void{
$this->deathMessage = $deathMessage; $this->deathMessage = $deathMessage;
} }
@ -82,7 +82,7 @@ class PlayerDeathEvent extends EntityDeathEvent{
/** /**
* Returns the vanilla death message for the given death cause. * Returns the vanilla death message for the given death cause.
*/ */
public static function deriveMessage(string $name, ?EntityDamageEvent $deathCause) : TranslationContainer{ public static function deriveMessage(string $name, ?EntityDamageEvent $deathCause) : Translatable{
switch($deathCause === null ? EntityDamageEvent::CAUSE_CUSTOM : $deathCause->getCause()){ switch($deathCause === null ? EntityDamageEvent::CAUSE_CUSTOM : $deathCause->getCause()){
case EntityDamageEvent::CAUSE_ENTITY_ATTACK: case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
if($deathCause instanceof EntityDamageByEntityEvent){ if($deathCause instanceof EntityDamageByEntityEvent){

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\event\player; namespace pocketmine\event\player;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\player\Player; use pocketmine\player\Player;
/** /**
@ -34,19 +34,19 @@ use pocketmine\player\Player;
* @see PlayerLoginEvent * @see PlayerLoginEvent
*/ */
class PlayerJoinEvent extends PlayerEvent{ class PlayerJoinEvent extends PlayerEvent{
/** @var string|TranslationContainer */ /** @var string|Translatable */
protected $joinMessage; protected $joinMessage;
public function __construct(Player $player, TranslationContainer|string $joinMessage){ public function __construct(Player $player, Translatable|string $joinMessage){
$this->player = $player; $this->player = $player;
$this->joinMessage = $joinMessage; $this->joinMessage = $joinMessage;
} }
public function setJoinMessage(TranslationContainer|string $joinMessage) : void{ public function setJoinMessage(Translatable|string $joinMessage) : void{
$this->joinMessage = $joinMessage; $this->joinMessage = $joinMessage;
} }
public function getJoinMessage() : TranslationContainer|string{ public function getJoinMessage() : Translatable|string{
return $this->joinMessage; return $this->joinMessage;
} }
} }

View File

@ -25,7 +25,7 @@ namespace pocketmine\event\player;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait; use pocketmine\event\CancellableTrait;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\player\Player; use pocketmine\player\Player;
/** /**
@ -34,13 +34,13 @@ use pocketmine\player\Player;
class PlayerKickEvent extends PlayerEvent implements Cancellable{ class PlayerKickEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var TranslationContainer|string */ /** @var Translatable|string */
protected $quitMessage; protected $quitMessage;
/** @var string */ /** @var string */
protected $reason; protected $reason;
public function __construct(Player $player, string $reason, TranslationContainer|string $quitMessage){ public function __construct(Player $player, string $reason, Translatable|string $quitMessage){
$this->player = $player; $this->player = $player;
$this->quitMessage = $quitMessage; $this->quitMessage = $quitMessage;
$this->reason = $reason; $this->reason = $reason;
@ -54,11 +54,11 @@ class PlayerKickEvent extends PlayerEvent implements Cancellable{
return $this->reason; return $this->reason;
} }
public function setQuitMessage(TranslationContainer|string $quitMessage) : void{ public function setQuitMessage(Translatable|string $quitMessage) : void{
$this->quitMessage = $quitMessage; $this->quitMessage = $quitMessage;
} }
public function getQuitMessage() : TranslationContainer|string{ public function getQuitMessage() : Translatable|string{
return $this->quitMessage; return $this->quitMessage;
} }
} }

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\event\player; namespace pocketmine\event\player;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\player\Player; use pocketmine\player\Player;
/** /**
@ -31,22 +31,22 @@ use pocketmine\player\Player;
*/ */
class PlayerQuitEvent extends PlayerEvent{ class PlayerQuitEvent extends PlayerEvent{
/** @var TranslationContainer|string */ /** @var Translatable|string */
protected $quitMessage; protected $quitMessage;
/** @var string */ /** @var string */
protected $quitReason; protected $quitReason;
public function __construct(Player $player, TranslationContainer|string $quitMessage, string $quitReason){ public function __construct(Player $player, Translatable|string $quitMessage, string $quitReason){
$this->player = $player; $this->player = $player;
$this->quitMessage = $quitMessage; $this->quitMessage = $quitMessage;
$this->quitReason = $quitReason; $this->quitReason = $quitReason;
} }
public function setQuitMessage(TranslationContainer|string $quitMessage) : void{ public function setQuitMessage(Translatable|string $quitMessage) : void{
$this->quitMessage = $quitMessage; $this->quitMessage = $quitMessage;
} }
public function getQuitMessage() : TranslationContainer|string{ public function getQuitMessage() : Translatable|string{
return $this->quitMessage; return $this->quitMessage;
} }

File diff suppressed because it is too large Load Diff

View File

@ -130,26 +130,26 @@ class Language{
} }
/** /**
* @param (float|int|string|TranslationContainer)[] $params * @param (float|int|string|Translatable)[] $params
*/ */
public function translateString(string $str, array $params = [], ?string $onlyPrefix = null) : string{ public function translateString(string $str, array $params = [], ?string $onlyPrefix = null) : string{
$baseText = $this->get($str); $baseText = $this->get($str);
$baseText = $this->parseTranslation(($onlyPrefix === null or strpos($str, $onlyPrefix) === 0) ? $baseText : $str, $onlyPrefix); $baseText = $this->parseTranslation(($onlyPrefix === null or strpos($str, $onlyPrefix) === 0) ? $baseText : $str, $onlyPrefix);
foreach($params as $i => $p){ foreach($params as $i => $p){
$replacement = $p instanceof TranslationContainer ? $this->translate($p) : $this->parseTranslation((string) $p); $replacement = $p instanceof Translatable ? $this->translate($p) : $this->parseTranslation((string) $p);
$baseText = str_replace("{%$i}", $replacement, $baseText); $baseText = str_replace("{%$i}", $replacement, $baseText);
} }
return $baseText; return $baseText;
} }
public function translate(TranslationContainer $c) : string{ public function translate(Translatable $c) : string{
$baseText = $this->internalGet($c->getText()); $baseText = $this->internalGet($c->getText());
$baseText = $this->parseTranslation($baseText ?? $c->getText()); $baseText = $this->parseTranslation($baseText ?? $c->getText());
foreach($c->getParameters() as $i => $p){ foreach($c->getParameters() as $i => $p){
$replacement = $p instanceof TranslationContainer ? $this->translate($p) : $this->parseTranslation($p); $replacement = $p instanceof Translatable ? $this->translate($p) : $this->parseTranslation($p);
$baseText = str_replace("{%$i}", $replacement, $baseText); $baseText = str_replace("{%$i}", $replacement, $baseText);
} }

View File

@ -23,21 +23,21 @@ declare(strict_types=1);
namespace pocketmine\lang; namespace pocketmine\lang;
final class TranslationContainer{ final class Translatable{
/** @var string $text */ /** @var string $text */
protected $text; protected $text;
/** @var string[]|TranslationContainer[] $params */ /** @var string[]|Translatable[] $params */
protected $params = []; protected $params = [];
/** /**
* @param (float|int|string|TranslationContainer)[] $params * @param (float|int|string|Translatable)[] $params
*/ */
public function __construct(string $text, array $params = []){ public function __construct(string $text, array $params = []){
$this->text = $text; $this->text = $text;
foreach($params as $k => $param){ foreach($params as $k => $param){
if(!($param instanceof TranslationContainer)){ if(!($param instanceof Translatable)){
$this->params[$k] = (string) $param; $this->params[$k] = (string) $param;
}else{ }else{
$this->params[$k] = $param; $this->params[$k] = $param;
@ -50,13 +50,13 @@ final class TranslationContainer{
} }
/** /**
* @return string[]|TranslationContainer[] * @return string[]|Translatable[]
*/ */
public function getParameters() : array{ public function getParameters() : array{
return $this->params; return $this->params;
} }
public function getParameter(int|string $i) : TranslationContainer|string|null{ public function getParameter(int|string $i) : Translatable|string|null{
return $this->params[$i] ?? null; return $this->params[$i] ?? null;
} }

View File

@ -82,7 +82,7 @@ use pocketmine\item\ItemUseResult;
use pocketmine\item\Releasable; use pocketmine\item\Releasable;
use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\KnownTranslationFactory;
use pocketmine\lang\Language; use pocketmine\lang\Language;
use pocketmine\lang\TranslationContainer; use pocketmine\lang\Translatable;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\IntTag;
@ -319,7 +319,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
} }
} }
public function getLeaveMessage() : TranslationContainer|string{ public function getLeaveMessage() : Translatable|string{
if($this->spawned){ if($this->spawned){
return KnownTranslationFactory::multiplayer_player_left($this->getDisplayName())->prefix(TextFormat::YELLOW); return KnownTranslationFactory::multiplayer_player_left($this->getDisplayName())->prefix(TextFormat::YELLOW);
} }
@ -1772,8 +1772,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
/** /**
* Sends a direct chat message to a player * Sends a direct chat message to a player
*/ */
public function sendMessage(TranslationContainer|string $message) : void{ public function sendMessage(Translatable|string $message) : void{
if($message instanceof TranslationContainer){ if($message instanceof Translatable){
$this->sendTranslation($message->getText(), $message->getParameters()); $this->sendTranslation($message->getText(), $message->getParameters());
return; return;
} }
@ -1782,11 +1782,11 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
} }
/** /**
* @param string[]|TranslationContainer[] $parameters * @param string[]|Translatable[] $parameters
*/ */
public function sendTranslation(string $message, array $parameters = []) : void{ public function sendTranslation(string $message, array $parameters = []) : void{
//we can't send nested translations to the client, so make sure they are always pre-translated by the server //we can't send nested translations to the client, so make sure they are always pre-translated by the server
$parameters = array_map(fn(string|TranslationContainer $p) => $p instanceof TranslationContainer ? $this->getLanguage()->translate($p) : $p, $parameters); $parameters = array_map(fn(string|Translatable $p) => $p instanceof Translatable ? $this->getLanguage()->translate($p) : $p, $parameters);
if(!$this->server->isLanguageForced()){ if(!$this->server->isLanguageForced()){
foreach($parameters as $i => $p){ foreach($parameters as $i => $p){
$parameters[$i] = $this->getLanguage()->translateString($p, [], "pocketmine."); $parameters[$i] = $this->getLanguage()->translateString($p, [], "pocketmine.");
@ -1873,7 +1873,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
/** /**
* Kicks a player from the server * Kicks a player from the server
*/ */
public function kick(string $reason = "", TranslationContainer|string|null $quitMessage = null) : bool{ public function kick(string $reason = "", Translatable|string|null $quitMessage = null) : bool{
$ev = new PlayerKickEvent($this, $reason, $quitMessage ?? $this->getLeaveMessage()); $ev = new PlayerKickEvent($this, $reason, $quitMessage ?? $this->getLeaveMessage());
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
@ -1898,10 +1898,10 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* *
* Note for internals developers: Do not call this from network sessions. It will cause a feedback loop. * Note for internals developers: Do not call this from network sessions. It will cause a feedback loop.
* *
* @param string $reason Shown to the player, usually this will appear on their disconnect screen. * @param string $reason Shown to the player, usually this will appear on their disconnect screen.
* @param TranslationContainer|string|null $quitMessage Message to broadcast to online players (null will use default) * @param Translatable|string|null $quitMessage Message to broadcast to online players (null will use default)
*/ */
public function disconnect(string $reason, TranslationContainer|string|null $quitMessage = null) : void{ public function disconnect(string $reason, Translatable|string|null $quitMessage = null) : void{
if(!$this->isConnected()){ if(!$this->isConnected()){
return; return;
} }
@ -1915,9 +1915,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* This method executes post-disconnect actions and cleanups. * This method executes post-disconnect actions and cleanups.
* *
* @param string $reason Shown to the player, usually this will appear on their disconnect screen. * @param string $reason Shown to the player, usually this will appear on their disconnect screen.
* @param TranslationContainer|string|null $quitMessage Message to broadcast to online players (null will use default) * @param Translatable|string|null $quitMessage Message to broadcast to online players (null will use default)
*/ */
public function onPostDisconnect(string $reason, TranslationContainer|string|null $quitMessage) : void{ public function onPostDisconnect(string $reason, Translatable|string|null $quitMessage) : void{
if($this->isConnected()){ if($this->isConnected()){
throw new \InvalidStateException("Player is still connected"); throw new \InvalidStateException("Player is still connected");
} }