OfflinePlayer no longer depends on Server

it also doesn't provide stuff like isOnline() (you had to have a Server reference to get an OfflinePlayer anyway, just ask the Server if the player is online ...) and getPlayer().
This commit is contained in:
Dylan K. Taylor 2020-11-28 21:29:41 +00:00
parent c102477f91
commit 614891f8a2
3 changed files with 4 additions and 18 deletions

View File

@ -500,7 +500,7 @@ class Server{
$result = $this->getPlayerExact($name);
if($result === null){
$result = new OfflinePlayer($this, $name);
$result = new OfflinePlayer($name, $this->getOfflinePlayerData($name));
}
return $result;

View File

@ -25,8 +25,6 @@ namespace pocketmine\player;
interface IPlayer{
public function isOnline() : bool;
public function getName() : string;
public function getFirstPlayed() : ?int;

View File

@ -25,35 +25,23 @@ namespace pocketmine\player;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\LongTag;
use pocketmine\Server;
class OfflinePlayer implements IPlayer{
/** @var string */
private $name;
/** @var Server */
private $server;
/** @var CompoundTag|null */
private $namedtag = null;
private $namedtag;
public function __construct(Server $server, string $name){
$this->server = $server;
public function __construct(string $name, ?CompoundTag $namedtag){
$this->name = $name;
$this->namedtag = $this->server->getOfflinePlayerData($this->name);
}
public function isOnline() : bool{
return $this->getPlayer() !== null;
$this->namedtag = $namedtag;
}
public function getName() : string{
return $this->name;
}
public function getPlayer() : ?Player{
return $this->server->getPlayerExact($this->name);
}
public function getFirstPlayed() : ?int{
return ($this->namedtag !== null and ($firstPlayedTag = $this->namedtag->getTag("firstPlayed")) instanceof LongTag) ? $firstPlayedTag->getValue() : null;
}