public function onEnable()
 {
     $this->setEnabled(true);
     $this->loadConfiguration();
     $this->qrlist = QRhelper::LoadQR($this);
     $this->getServer()->getPluginManager()->registerEvents(new QRcraftPlugInListener($this), $this);
     $this->log(TextFormat::GREEN . "QRcraft - Enabled");
 }
 public function onPlayerInteract(PlayerInteractEvent $event)
 {
     $level = $event->getPlayer()->level;
     $player = $event->getPlayer();
     $blockTouched = $event->getBlock();
     //        if (\pocketmine\DEBUG > 1) {
     //            $direction = $player->getDirectionVector();
     //            $msg = "Player direction is X:" . round($direction->x, 2) . " Y:" . round($direction->y, 2) . " Z:" . round($direction->z, 2);
     //            $this->pgin->log($msg);
     //            $player->sendMessage($msg);
     //        }
     QRhelper::CreateQRAndUnmark($this->pgin, $player, $blockTouched, $level, true);
 }
Пример #3
0
 public static function SaveQRlist(QRcraftPlugIn $plugin)
 {
     //save list
     $path = QRhelper::GetQRfile($plugin);
     $config = new Config($path, Config::JSON);
     $config->setAll($plugin->qrlist);
     return $config->save();
 }
 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     $cmd = strtolower($command->getName());
     if ($sender instanceof Player) {
         $player = $sender->getPlayer();
         switch ($cmd) {
             case "qr":
                 $this->showusage($sender);
                 break;
             case "qrt":
                 if (isset($args[0])) {
                     $url = $args[0];
                     $size = QRhelper::TestQRCode(true, $url);
                     $sender->sendMessage("QR panel for '{$url}' will need " . $size . "x" . $size . " blocks");
                 } else {
                     $this->showusage($sender);
                 }
                 break;
             case "qrc":
                 if (isset($args[0])) {
                     $url = $args[0];
                     $orientation = isset($args[1]) ? strtolower($args[1]) : "a";
                     //a - auto
                     $allor = array("h", "v", "a");
                     if (!in_array($orientation, $allor)) {
                         $this->showusage($sender);
                     } else {
                         QRhelper::MarkPlayerCanCreateQR($this->pgin, $player, $url, $orientation);
                     }
                 } else {
                     $this->showusage($sender);
                 }
                 break;
             case "qrl":
                 if (!isset($this->pgin->qrlist) || count($this->pgin->qrlist) == 0) {
                     $player->sendMessage("QR panels list is empty!");
                 } else {
                     $player->sendMessage("--------------");
                     $player->sendMessage("QR LIST");
                     $player->sendMessage("--------------");
                     foreach ($this->pgin->qrlist as $li) {
                         $liId = $li[0];
                         $liText = $li[1];
                         $liSize = $li[2];
                         $coord = $li[3];
                         $liCoord = "x:" . $coord[0] . "-y:" . $coord[1] . "-z:" . $coord[2];
                         //implode("-",$li[3]);
                         $player->sendMessage("[{$liId}] '{$liText}' ({$liSize}) {$liCoord}");
                     }
                     $player->sendMessage("--------------");
                 }
                 break;
             case "qrd":
                 if (!isset($this->pgin->qrlist) || count($this->pgin->qrlist) == 0) {
                     $player->sendMessage("QR panel list is empty!");
                 } else {
                     if (isset($args[0])) {
                         $idToDelete = $args[0];
                         $wasDeleted = false;
                         foreach ($this->pgin->qrlist as $li) {
                             if ($idToDelete == $li[0]) {
                                 //delete in world (fill with air)
                                 $coord = $li[3];
                                 QRhelper::FillWithAir($player->level, $coord);
                                 //delete from file
                                 unset($this->pgin->qrlist[array_search($li, $this->pgin->qrlist)]);
                                 QRhelper::SaveQRlist($this->pgin);
                                 $wasDeleted = true;
                                 $player->sendMessage("QR panel [{$idToDelete}] deleted.");
                                 break;
                             }
                         }
                         if (!$wasDeleted) {
                             $player->sendMessage("QR panel [{$idToDelete}] not found.");
                         }
                     } else {
                         $this->showusage($sender);
                     }
                 }
                 break;
             case "qrp":
                 if (!isset($this->pgin->qrlist) || count($this->pgin->qrlist) == 0) {
                     $player->sendMessage("QR panel list is empty!");
                 } else {
                     if (isset($args[0])) {
                         $idToTP = $args[0];
                         $qrItem = null;
                         foreach ($this->pgin->qrlist as $li) {
                             if ($idToTP == $li[0]) {
                                 $qrItem = $li;
                             }
                         }
                         if (isset($qrItem) && !is_null($qrItem)) {
                             //get qr code panel coords
                             $coord = $qrItem[3];
                             $coord[0] = $coord[0] - 2;
                             $coord[2] = $coord[2] - 2;
                             //tp playr
                             $player->teleport(new Vector3($coord[0], $coord[1], $coord[2]));
                             $player->sendMessage("You've been teleported nearby QR panel [{$idToTP}].");
                         } else {
                             $player->sendMessage("QR panel [{$idToTP}] not found.");
                         }
                     } else {
                         $this->showusage($sender);
                     }
                 }
                 break;
             default:
                 $this->showusage($sender);
                 break;
         }
         return true;
     } else {
         $this->showusage($sender);
     }
 }