mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-02 10:11:27 +00:00
Did you guys think ALPHA7 changes were done?! Sone stuff still needs some work, most notably data-properties can't be typed yet because they are just mushed into a couple of methods.
140 lines
3.6 KiB
PHP
140 lines
3.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine;
|
|
|
|
use pocketmine\metadata\Metadatable;
|
|
use pocketmine\metadata\MetadataValue;
|
|
use pocketmine\nbt\tag\CompoundTag;
|
|
use pocketmine\plugin\Plugin;
|
|
|
|
class OfflinePlayer implements IPlayer, Metadatable{
|
|
|
|
/** @var string */
|
|
private $name;
|
|
/** @var Server */
|
|
private $server;
|
|
/** @var CompoundTag|null */
|
|
private $namedtag;
|
|
|
|
/**
|
|
* @param Server $server
|
|
* @param string $name
|
|
*/
|
|
public function __construct(Server $server, string $name){
|
|
$this->server = $server;
|
|
$this->name = $name;
|
|
if(file_exists($this->server->getDataPath() . "players/" . strtolower($this->getName()) . ".dat")){
|
|
$this->namedtag = $this->server->getOfflinePlayerData($this->name);
|
|
}else{
|
|
$this->namedtag = null;
|
|
}
|
|
}
|
|
|
|
public function isOnline() : bool{
|
|
return $this->getPlayer() !== null;
|
|
}
|
|
|
|
public function getName() : string{
|
|
return $this->name;
|
|
}
|
|
|
|
public function getServer(){
|
|
return $this->server;
|
|
}
|
|
|
|
public function isOp() : bool{
|
|
return $this->server->isOp(strtolower($this->getName()));
|
|
}
|
|
|
|
public function setOp(bool $value){
|
|
if($value === $this->isOp()){
|
|
return;
|
|
}
|
|
|
|
if($value === true){
|
|
$this->server->addOp(strtolower($this->getName()));
|
|
}else{
|
|
$this->server->removeOp(strtolower($this->getName()));
|
|
}
|
|
}
|
|
|
|
public function isBanned() : bool{
|
|
return $this->server->getNameBans()->isBanned(strtolower($this->getName()));
|
|
}
|
|
|
|
public function setBanned(bool $value){
|
|
if($value === true){
|
|
$this->server->getNameBans()->addBan($this->getName(), null, null, null);
|
|
}else{
|
|
$this->server->getNameBans()->remove($this->getName());
|
|
}
|
|
}
|
|
|
|
public function isWhitelisted() : bool{
|
|
return $this->server->isWhitelisted(strtolower($this->getName()));
|
|
}
|
|
|
|
public function setWhitelisted(bool $value){
|
|
if($value === true){
|
|
$this->server->addWhitelist(strtolower($this->getName()));
|
|
}else{
|
|
$this->server->removeWhitelist(strtolower($this->getName()));
|
|
}
|
|
}
|
|
|
|
public function getPlayer(){
|
|
return $this->server->getPlayerExact($this->getName());
|
|
}
|
|
|
|
public function getFirstPlayed(){
|
|
return $this->namedtag instanceof CompoundTag ? $this->namedtag["firstPlayed"] : null;
|
|
}
|
|
|
|
public function getLastPlayed(){
|
|
return $this->namedtag instanceof CompoundTag ? $this->namedtag["lastPlayed"] : null;
|
|
}
|
|
|
|
public function hasPlayedBefore() : bool{
|
|
return $this->namedtag instanceof CompoundTag;
|
|
}
|
|
|
|
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue){
|
|
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
|
|
}
|
|
|
|
public function getMetadata(string $metadataKey){
|
|
return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
|
|
}
|
|
|
|
public function hasMetadata(string $metadataKey) : bool{
|
|
return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
|
|
}
|
|
|
|
public function removeMetadata(string $metadataKey, Plugin $owningPlugin){
|
|
$this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
|
|
}
|
|
|
|
|
|
}
|