From 08f6a93a57bed86d5beb822bdc41f99f41167d35 Mon Sep 17 00:00:00 2001 From: Flavius12 Date: Sat, 27 Dec 2014 16:17:30 +0100 Subject: [PATCH] Create Update.php --- src/AutoUpdater/Commands/Update.php | 73 +++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/AutoUpdater/Commands/Update.php diff --git a/src/AutoUpdater/Commands/Update.php b/src/AutoUpdater/Commands/Update.php new file mode 100644 index 0000000..ed027a4 --- /dev/null +++ b/src/AutoUpdater/Commands/Update.php @@ -0,0 +1,73 @@ +plugin = $plugin; + } + + public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { + $fcmd = strtolower($cmd->getName()); + switch($fcmd){ + case "update": + if($sender->hasPermission("autoupdater.update")){ + $query = $this->plugin->getQuery($this->plugin->getChannel()); + $version = new VersionString(); + //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(); + $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&aUpdating PocketMine...")); + $sender->sendMessage($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"]))); + $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)){ + $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&aPocketMine updated. Restarting server now...")); + $this->plugin->getServer()->forceShutdown(); + sleep(1); + copy($this->plugin->getDataFolder() . "/" . $filename, $this->plugin->getServer()->getDataPath() . "/" . $filename); + unlink($this->plugin->getDataFolder() . "/" . $filename); + shell_exec($this->plugin->getStartScript()); + }else{ + $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cCan't update PocketMine, an error has occurred")); + } + }else{ + $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&aYour PocketMine version is already up to date.")); + } + }else{ + $sender->sendMessage($this->plugin->translateColors("&", Main::PREFIX . "&cCan't update PocketMine, an error has occurred")); + } + }else{ + $sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command")); + break; + } + } + } +}