diff --git a/src/PocketMine/Player.php b/src/PocketMine/Player.php index 0790c846b..ad96aac7f 100644 --- a/src/PocketMine/Player.php +++ b/src/PocketMine/Player.php @@ -22,7 +22,7 @@ namespace PocketMine; use PocketMine\Command\CommandSender; -use PocketMine\Entity\RealHuman; +use PocketMine\Entity\Human; use PocketMine\Event; use PocketMine\Item\Item; use PocketMine\Level\Level; @@ -84,7 +84,7 @@ use PocketMine\Utils\Utils; * Class Player * @package PocketMine */ -class Player extends RealHuman implements CommandSender{ +class Player extends Human implements CommandSender{ const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin"; const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user"; @@ -132,6 +132,8 @@ class Player extends RealHuman implements CommandSender{ protected $startAction = false; protected $sleeping = false; protected $chunksOrder = array(); + /** @var Player[] */ + protected $hiddenPlayers = array(); private $recoveryQueue = array(); private $receiveQueue = array(); private $resendQueue = array(); @@ -166,6 +168,30 @@ class Player extends RealHuman implements CommandSender{ private $perm = null; + + protected function initEntity(){ + $this->level->players[$this->CID] = $this; + parent::initEntity(); + } + + /** + * @param Player $player + */ + public function spawnTo(Player $player){ + if($this->spawned === true and $player->getLevel() === $this->getLevel() and $player->canSee($this)){ + parent::spawnTo($player); + } + } + + /** + * @param Player $player + */ + public function despawnFrom(Player $player){ + if($this->spawned === true){ + parent::despawnFrom($player); + } + } + /** * @return Server */ @@ -173,6 +199,44 @@ class Player extends RealHuman implements CommandSender{ return $this->server; } + /** + * @param Player $player + * + * @return bool + */ + public function canSee(Player $player){ + return !isset($this->hiddenPlayers[$player->getName()]); + } + + /** + * @param Player $player + */ + public function hidePlayer(Player $player){ + if($player === $this){ + return; + } + $this->hiddenPlayers[$player->getName()] = $player; + $player->despawnFrom($this); + } + + /** + * @param Player $player + */ + public function showPlayer(Player $player){ + if($player === $this){ + return; + } + unset($this->hiddenPlayers[$player->getName()]); + $player->spawnTo($this); + } + + /** + * @return bool + */ + public function isOnline(){ + return $this->connected === true and $this->loggedIn === true; + } + /** * @return bool */ @@ -1542,7 +1606,7 @@ class Player extends RealHuman implements CommandSender{ if($target instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){ $data["targetentity"] = $target; $data["entity"] = $this->entity; - if($target instanceof RealHuman and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($target->player->gamemode & 0x01) === 0x01)){ + if($target instanceof Player and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($target->player->gamemode & 0x01) === 0x01)){ break; }elseif($this->server->handle("player.interact", $data) !== false){ $slot = $this->getSlot($this->slot); @@ -2086,6 +2150,7 @@ class Player extends RealHuman implements CommandSender{ $this->chunkCount = array(); $this->craftingItems = array(); $this->received = array(); + unset($this->level->players[$this->CID]); parent::close(); $this->buffer = null; unset($this->buffer); diff --git a/src/PocketMine/command/SimpleCommandMap.php b/src/PocketMine/command/SimpleCommandMap.php index d222c4f8d..f56edac4e 100644 --- a/src/PocketMine/command/SimpleCommandMap.php +++ b/src/PocketMine/command/SimpleCommandMap.php @@ -26,6 +26,7 @@ use PocketMine\Command\Defaults\BanIpCommand; use PocketMine\Command\Defaults\BanListCommand; use PocketMine\Command\Defaults\DefaultGamemodeCommand; use PocketMine\Command\Defaults\HelpCommand; +use PocketMine\Command\Defaults\ListCommand; use PocketMine\Command\Defaults\MeCommand; use PocketMine\Command\Defaults\PardonCommand; use PocketMine\Command\Defaults\PardonIpCommand; @@ -68,6 +69,7 @@ class SimpleCommandMap implements CommandMap{ $this->register("pocketmine", new PardonIpCommand("pardon-ip")); $this->register("pocketmine", new SayCommand("say")); $this->register("pocketmine", new MeCommand("me")); + $this->register("pocketmine", new ListCommand("list")); } diff --git a/src/PocketMine/command/defaults/ListCommand.php b/src/PocketMine/command/defaults/ListCommand.php new file mode 100644 index 000000000..b0f07b281 --- /dev/null +++ b/src/PocketMine/command/defaults/ListCommand.php @@ -0,0 +1,58 @@ +setPermission("pocketmine.command.list"); + } + + public function execute(CommandSender $sender, $currentAlias, array $args){ + if(!$this->testPermission($sender)){ + return true; + } + + $online = ""; + + foreach(Player::getAll() as $player){ + if($player->isOnline() and (!($sender instanceof Player) or $sender->canSee($player))){ + $online .= $player->getDisplayName() . ", "; + } + } + + $sender->sendMessage("There are ".count(Player::getAll())."/".Server::getInstance()->getMaxPlayers()." players online:\n" . substr($online, 0, -2)); + + return true; + } +} \ No newline at end of file diff --git a/src/PocketMine/entity/RealHuman.php b/src/PocketMine/entity/RealHuman.php deleted file mode 100644 index 5959f7ef6..000000000 --- a/src/PocketMine/entity/RealHuman.php +++ /dev/null @@ -1,49 +0,0 @@ -level->players[$this->CID] = $this; - parent::initEntity(); - } - - public function close(){ - unset($this->level->players[$this->CID]); - parent::close(); - } - - public function spawnTo(Player $player){ - if($this->spawned === true){ - parent::spawnTo($player); - } - } - - public function despawnFrom(Player $player){ - if($this->spawned === true){ - parent::despawnFrom($player); - } - } -} \ No newline at end of file