Skip to content

Commit

Permalink
Added exception handling in checking update
Browse files Browse the repository at this point in the history
  • Loading branch information
onebone committed Mar 13, 2015
1 parent 889fe24 commit e5ecd70
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion EconomyAPI/plugin.yml
@@ -1,6 +1,6 @@
name: EconomyAPI
main: onebone\economyapi\EconomyAPI
version: "2.0.5"
version: "2.0.6"
author: onebone
api:
- 1.0.0
Expand Down
44 changes: 20 additions & 24 deletions EconomyAPI/src/onebone/economyapi/EconomyAPI.php
Expand Up @@ -12,6 +12,7 @@
use pocketmine\plugin\PluginBase;
use pocketmine\Player;
use pocketmine\scheduler\CallbackTask;
use pocketmine\utils\Utils;

use onebone\economyapi\event\money\AddMoneyEvent;
use onebone\economyapi\event\money\ReduceMoneyEvent;
Expand Down Expand Up @@ -191,36 +192,31 @@ public function onEnable(){
}

if($this->config->get("check-update")){
$this->getLogger()->info("Checking for updates... It may be take some while.");
$lastest = $this->getLastestDescription();
$desc = \yaml_parse($lastest);

$description = $this->getDescription();
if(version_compare($description->getVersion(), $desc["version"]) < 0){
$this->getLogger()->warning("New version of EconomyAPI (v".$desc["version"].") has been found. Current version : v".$description->getVersion().". Please update the plugin.");
}else{
$this->getLogger()->notice("EconomyAPI is currently up-to-date.");
}

if($desc["author"] !== $description->getAuthors()[0]){
$this->getLogger()->warning("You are using the modified version of the plugin. This version could not be supported.");
try{
$this->getLogger()->info("Checking for updates... It may be take some while.");
//$lastest = $this->getLastestDescription();
$lastest = Utils::getURL("https://raw.githubusercontent.com/onebone/EconomyS/master/EconomyAPI/plugin.yml");

$desc = \yaml_parse($lastest);

$description = $this->getDescription();
if(version_compare($description->getVersion(), $desc["version"]) < 0){
$this->getLogger()->warning("New version of EconomyAPI (v".$desc["version"].") has been found. Current version : v".$description->getVersion().". Please update the plugin.");
}else{
$this->getLogger()->notice("EconomyAPI is currently up-to-date.");
}

if($desc["author"] !== $description->getAuthors()[0]){
$this->getLogger()->warning("You are using the modified version of the plugin. This version could not be supported.");
}
}catch(\Exception $e){
$this->getLogger()->warning("An exception during check-update has been detected.");
}
}

$this->registerList("EconomyAPI");
}

private function getLastestDescription(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://raw.githubusercontent.com/onebone/EconomyS/master/EconomyAPI/plugin.yml');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);

return $content;
}

private function convertData(){
$cnt = 0;
if(is_file($this->path."MoneyData.yml")){
Expand Down

0 comments on commit e5ecd70

Please sign in to comment.