Minecraft selectors (@A, @p, @r, @e, @s) added to pocketmine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

<?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){
if($params["c"] !== 0 && count($return) == $params["c"]) break; // Too much players
if($p->getLevel()->getName() !== $params["lvl"] && $params["lvl"] !== "") break; // Not in the right level
if(!$this->checkDefaultParams($p, $params)) break;
$return[] = $p->getName();
}
return $return;
}
}