From 8639888cedac548010466401c4988a8c6ff88c31 Mon Sep 17 00:00:00 2001 From: Flavius12 Date: Sat, 27 Dec 2014 16:16:51 +0100 Subject: [PATCH] Create Query.php --- src/AutoUpdater/Query.php | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/AutoUpdater/Query.php diff --git a/src/AutoUpdater/Query.php b/src/AutoUpdater/Query.php new file mode 100644 index 0000000..0cb6545 --- /dev/null +++ b/src/AutoUpdater/Query.php @@ -0,0 +1,66 @@ +plugin = $plugin; + } + + public function onRun($currentTick){ + $this->plugin = $this->getOwner(); + $this->cfg = $this->plugin->getConfig()->getAll(); + $query = $this->plugin->getQuery($this->plugin->getChannel()); + $version = new VersionString(); + $server = Server::getInstance(); + $logger = $server->getLogger(); + //Checking query + if(isset($query["version"]) && isset($query["api_version"]) && isset($query["build"]) && isset($query["date"]) && isset($query["details_url"]) && isset($query["download_url"])){ + //Checking Build + if($version->getBuild() < $query["build"]){ + $filename = $this->plugin->getFileName(); + $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&aA new PocketMine update is available!")); + $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&eDetails: PocketMine " . $version->get() . " (Build #" . $query["build"] . ") API " . $query["api_version"] . " was released on " . date("d/m/Y h:i:s", $query["date"]))); + $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&eDownload URL: " . $query["download_url"])); + //Check auto-update + if($this->cfg["auto-update"] == true){ + $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&aUpdating PocketMine...")); + $this->plugin->getServer()->getScheduler()->scheduleAsyncTask(new Downloader($query["download_url"], $this->plugin->getDataFolder() . "/" . $filename)); + //Do Timeout + sleep($this->plugin->getTimeout()); + //Checking status + if(file_exists($this->plugin->getDataFolder() . "/" . $filename)){ + $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&aPocketMine updated. Restarting server now...")); + $this->plugin->getServer()->forceShutdown(); + sleep(1); + copy($this->plugin->getDataFolder() . "/" . $this->plugin->getFileName(), $this->plugin->getServer()->getDataPath() . "/" . $filename); + unlink($this->plugin->getDataFolder() . "/" . $filename); + shell_exec($this->plugin->getStartScript()); + }else{ + $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&cCan't update PocketMine, an error has occurred")); + } + } + } + }else{ + $logger->info($this->plugin->translateColors("&", Main::PREFIX . "&cCan't update PocketMine, an error has occurred")); + } + } +} +?>