mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-08-19 17:40:38 +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);
|
$result = $this->getPlayerExact($name);
|
||||||
|
|
||||||
if($result === null){
|
if($result === null){
|
||||||
$result = new OfflinePlayer($this, $name);
|
$result = new OfflinePlayer($name, $this->getOfflinePlayerData($name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -25,8 +25,6 @@ namespace pocketmine\player;
|
|||||||
|
|
||||||
interface IPlayer{
|
interface IPlayer{
|
||||||
|
|
||||||
public function isOnline() : bool;
|
|
||||||
|
|
||||||
public function getName() : string;
|
public function getName() : string;
|
||||||
|
|
||||||
public function getFirstPlayed() : ?int;
|
public function getFirstPlayed() : ?int;
|
||||||
|
@ -25,35 +25,23 @@ namespace pocketmine\player;
|
|||||||
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\LongTag;
|
use pocketmine\nbt\tag\LongTag;
|
||||||
use pocketmine\Server;
|
|
||||||
|
|
||||||
class OfflinePlayer implements IPlayer{
|
class OfflinePlayer implements IPlayer{
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $name;
|
private $name;
|
||||||
/** @var Server */
|
|
||||||
private $server;
|
|
||||||
/** @var CompoundTag|null */
|
/** @var CompoundTag|null */
|
||||||
private $namedtag = null;
|
private $namedtag;
|
||||||
|
|
||||||
public function __construct(Server $server, string $name){
|
public function __construct(string $name, ?CompoundTag $namedtag){
|
||||||
$this->server = $server;
|
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->namedtag = $this->server->getOfflinePlayerData($this->name);
|
$this->namedtag = $namedtag;
|
||||||
}
|
|
||||||
|
|
||||||
public function isOnline() : bool{
|
|
||||||
return $this->getPlayer() !== null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName() : string{
|
public function getName() : string{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPlayer() : ?Player{
|
|
||||||
return $this->server->getPlayerExact($this->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFirstPlayed() : ?int{
|
public function getFirstPlayed() : ?int{
|
||||||
return ($this->namedtag !== null and ($firstPlayedTag = $this->namedtag->getTag("firstPlayed")) instanceof LongTag) ? $firstPlayedTag->getValue() : null;
|
return ($this->namedtag !== null and ($firstPlayedTag = $this->namedtag->getTag("firstPlayed")) instanceof LongTag) ? $firstPlayedTag->getValue() : null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user