Exemplo n.º 1
0
 /**
  * @param $currentTick
  */
 public function onRun($currentTick)
 {
     if ($this->index < 0) {
         Cameraman::getInstance()->sendMessage($this->getCamera()->getTarget(), "message-travelling-started", ["slowness" => $this->getCamera()->getSlowness()]);
         $this->index = 0;
     }
     if ($this->index >= count($this->getCamera()->getMovements())) {
         $this->getCamera()->stop();
         return;
     }
     if (($location = $this->getCamera()->getMovement($this->index)->tick($this->getCamera()->getSlowness())) === null) {
         $this->index++;
         return;
     }
     $this->getCamera()->getTarget()->setPositionAndRotation($location, $location->getYaw(), $location->getPitch());
     Cameraman::sendMovePlayerPacket($this->getCamera()->getTarget());
 }
Exemplo n.º 2
0
 public function onRun($currentTick)
 {
     Cameraman::getInstance()->saveConfigs();
 }
Exemplo n.º 3
0
 /**
  * @param CommandSender $sender
  * @param Command $command
  * @param string $commandAlias
  * @param array $args
  * @return bool
  */
 public function onCommand(CommandSender $sender, Command $command, $commandAlias, array $args)
 {
     if (!$sender instanceof Player) {
         $this->sendMessage($sender, "#error-only-in-game");
         return true;
     }
     if ($commandAlias === "p") {
         //shortcut for /cam p
         array_unshift($args, "p");
     }
     if (count($args) < 1) {
         return $this->sendHelpMessages($sender);
     }
     switch (strToLower($args[0])) {
         default:
             $this->sendUnknownCommandErrorMessage($sender);
             break;
         case "help":
             if (count($args) > 1) {
                 return $this->sendHelpMessages($sender, $args[1]);
             } else {
                 return $this->sendHelpMessages($sender);
             }
         case "about":
             return $this->sendAboutMessages($sender);
         case "p":
             if (($waypoints = $this->getWaypoints($sender)) === null) {
                 $waypoints = $this->setWaypoints($sender, []);
             }
             if (count($args) > 1 and is_numeric($args[1])) {
                 if ($this->checkIndex($index = intval($args[1]), $waypoints, $sender)) {
                     return true;
                 }
                 $waypoints = $this->setWaypoint($sender, $sender->getLocation(), $index - 1);
                 $this->sendMessage($sender, "message-reset-waypoint", ["index" => $index, "total" => count($waypoints)]);
             } else {
                 $waypoints = $this->setWaypoint($sender, $sender->getLocation());
                 $this->sendMessage($sender, "message-added-waypoint", ["index" => count($waypoints)]);
             }
             break;
         case "start":
             if (count($args) < 2 or !is_numeric($args[1])) {
                 return $this->sendHelpMessages($sender, $args[0]);
             }
             if (($waypoints = $this->getWaypoints($sender)) === null or count($waypoints) < 2) {
                 $this->sendMessage($sender, "#error-too-few-waypoints");
                 return $this->sendHelpMessages($sender, "p");
             }
             if (($slowness = doubleval($args[1])) < 1.0E-7) {
                 return $this->sendMessage($sender, "#error-negative-slowness", ["slowness" => $slowness]);
             }
             if (($camera = $this->getCamera($sender)) !== null and $camera->isRunning()) {
                 $this->sendMessage($sender, ".message-interrupting-current-travel");
                 $camera->stop();
             }
             $this->setCamera($sender, new Camera($sender, Cameraman::createStraightMovements($waypoints), $slowness))->start();
             break;
         case "stop":
             if (($camera = $this->getCamera($sender)) === null or !$camera->isRunning()) {
                 return $this->sendMessage($sender, "#error-travels-already-interrupted");
             }
             $camera->stop();
             unset($camera);
             $this->sendMessage($sender, "message-travelling-interrupted");
             break;
         case "info":
             if (($waypoints = $this->getWaypoints($sender)) === null or count($waypoints) === 0) {
                 return $this->sendMessage($sender, "#error-no-waypoints-to-show");
             }
             if (count($args) > 1 and is_numeric($args[1])) {
                 if ($this->checkIndex($index = intval($args[1]), $waypoints, $sender)) {
                     return true;
                 }
                 $this->sendWaypointMessage($sender, $waypoints[$index - 1], $index);
             } else {
                 foreach ($waypoints as $index => $waypoint) {
                     $this->sendWaypointMessage($sender, $waypoint, $index + 1);
                 }
             }
             break;
         case "goto":
             if (count($args) < 2 or !is_numeric($args[1])) {
                 return $this->sendHelpMessages($sender, $args[0]);
             }
             if (($waypoints = $this->getWaypoints($sender)) === null or count($waypoints) === 0) {
                 return $this->sendMessage($sender, "#error-no-waypoints-to-teleport");
             }
             if ($this->checkIndex($index = intval($args[1]), $waypoints, $sender)) {
                 return true;
             }
             $sender->teleport($waypoints[$index - 1]);
             $this->sendMessage($sender, "message-teleported", ["index" => $index]);
             break;
         case "clear":
             if (($waypoints = $this->getWaypoints($sender)) === null or count($waypoints) === 0) {
                 return $this->sendMessage($sender, "#error-no-waypoints-to-remove");
             }
             if (count($args) > 1 and is_numeric($args[1])) {
                 if ($this->checkIndex($index = intval($args[1]), $waypoints, $sender)) {
                     return true;
                 }
                 array_splice($waypoints, $index - 1, 1);
                 $this->sendMessage($sender, "message-removed-waypoint", ["index" => $index, "total" => count($waypoints)]);
             } else {
                 unset($waypoints);
                 $this->sendMessage($sender, "message-all-waypoint-removed");
             }
             break;
     }
     return true;
 }
Exemplo n.º 4
0
 public function stop()
 {
     if ($this->isRunning()) {
         Cameraman::getInstance()->getServer()->getScheduler()->cancelTask($this->taskId);
         $this->taskId = -1;
         $this->getTarget()->teleport($this->location);
         $this->getTarget()->setGamemode($this->gamemode);
         Cameraman::getInstance()->sendMessage($this->getTarget(), "message-travelling-finished");
     }
 }