Rewrite message broadcasting system to not depend on PermissionManager subscriptions

relying on permission subscriptions for this was unreliable (a permissible is not always subscribed to a permission even when it does have it), and also difficult to control (for example there have been various bugs in the past where a Player ended up subscribed to broadcast permissions when it didn't expect to be, thanks to permission recalculation happening too early).
In addition, we might in the future want to have broadcast receivers which are not permissibles (i.e. a more general interface than CommandSender (why does a broadcast receiver need to also be a command sender, anyway?)), which the permission system wouldn't be suitable for.
This commit is contained in:
Dylan K. Taylor
2020-11-28 19:28:47 +00:00
parent ee7fad2271
commit dd200ca8cd
4 changed files with 70 additions and 49 deletions

View File

@ -26,11 +26,8 @@ namespace pocketmine\event\player;
use pocketmine\command\CommandSender;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\permission\PermissionManager;
use pocketmine\player\Player;
use pocketmine\Server;
use pocketmine\utils\Utils;
use function spl_object_id;
/**
* Called when a player chats something
@ -50,21 +47,13 @@ class PlayerChatEvent extends PlayerEvent implements Cancellable{
/**
* @param CommandSender[] $recipients
*/
public function __construct(Player $player, string $message, string $format = "chat.type.text", ?array $recipients = null){
public function __construct(Player $player, string $message, array $recipients, string $format = "chat.type.text"){
$this->player = $player;
$this->message = $message;
$this->format = $format;
if($recipients === null){
foreach(PermissionManager::getInstance()->getPermissionSubscriptions(Server::BROADCAST_CHANNEL_USERS) as $permissible){
if($permissible instanceof CommandSender){
$this->recipients[spl_object_id($permissible)] = $permissible;
}
}
}else{
$this->recipients = $recipients;
}
$this->recipients = $recipients;
}
public function getMessage() : string{