Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace OlriaCore\Tasks;
- use pocketmine\plugin\Plugin;
- use pocketmine\scheduler\Task;
- use pocketmine\Player;
- use pocketmine\tile\Chest;
- use pocketmine\math\Vector2;
- use OlriaCore\Items\ChestFinder;
- class ChestFinderTask extends Task
- {
- public $plugin;
- public $chestFinder;
- public $radius = 50;
- public function __construct(Plugin $pl)
- {
- $this->plugin = $pl;
- }
- public function onRun(int $tick)
- {
- $players = $this->plugin->getServer()->getOnlinePlayers();
- foreach ($players as $p) {
- $i = $p->getInventory()->getItemInHand();
- if ($i->getId() === TON PTN DID) {
- $playerVector = new Vector2($p->getX(), $p->getY());
- $playerVector3 = $p->asVector3();
- $n = 0;
- $nearest = false;
- $tiles = $p->getLevel()->getTiles();
- foreach ($tiles as $t) {
- if ($t instanceof Chest) {
- $chestVector = new Vector2($t->getX(), $t->getY());
- $chestVector3 = $t->asVector3();
- if ($playerVector->distance($chestVector) <= $this->radius) {
- $n += 1;
- if (!$nearest) {
- $nearest = $playerVector3->distance($chestVector3);
- } else if ($nearest > $playerVector3->distance($chestVector3)) {
- $nearest = $playerVector3->distance($chestVector3);
- }
- }
- }
- }
- if ($n > 0) {
- $p->sendPopup('§cIl y a §6' . $n . ' §ccoffre(s) autour de toi !' . PHP_EOL . '§cLe coffre le plus proche est à §6' . intval($nearest) . ' §cblocs.');
- } else {
- $p->sendPopup('§cIl n\'y a aucun coffre autour de toi');
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement