Advertisement
Guest User

Chestfinder pour perzival

a guest
Jul 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2.  
  3. namespace OlriaCore\Tasks;
  4.  
  5. use pocketmine\plugin\Plugin;
  6. use pocketmine\scheduler\Task;
  7. use pocketmine\Player;
  8. use pocketmine\tile\Chest;
  9. use pocketmine\math\Vector2;
  10.  
  11. use OlriaCore\Items\ChestFinder;
  12.  
  13. class ChestFinderTask extends Task
  14. {
  15.  
  16.     public $plugin;
  17.     public $chestFinder;
  18.     public $radius = 50;
  19.  
  20.  
  21.     public function __construct(Plugin $pl)
  22.     {
  23.         $this->plugin = $pl;
  24.     }
  25.  
  26.     public function onRun(int $tick)
  27.     {
  28.  
  29.         $players = $this->plugin->getServer()->getOnlinePlayers();
  30.  
  31.         foreach ($players as $p) {
  32.  
  33.             $i = $p->getInventory()->getItemInHand();
  34.  
  35.             if ($i->getId() === TON PTN DID) {
  36.  
  37.                 $playerVector = new Vector2($p->getX(), $p->getY());
  38.                 $playerVector3 = $p->asVector3();
  39.  
  40.                 $n = 0;
  41.                 $nearest = false;
  42.                 $tiles = $p->getLevel()->getTiles();
  43.  
  44.                 foreach ($tiles as $t) {
  45.  
  46.                     if ($t instanceof Chest) {
  47.  
  48.                         $chestVector = new Vector2($t->getX(), $t->getY());
  49.                         $chestVector3 = $t->asVector3();
  50.  
  51.                         if ($playerVector->distance($chestVector) <= $this->radius) {
  52.                             $n += 1;
  53.  
  54.                             if (!$nearest) {
  55.                                 $nearest = $playerVector3->distance($chestVector3);
  56.                             } else if ($nearest > $playerVector3->distance($chestVector3)) {
  57.                                 $nearest = $playerVector3->distance($chestVector3);
  58.                             }
  59.                         }
  60.                     }
  61.                 }
  62.  
  63.                 if ($n > 0) {
  64.                     $p->sendPopup('§cIl y a §6' . $n . ' §ccoffre(s) autour de toi !' . PHP_EOL . '§cLe coffre le plus proche est à §6' . intval($nearest) . ' §cblocs.');
  65.                 } else {
  66.                     $p->sendPopup('§cIl n\'y a aucun coffre autour de toi');
  67.                 }
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement