mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Use native union types for TranslationContainer|string
This commit is contained in:
parent
27a2d06083
commit
b4c0ddd155
@ -1194,10 +1194,9 @@ class Server{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TranslationContainer|string $message
|
||||
* @param CommandSender[]|null $recipients
|
||||
*/
|
||||
public function broadcastMessage($message, ?array $recipients = null) : int{
|
||||
public function broadcastMessage(TranslationContainer|string $message, ?array $recipients = null) : int{
|
||||
$recipients = $recipients ?? $this->getBroadcastChannelSubscribers(self::BROADCAST_CHANNEL_USERS);
|
||||
|
||||
foreach($recipients as $recipient){
|
||||
|
@ -231,10 +231,7 @@ abstract class Command{
|
||||
$this->usageMessage = $usage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TranslationContainer|string $message
|
||||
*/
|
||||
public static function broadcastCommandMessage(CommandSender $source, $message, bool $sendToSource = true) : void{
|
||||
public static function broadcastCommandMessage(CommandSender $source, TranslationContainer|string $message, bool $sendToSource = true) : void{
|
||||
$users = $source->getServer()->getBroadcastChannelSubscribers(Server::BROADCAST_CHANNEL_ADMINISTRATIVE);
|
||||
if($message instanceof TranslationContainer){
|
||||
$formatted = "[" . $source->getName() . ": " . ($source->getLanguage()->get($message->getText()) !== $message->getText() ? "%" : "") . $message->getText() . "]";
|
||||
|
@ -32,10 +32,7 @@ interface CommandSender extends Permissible{
|
||||
|
||||
public function getLanguage() : Language;
|
||||
|
||||
/**
|
||||
* @param TranslationContainer|string $message
|
||||
*/
|
||||
public function sendMessage($message) : void;
|
||||
public function sendMessage(TranslationContainer|string $message) : void;
|
||||
|
||||
public function getServer() : Server;
|
||||
|
||||
|
@ -58,10 +58,7 @@ class ConsoleCommandSender implements CommandSender{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TranslationContainer|string $message
|
||||
*/
|
||||
public function sendMessage($message) : void{
|
||||
public function sendMessage(TranslationContainer|string $message) : void{
|
||||
$server = $this->getServer();
|
||||
if($message instanceof TranslationContainer){
|
||||
$message = $this->getLanguage()->translate($message);
|
||||
|
@ -47,7 +47,7 @@ class PlayerDeathEvent extends EntityDeathEvent{
|
||||
* @param Item[] $drops
|
||||
* @param string|TranslationContainer|null $deathMessage Null will cause the default vanilla message to be used
|
||||
*/
|
||||
public function __construct(Player $entity, array $drops, int $xp, $deathMessage){
|
||||
public function __construct(Player $entity, array $drops, int $xp, TranslationContainer|string|null $deathMessage){
|
||||
parent::__construct($entity, $drops, $xp);
|
||||
$this->deathMessage = $deathMessage ?? self::deriveMessage($entity->getDisplayName(), $entity->getLastDamageCause());
|
||||
}
|
||||
@ -63,17 +63,11 @@ class PlayerDeathEvent extends EntityDeathEvent{
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TranslationContainer|string
|
||||
*/
|
||||
public function getDeathMessage(){
|
||||
public function getDeathMessage() : TranslationContainer|string{
|
||||
return $this->deathMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TranslationContainer|string $deathMessage
|
||||
*/
|
||||
public function setDeathMessage($deathMessage) : void{
|
||||
public function setDeathMessage(TranslationContainer|string $deathMessage) : void{
|
||||
$this->deathMessage = $deathMessage;
|
||||
}
|
||||
|
||||
|
@ -37,27 +37,16 @@ class PlayerJoinEvent extends PlayerEvent{
|
||||
/** @var string|TranslationContainer */
|
||||
protected $joinMessage;
|
||||
|
||||
/**
|
||||
* PlayerJoinEvent constructor.
|
||||
*
|
||||
* @param TranslationContainer|string $joinMessage
|
||||
*/
|
||||
public function __construct(Player $player, $joinMessage){
|
||||
public function __construct(Player $player, TranslationContainer|string $joinMessage){
|
||||
$this->player = $player;
|
||||
$this->joinMessage = $joinMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|TranslationContainer $joinMessage
|
||||
*/
|
||||
public function setJoinMessage($joinMessage) : void{
|
||||
public function setJoinMessage(TranslationContainer|string $joinMessage) : void{
|
||||
$this->joinMessage = $joinMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|TranslationContainer
|
||||
*/
|
||||
public function getJoinMessage(){
|
||||
public function getJoinMessage() : TranslationContainer|string{
|
||||
return $this->joinMessage;
|
||||
}
|
||||
}
|
||||
|
@ -40,12 +40,7 @@ class PlayerKickEvent extends PlayerEvent implements Cancellable{
|
||||
/** @var string */
|
||||
protected $reason;
|
||||
|
||||
/**
|
||||
* PlayerKickEvent constructor.
|
||||
*
|
||||
* @param TranslationContainer|string $quitMessage
|
||||
*/
|
||||
public function __construct(Player $player, string $reason, $quitMessage){
|
||||
public function __construct(Player $player, string $reason, TranslationContainer|string $quitMessage){
|
||||
$this->player = $player;
|
||||
$this->quitMessage = $quitMessage;
|
||||
$this->reason = $reason;
|
||||
@ -59,17 +54,11 @@ class PlayerKickEvent extends PlayerEvent implements Cancellable{
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TranslationContainer|string $quitMessage
|
||||
*/
|
||||
public function setQuitMessage($quitMessage) : void{
|
||||
public function setQuitMessage(TranslationContainer|string $quitMessage) : void{
|
||||
$this->quitMessage = $quitMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TranslationContainer|string
|
||||
*/
|
||||
public function getQuitMessage(){
|
||||
public function getQuitMessage() : TranslationContainer|string{
|
||||
return $this->quitMessage;
|
||||
}
|
||||
}
|
||||
|
@ -36,26 +36,17 @@ class PlayerQuitEvent extends PlayerEvent{
|
||||
/** @var string */
|
||||
protected $quitReason;
|
||||
|
||||
/**
|
||||
* @param TranslationContainer|string $quitMessage
|
||||
*/
|
||||
public function __construct(Player $player, $quitMessage, string $quitReason){
|
||||
public function __construct(Player $player, TranslationContainer|string $quitMessage, string $quitReason){
|
||||
$this->player = $player;
|
||||
$this->quitMessage = $quitMessage;
|
||||
$this->quitReason = $quitReason;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TranslationContainer|string $quitMessage
|
||||
*/
|
||||
public function setQuitMessage($quitMessage) : void{
|
||||
public function setQuitMessage(TranslationContainer|string $quitMessage) : void{
|
||||
$this->quitMessage = $quitMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TranslationContainer|string
|
||||
*/
|
||||
public function getQuitMessage(){
|
||||
public function getQuitMessage() : TranslationContainer|string{
|
||||
return $this->quitMessage;
|
||||
}
|
||||
|
||||
|
@ -319,10 +319,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TranslationContainer|string
|
||||
*/
|
||||
public function getLeaveMessage(){
|
||||
public function getLeaveMessage() : TranslationContainer|string{
|
||||
if($this->spawned){
|
||||
return new TranslationContainer(TextFormat::YELLOW . "%" . KnownTranslationKeys::MULTIPLAYER_PLAYER_LEFT, [
|
||||
$this->getDisplayName()
|
||||
@ -1782,10 +1779,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
|
||||
/**
|
||||
* Sends a direct chat message to a player
|
||||
*
|
||||
* @param TranslationContainer|string $message
|
||||
*/
|
||||
public function sendMessage($message) : void{
|
||||
public function sendMessage(TranslationContainer|string $message) : void{
|
||||
if($message instanceof TranslationContainer){
|
||||
$this->sendTranslation($message->getText(), $message->getParameters());
|
||||
return;
|
||||
@ -1883,10 +1878,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
|
||||
/**
|
||||
* Kicks a player from the server
|
||||
*
|
||||
* @param TranslationContainer|string|null $quitMessage
|
||||
*/
|
||||
public function kick(string $reason = "", $quitMessage = null) : bool{
|
||||
public function kick(string $reason = "", TranslationContainer|string|null $quitMessage = null) : bool{
|
||||
$ev = new PlayerKickEvent($this, $reason, $quitMessage ?? $this->getLeaveMessage());
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled()){
|
||||
@ -1914,7 +1907,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
* @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)
|
||||
*/
|
||||
public function disconnect(string $reason, $quitMessage = null) : void{
|
||||
public function disconnect(string $reason, TranslationContainer|string|null $quitMessage = null) : void{
|
||||
if(!$this->isConnected()){
|
||||
return;
|
||||
}
|
||||
@ -1930,7 +1923,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
* @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)
|
||||
*/
|
||||
public function onPostDisconnect(string $reason, $quitMessage) : void{
|
||||
public function onPostDisconnect(string $reason, TranslationContainer|string|null $quitMessage) : void{
|
||||
if($this->isConnected()){
|
||||
throw new \InvalidStateException("Player is still connected");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user