First commit!
commit
e02535809b
@ -0,0 +1,28 @@
|
||||
<h1><img src="https://github.com/Ad5001/PlayerSelectors/raw/master/icon.png"> PlayerSelectors</h1>
|
||||
Implementation of minecraft selectors into PocketMine!
|
||||
|
||||
<h1><img src="https://png.icons8.com/?id=365&size=1x"> How to install?</h1>
|
||||
1. Download the .phar file from the link given at the top of the repo
|
||||
2. Put that phar into your "plugins" folder
|
||||
3. Restart your server and Selectors should be reay to go!
|
||||
|
||||
<h1><img src="https://png.icons8.com/?id=3330&size=1x"> Implemented features</h1>
|
||||
PlayerSelectors implements all the default minecraft selectors:<br>
|
||||
- @a - All players<br>
|
||||
- @p - Nearset player<br>
|
||||
- @e - Entities<br>
|
||||
- @r - Random player<br>
|
||||
- @s - Self/Sender<br>
|
||||
but also features a custom made one:<br>
|
||||
Since PocketMine implements a multi world system, you can easily select players from your current world using the "@w" selector!
|
||||
<br><br>
|
||||
Minecraft also supports specific search parameters such as the distance from the sender, the count of matched player/entities, ...<br>
|
||||
All the standard minecraft search params can be used with the syntax
|
||||
|
||||
```
|
||||
@<selector name>[key=param,other=value]
|
||||
```
|
||||
|
||||
EXEPT the team & score params since the /scoreboard command isn't implemeted into pocketmine yet<br> Thought, one new params comes with this plugin: the "lvl" param which is for searching in a specific level.
|
||||
|
||||
Have fun!
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
name: PlayerSelectors
|
||||
author: Ad5001
|
||||
version: 1.0
|
||||
api: [3.0.0-ALPHA9]
|
||||
main: Ad5001\PlayerSelectors\Main
|
||||
commands: []
|
||||
permissions: []
|
||||
...
|
@ -0,0 +1,180 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ad5001\PlayerSelectors;
|
||||
|
||||
use pocketmine\plugin\PluginBase;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\event\player\PlayerCommandPreprocessEvent;
|
||||
use pocketmine\event\server\ServerCommandEvent;
|
||||
|
||||
|
||||
use Ad5001\PlayerSelectors\selector\Selector;
|
||||
use Ad5001\PlayerSelectors\selector\ClosestPlayer;
|
||||
use Ad5001\PlayerSelectors\selector\AllPlayers;
|
||||
use Ad5001\PlayerSelectors\selector\RandomPlayer;
|
||||
use Ad5001\PlayerSelectors\selector\WorldPlayers;
|
||||
use Ad5001\PlayerSelectors\selector\Entities;
|
||||
use Ad5001\PlayerSelectors\selector\SelfSelector;
|
||||
|
||||
|
||||
class Main extends PluginBase implements Listener {
|
||||
|
||||
protected static $selectors = [];
|
||||
|
||||
/**
|
||||
* When the plugin enables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onEnable(): void{
|
||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
// Registering the default selectors
|
||||
self::registerSelector(new ClosestPlayer());
|
||||
self::registerSelector(new AllPlayers());
|
||||
self::registerSelector(new RandomPlayer());
|
||||
self::registerSelector(new WorldPlayers());
|
||||
self::registerSelector(new Entities());
|
||||
self::registerSelector(new SelfSelector());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When a command is executed, check for selectors
|
||||
*
|
||||
* @param PlayerCommandPreProcessEvent $event
|
||||
* @return void
|
||||
*/
|
||||
public function onCommandPreProcess(PlayerCommandPreProcessEvent $event): void{
|
||||
$m = $event->getMessage();
|
||||
$this->execSelectors($m, $event->getPlayer());
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When a command is executed, check for selectors
|
||||
*
|
||||
* @param PlayerCommandPreProcessEvent $event
|
||||
* @return void
|
||||
*/
|
||||
public function onServerCommand(ServerCommandEvent $event): void{
|
||||
$m = $event->getCommand();
|
||||
$this->execSelectors($m, $event->getSender());
|
||||
$event->setCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses selectors and executes the commands
|
||||
*
|
||||
* @param string $m The command
|
||||
* @param CommandSender $sender
|
||||
* @return void
|
||||
*/
|
||||
public function execSelectors(string $m, CommandSender $sender): void{
|
||||
preg_match_all($this->buildRegExr(), $m, $matches);
|
||||
$commandsToExecute = [$m];
|
||||
foreach($matches[0] as $index => $match){
|
||||
if(isset(self::$selectors[$matches[1][$index]])){ // Does the selector exist?
|
||||
// Search for the parameters
|
||||
echo $matches[1][$index];
|
||||
$params = self::$selectors[$matches[1][$index]]->acceptsModifiers() ? $this->checkArgParams($matches, $index): [];
|
||||
// Applying the selector
|
||||
$newCommandsToExecute = [];
|
||||
foreach($commandsToExecute as $index => $cmd){
|
||||
// Foreaching the returning commands to push them to the new commands to be executed at the next run.
|
||||
foreach(self::$selectors[$matches[1][$index]]->applySelector($sender, $params) as $selectorStr){
|
||||
$newCommandsToExecute[] = substr_replace($cmd, " " . $selectorStr . " ", strpos($cmd, $match), strlen($match));
|
||||
}
|
||||
if(count($newCommandsToExecute) == 0) {
|
||||
$sender->sendMessage("§cYour selector $match (" . self::$selectors[$matches[1][$index]]->getName() . ") did not mactch any player/entity.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
$commandsToExecute = $newCommandsToExecute;
|
||||
}
|
||||
}
|
||||
// Then we have all the commands here and we can execute them
|
||||
foreach($commandsToExecute as $cmd){
|
||||
$this->getServer()->dispatchCommand($sender, $cmd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the params in an array form in a match.
|
||||
*
|
||||
* @param array $match
|
||||
* @return void
|
||||
*/
|
||||
public function checkArgParams(array $match, int $index): array{
|
||||
$params = [];
|
||||
if(strlen($match[2][$index]) !== 0){ // Is there any command parameter?
|
||||
if(strpos($match[3][$index], ",") !== -1){ // Is there multiple arguments
|
||||
foreach(explode(",", $match[3][$index]) as $param){
|
||||
// Param here is in form argName=argproperty.
|
||||
// Parsing it to put it into the $params
|
||||
$parts = explode("=", $param);
|
||||
$params[$parts[0]] = $parts[1];
|
||||
}
|
||||
} else { // There is one argument
|
||||
$parts = explode("=", $match[3][$index]);
|
||||
$params[$parts[0]] = $parts[1];
|
||||
}
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the regexr for parsing selectors in commands
|
||||
* $1 is the selector character(s)
|
||||
* $2 is "Is there any arguments to the command?"
|
||||
* $3 is the list of arguments
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function buildRegExr(): string {
|
||||
$regexr = "/ @("; // Space is to check that it's an argument on it's own and not a part of one
|
||||
// Adding the selectors
|
||||
$regexr .= preg_replace("/(\\$|\\(|\\)|\\^|\\[|\\])/", "\\\\$1", // Always parse input we don't trust!
|
||||
implode("|", array_keys(self::$selectors))
|
||||
);
|
||||
// Adding the arguments
|
||||
$regexr .= ")(\\[(((\w+)?=(.)+(,)?){1,})\\])?";
|
||||
// Closing the regexr
|
||||
$regexr .= "( |$)/"; // Space is to check that it's an argument on it's own and not a part of one (cf twitter accounts would we used with @+some letters)
|
||||
return $regexr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a selector
|
||||
*
|
||||
* @param Selector $sel
|
||||
* @return void
|
||||
*/
|
||||
public static function registerSelector(Selector $sel): void{
|
||||
self::$selectors[$sel->getSelectorChar()] = $sel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a selector
|
||||
*
|
||||
* @param string $selChar The selector character
|
||||
* @return void
|
||||
*/
|
||||
public static function unregisterSelector(string $selChar): void{
|
||||
unset(self::$selectors[$selChar]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a selector
|
||||
*
|
||||
* @param string $selChar The selector character
|
||||
* @return Selector
|
||||
*/
|
||||
public static function getSelector(string $selChar): Selector{
|
||||
return self::$selectors[$selChar];
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ad5001\PlayerSelectors\selector;
|
||||
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\level\Position;
|
||||
|
||||
|
||||
class AllPlayers extends Selector{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct("All players", "a", 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;
|
||||
}
|
||||
$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)) {
|
||||
echo "Not checked param";
|
||||
break;
|
||||
}
|
||||
$return[] = $p->getName();
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ad5001\PlayerSelectors\selector;
|
||||
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
|
||||
class ClosestPlayer extends Selector{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct("Closest player", "p", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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{
|
||||
$online = Server::getInstance()->getOnlinePlayers();
|
||||
// Console
|
||||
if(!($sender instanceof Player)) {
|
||||
if(count($online) > 0){
|
||||
return [$online[0]];
|
||||
} else {
|
||||
return [$sender->getName()];
|
||||
}
|
||||
}
|
||||
// Player
|
||||
if(count($online) > 1){
|
||||
// Checking the closest player
|
||||
foreach($online as $p){
|
||||
if($p->getLevel()->getName() == $sender->getLevel()->getName() &&
|
||||
(!isset($selectedP) || $p->distanceSquared($sender) < $selectorP->distanceSquared($sender))){
|
||||
$selectedP = $p;
|
||||
}
|
||||
}
|
||||
return [$selectorP->getName()];
|
||||
} else {
|
||||
// Otherwise, just return sender's name because there's no other player.
|
||||
return [$sender->getName()];
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Ad5001\PlayerSelectors\selector;
|
||||
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\level\Position;
|
||||
|
||||
use Ad5001\PlayerSelectors\Main;
|
||||
|
||||
|
||||
class Entities extends Selector{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct("Entities", "e", 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;
|
||||
}
|
||||
$params = $parameters + $defaultParams;
|
||||
$return = [];
|
||||
foreach(Server::getInstance()->getLevels() as $lvl){
|
||||
foreach($lvl->getEntities() as $e){
|
||||
if($params["c"] !== 0 && count($return) == $params["c"]) break; // Too much players
|
||||
if($e->getLevel()->getName() !== $params["lvl"] && $params["lvl"] !== "") break; // Not in the right level
|
||||
if(!$this->checkDefaultParams($e, $params)) break;
|
||||
$return[] = "e" . $e->getId();
|
||||
}
|
||||
}
|
||||
return array_merge($return, Main::getSelector("a")->applySelector($sender, $parameters)); // Merging w/ all players so that it also adds players.
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace Ad5001\PlayerSelectors\selector;
|
||||
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\level\Position;
|
||||
|
||||
|
||||
class RandomPlayer extends Selector{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct("Random player", "r", 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;
|
||||
}
|
||||
$params = $parameters + $defaultParams;
|
||||
$possible = [];
|
||||
foreach(Server::getInstance()->getOnlinePlayers() as $p){
|
||||
if($p->getLevel()->getName() !== $params["lvl"] && $params["lvl"] !== "") break; // Not in the right level
|
||||
if(!$this->checkDefaultParams($p, $params)) break;
|
||||
$possible[] = $p;
|
||||
}
|
||||
if(count($possible) == 0) return [];
|
||||
return [$possible[array_rand($possible)]->getName()];
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ad5001\PlayerSelectors\selector;
|
||||
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\math\Vector3;
|
||||
|
||||
abstract class Selector {
|
||||
/**
|
||||
* Default minecraft selectors params.
|
||||
* Can be used in selectors that supports them.
|
||||
*/
|
||||
const DEFAULT_PARAMS = [
|
||||
// Coordinates of the center, will be modified if player in command
|
||||
"x" => 0,
|
||||
"y" => 0,
|
||||
"z" => 0,
|
||||
"lvl" => "", // The world to search in. Defaults to the current world in case of console, current world in the case of a player
|
||||
// Search by coordinates
|
||||
"dx" => 0, // Distance from the center in x (0 = no limit)
|
||||
"dy" => 0, // Distance from the center in y (0 = no limit)
|
||||
"dz" => 0, // Distance from the center in z (0 = no limit)
|
||||
"r" => 0, // Radius max (0 = no limit)
|
||||
"rm" => 0, // Radius min
|
||||
// Search by pitch and yaw
|
||||
"rx" => 180, // Pitch max
|
||||
"rxm" => 0, // Pitch min
|
||||
"ry" => 360, // Yaw max
|
||||
"rym" => 0, // Yaw min
|
||||
// Count searching
|
||||
"c" => 0,
|
||||
// Player parameters searching
|
||||
"m" => -1, // Gamemode
|
||||
"l" => PHP_INT_MAX, // Maximum xp level
|
||||
"lm" => 0, // Min xp level
|
||||
"name" => "", // Displayed name of the entity (display name for the player, name tag rename for entity)
|
||||
"type" => "all", // Type of the entity (only for entity selector). "all" means all entities
|
||||
"tag" => "Health", // Check if the tag exists in the entity/player.
|
||||
];
|
||||
|
||||
protected $name;
|
||||
protected $selectorChar;
|
||||
protected $acceptModifiers;
|
||||
|
||||
/**
|
||||
* Defines base for a selector
|
||||
*
|
||||
* @param string $name The name of the selector. E.g: "All players", "Entities", ...
|
||||
* @param string $selectorChar What should be after the "@" to use this selector
|
||||
* @param bool $acceptModifiers Should the selector accept modifiers? If false, arguments used in commands will be ignored. Can save alot of performances.
|
||||
*/
|
||||
public function __construct(string $name, string $selectorChar, bool $acceptModifiers){
|
||||
$this->name = $name;
|
||||
$this->selectorChar = $selectorChar;
|
||||
$this->acceptModifiers = $acceptModifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the selector. E.g: "All players", "Entities", ...
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the character of the selector. What should be after the "@" to use this selector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSelectorChar(): string{
|
||||
return $this->selectorChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the selector accept modifiers? If false, arguments used in commands will be ignored. Can save alot of performances.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function acceptsModifiers(): bool{
|
||||
return $this->acceptModifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the possible values for a selector depending on the sender and the parameters.
|
||||
* Return should be an array of all the possible strings that match up to this selector.
|
||||
*
|
||||
* @param CommandSender $sender
|
||||
* @param String[] $parameters
|
||||
* @return String[]
|
||||
*/
|
||||
abstract public function applySelector(CommandSender $sender, array $parameters = []): array;
|
||||
|
||||
/**
|
||||
* Check if an entity $et matches default params provided in $params.
|
||||
*
|
||||
* @param Entity $et
|
||||
* @param array $params
|
||||
* @return bool
|
||||
*/
|
||||
public function checkDefaultParams(Entity $et, array $params): bool{
|
||||
$dist = sqrt($et->distanceSquared(new Vector3($params["x"], $params["y"], $params["z"])));
|
||||
if(($params["r"] !== 0 && $dist > $params["r"]) || $dist < $params["rm"]) return false; // Not in range
|
||||
if($params["dx"] !== 0 && abs($et->x - $params["x"]) > $params["dx"]); // Not in x range
|
||||
if($params["dy"] !== 0 && abs($et->y - $params["y"]) > $params["dy"]); // Not in y range
|
||||
if($params["dz"] !== 0 && abs($et->z - $params["z"]) > $params["dz"]); // Not in z range
|
||||
if($params["m"] !== -1 && $et instanceof Player && $et->getGamemode() !== $params["m"]) return false; // Not in the right mode.
|
||||
if($params["rx"] < $et->getPitch() || $et->getPitch() < $params["rxm"]) return false; // Not in range pitch
|
||||
if($params["ry"] < $et->getYaw() || $et->getYaw() < $params["rym"]) return false; // Not in range yaw
|
||||
if($et instanceof Player && ($et->getXpLevel() > $params["l"] || $et->getXpLevel() < $params["lm"])) return false; // Not in range XP
|
||||
if($params["name"] !== "" && (($et instanceof Player && $et->getDisplayName() !== $params["name"]) ||
|
||||
(!($et instanceof Player) && $et->getNameTag() !== $params["name"]))) return false; // Not selected name
|
||||
// Entity type
|
||||
$etClassName = explode("\\", get_class($et))[count(explode("\\", get_class($et))) - 1];
|
||||
if(substr($params["type"], 0, 1) == "!" && $etClassName == substr($params["type"], 1)) return false; // Should not be this kind of entity
|
||||
if($params["type"] !== "all" && $etClassName !== $params["type"]) return false; // Not the required kind of entity
|
||||
return true; // All checks passed!
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Ad5001\PlayerSelectors\selector;
|
||||
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\Player;
|
||||
|
||||
class SelfSelector extends Selector{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct("Self", "s", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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{
|
||||
return [$sender->getName()];
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue