I dont know if i cant, but i have one attempt PHP: <?phpnamespace Core;use pocketmine\scheduler\PluginTask;use Core\Core;use pocketmine\Player;use pocketmine\utils\TextFormat as C;class ParticleTask extends PluginTask{private $plugin;private $playergg = [];public function __construct(Core $plugin){$this->plugin = $plugin;parent::__construct($plugin);}public function getPlayer(Player $p){$this->playergg[$p->toString] = $p;}public function onRun($currentTick){foreach ($this->playergg as $p) {$this->testPlayer($p);$this->plugin->getServer()->broadcastMessage("It work");}}}
Lol. PHP: foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) {$player->sendMessage("It works!");}
PHP: public $playerName;public function __construct(Core $plugin,$name){$this->plugin = $plugin;$this->playerName=$name;parent::__construct($plugin);}public function onRun($currentTick){if($player = $this->plugin->getServer()->getPlayerExact($this->playerName)) $player->sendMessage("It works");}
you can add in the constructor the Player Object ^^ then you can send him directly a message ^^ he want to send a message to one player, not all who are online ^^
That's very unsafe. If the player leaves the game you end up crashing the server. PHP: public $playerName;public function __construct(Core $plugin,string $name){ $this->plugin = $plugin; $this->playerName=$name; parent::__construct($plugin);}public function onRun($currentTick){ if(($player = $this->plugin->getServer()->getPlayerExact($this->playerName)) instanceof Player){ $player->sendMessage("It works"); }}
a player object cannot be null, because it wouldn't be a player object then. If you meant to check if the variable is not null, that's also wrong, because it could be an object of an offline player, or an object of something else, or a string. just do an instanceof check. and, if required an online check after that.
lol i am using a lot of times this to check if the player is offline or online and it works fine! PHP: $player = /* pocketmine\Player Object */if($player != null){ //player is online} else { //player is offline}
Nope, I can gurantee you that "//player is offline" will NEVER be reached, if $player really contains a pocketmine\Player Object. Do a vardump on $player, and you'll see it is null if "//player is offline" is reached. So you can't say it's containing a Player Object.
it does work with function returning null if no player is found/the player is offline. But don't use it for checking whether a player object still points to an online player.