CommandTargets 5.46.0
Resolves command arguments that name targets: a Bedrock target selector (@a, @e[type=cow,r=10]...) or a player name (matched by prefix, like PocketMine always did). Plugin commands can use these helpers to accept selectors:
foreach(CommandTargets::players($sender, $args[0]) as $player){ ... }Failures throw a TargetSelectorException with a message for the sender; when thrown from Command::execute() the command map shows it (in red), so commands usually let it propagate.
Methods
entities()
public static function entities(\pocketmine\command\CommandSender $sender, string $target) : arrayEntities named by the argument: the entities matched by a selector, or the online player whose name starts with the argument. Never empty.
entity()
public static function entity(\pocketmine\command\CommandSender $sender, string $target) : \pocketmine\entity\EntityExactly one entity (e.g. a teleport destination): throws "Too many targets matched selector" when a selector matches more than one.
expandSelectors()
public static function expandSelectors(\pocketmine\command\CommandSender $sender, string $text) : stringReplaces the target selectors in a chat text by the names they match, like Bedrock /say, /me and /tell ("hi @a" -> "hi Steve, Alex"). Selectors that are malformed or match nothing are left as they are.
player()
public static function player(\pocketmine\command\CommandSender $sender, string $target) : \pocketmine\player\PlayerExactly one player.
players()
public static function players(\pocketmine\command\CommandSender $sender, string $target) : arrayPlayers named by the argument: the players matched by a selector (which must be able to select only players), or the online player whose name starts with the argument. Never empty.
