mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
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:
parent
c102477f91
commit
614891f8a2
@ -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;
|
||||
|
@ -25,8 +25,6 @@ namespace pocketmine\player;
|
||||
|
||||
interface IPlayer{
|
||||
|
||||
public function isOnline() : bool;
|
||||
|
||||
public function getName() : string;
|
||||
|
||||
public function getFirstPlayed() : ?int;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user