2017-11-04 23:09:24 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ad5001\PlayerSelectors\selector;
|
|
|
|
|
|
|
|
use pocketmine\command\CommandSender;
|
|
|
|
use pocketmine\Server;
|
|
|
|
use pocketmine\Player;
|
|
|
|
use pocketmine\level\Position;
|
|
|
|
|
|
|
|
|
|
|
|
class WorldPlayers extends Selector{
|
|
|
|
|
|
|
|
public function __construct(){
|
|
|
|
parent::__construct("World players", "w", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the selector.
|
|
|
|
* Documentation is in the Selector.php file.
|
|
|
|
*
|
|
|
|
* @param CommandSender $sender
|
|
|
|
* @param array $parameters
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function applySelector(CommandSender $sender, array $parameters = []): array{
|
|
|
|
$defaultParams = Selector::DEFAULT_PARAMS;
|
|
|
|
if($sender instanceof Position){
|
|
|
|
$defaultParams["x"] = $sender->x;
|
|
|
|
$defaultParams["y"] = $sender->y;
|
|
|
|
$defaultParams["z"] = $sender->z;
|
|
|
|
$defaultParams["lvl"] = $sender->getLevel()->getName();
|
|
|
|
} else {
|
|
|
|
$defaultParams["lvl"] = Server::getInstance()->getDefaultLevel()->getName();
|
|
|
|
|
|
|
|
}
|
|
|
|
$params = $parameters + $defaultParams;
|
|
|
|
$return = [];
|
|
|
|
foreach(Server::getInstance()->getOnlinePlayers() as $p){
|
2017-11-05 15:31:11 +00:00
|
|
|
if($params["c"] !== 0 && count($return) == $params["c"]) continue; // Too much players
|
|
|
|
if($p->getLevel()->getName() !== $params["lvl"] && $params["lvl"] !== "") continue; // Not in the right level
|
|
|
|
if(!$this->checkDefaultParams($p, $params)) continue;
|
2017-11-04 23:09:24 +00:00
|
|
|
$return[] = $p->getName();
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|