PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
OfflinePlayer.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine;
23 
24 
28 
29 class OfflinePlayer implements IPlayer{
30 
31  private $name;
32  private $server;
33  private $namedtag;
34 
39  public function __construct(Server $server, $name){
40  $this->server = $server;
41  $this->name = $name;
42  if(file_exists($this->server->getDataPath() . "players/" . strtolower($this->getName()) . ".dat")){
43  $this->namedtag = $this->server->getOfflinePlayerData($this->name);
44  }else{
45  $this->namedtag = null;
46  }
47  }
48 
49  public function isOnline(){
50  return $this->getPlayer() !== null;
51  }
52 
53  public function getName(){
54  return $this->name;
55  }
56 
57  public function getServer(){
58  return $this->server;
59  }
60 
61  public function isOp(){
62  return $this->server->isOp(strtolower($this->getName()));
63  }
64 
65  public function setOp($value){
66  if($value === $this->isOp()){
67  return;
68  }
69 
70  if($value === true){
71  $this->server->addOp(strtolower($this->getName()));
72  }else{
73  $this->server->removeOp(strtolower($this->getName()));
74  }
75  }
76 
77  public function isBanned(){
78  return $this->server->getNameBans()->isBanned(strtolower($this->getName()));
79  }
80 
81  public function setBanned($value){
82  if($value === true){
83  $this->server->getNameBans()->addBan($this->getName(), null, null, null);
84  }else{
85  $this->server->getNameBans()->remove($this->getName());
86  }
87  }
88 
89  public function isWhitelisted(){
90  return $this->server->isWhitelisted(strtolower($this->getName()));
91  }
92 
93  public function setWhitelisted($value){
94  if($value === true){
95  $this->server->addWhitelist(strtolower($this->getName()));
96  }else{
97  $this->server->removeWhitelist(strtolower($this->getName()));
98  }
99  }
100 
101  public function getPlayer(){
102  return $this->server->getPlayerExact($this->getName());
103  }
104 
105  public function getFirstPlayed(){
106  return $this->namedtag instanceof Compound ? $this->namedtag["firstPlayed"] : null;
107  }
108 
109  public function getLastPlayed(){
110  return $this->namedtag instanceof Compound ? $this->namedtag["lastPlayed"] : null;
111  }
112 
113  public function hasPlayedBefore(){
114  return $this->namedtag instanceof Compound;
115  }
116 
117  public function setMetadata($metadataKey, MetadataValue $metadataValue){
118  $this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue);
119  }
120 
121  public function getMetadata($metadataKey){
122  return $this->server->getPlayerMetadata()->getMetadata($this, $metadataKey);
123  }
124 
125  public function hasMetadata($metadataKey){
126  return $this->server->getPlayerMetadata()->hasMetadata($this, $metadataKey);
127  }
128 
129  public function removeMetadata($metadataKey, Plugin $plugin){
130  $this->server->getPlayerMetadata()->removeMetadata($this, $metadataKey, $plugin);
131  }
132 
133 
134 }
getOfflinePlayerData($name)
Definition: Server.php:696
__construct(Server $server, $name)