mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Added /list, Player::canSee(), Player::showPlayer(), Player::hidePlayer(), removed RealHuman
This commit is contained in:
parent
f9a7385b47
commit
2f03251795
@ -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);
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
|
||||
|
58
src/PocketMine/command/defaults/ListCommand.php
Normal file
58
src/PocketMine/command/defaults/ListCommand.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Command\Defaults;
|
||||
|
||||
use PocketMine\Command\Command;
|
||||
use PocketMine\Command\CommandSender;
|
||||
use PocketMine\Player;
|
||||
use PocketMine\Server;
|
||||
use PocketMine\Utils\TextFormat;
|
||||
|
||||
class ListCommand extends VanillaCommand{
|
||||
|
||||
public function __construct($name){
|
||||
parent::__construct(
|
||||
$name,
|
||||
"Lists all online players",
|
||||
"/list"
|
||||
);
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PocketMine\Entity;
|
||||
|
||||
use PocketMine\Player;
|
||||
|
||||
abstract class RealHuman extends Human{
|
||||
|
||||
protected function initEntity(){
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user