Skip to content

CommandTargets 5.46.0 ​

final class · pocketmine\command\selector\CommandTargets · source

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:

php
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() ​

php
public static function entities(\pocketmine\command\CommandSender $sender, string $target) : array

Entities named by the argument: the entities matched by a selector, or the online player whose name starts with the argument. Never empty.

entity() ​

php
public static function entity(\pocketmine\command\CommandSender $sender, string $target) : \pocketmine\entity\Entity

Exactly one entity (e.g. a teleport destination): throws "Too many targets matched selector" when a selector matches more than one.

expandSelectors() ​

php
public static function expandSelectors(\pocketmine\command\CommandSender $sender, string $text) : string

Replaces 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() ​

php
public static function player(\pocketmine\command\CommandSender $sender, string $target) : \pocketmine\player\Player

Exactly one player.

players() ​

php
public static function players(\pocketmine\command\CommandSender $sender, string $target) : array

Players 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.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.