Hello, I have a doubt, and state created a plugin, and for example, I want the command "test", give the player and others near the say within a radius of 5 blocks, give it an effect or enchantment, for this I understand that I need a foreach, but I do not know how to create it for this kind of thing, if someone can support me would be appreciated!!
PHP: foreach(Server::getInstance()->getOnlinePlayers() as $player){ if($player->distance($position) <= 5){ // do your thing here }}
Thank you very much, I would thank you very much for the answer, something else in the case of wanting to give an enchantment (in //do your thing here) as it would be?
PHP: foreach(Server::getInstance()->getOnlinePlayers() as $player){ if($player->distance($position) <= 5){ $iteminhand = $player->getInventory()->getItemInHand(); $en = Enchantment::getEnchantment(Enchantment::UNBREAKING); $ench = new EnchantmentInstance($en,10); $iteminhand->addEnchantment($ench); $player->getInventory->setItemInHand(); }}