-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nmtho
committed
Dec 1, 2023
1 parent
37f543e
commit 453e887
Showing
6 changed files
with
90 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of oh-my-pmmp. | ||
* | ||
* (c) thebigcrafter <[email protected]> | ||
* | ||
* This source file is subject to the GPL-3.0 license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace thebigcrafter\omp\helpers; | ||
|
||
use Closure; | ||
use Exception; | ||
use Generator; | ||
use SOFe\AwaitGenerator\Await; | ||
use function file_put_contents; | ||
|
||
class PharHelper | ||
{ | ||
public static function writePhar(string $path, string $content) : Generator | ||
{ | ||
return yield from Await::promise(function (Closure $resolve, Closure $reject) use ($path, $content) { | ||
$exec = file_put_contents($path, $content); | ||
|
||
if ($exec === false) { | ||
$reject(new Exception("Cannot create Phar file")); | ||
} | ||
|
||
$resolve($exec); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of oh-my-pmmp. | ||
* | ||
* (c) thebigcrafter <[email protected]> | ||
* | ||
* This source file is subject to the GPL-3.0 license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace thebigcrafter\omp\tasks; | ||
|
||
|
||
/* | ||
* This file is part of oh-my-pmmp. | ||
* | ||
* (c) thebigcrafter <[email protected]> | ||
* | ||
* This source file is subject to the GPL-3.0 license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace thebigcrafter\omp\tasks; | ||
|
||
use pocketmine\scheduler\AsyncTask; | ||
use pocketmine\utils\Internet; | ||
use thebigcrafter\omp\Language; | ||
use thebigcrafter\omp\OhMyPMMP; | ||
use function json_decode; | ||
use function version_compare; | ||
|
||
use function version_compare; | ||
|
||
final class CheckForUpdates extends AsyncTask | ||
{ | ||
private string $highestVersion; | ||
|
@@ -28,33 +28,33 @@ public function __construct(private readonly string $name, private string $curre | |
{ | ||
$this->highestVersion = $currentVersion; | ||
$this->artifactUrl = ""; | ||
} | ||
|
||
} | ||
|
||
public function onRun() : void | ||
{ | ||
$res = Internet::getURL("https://poggit.pmmp.io/releases.min.json?name=" . $this->name); | ||
|
||
$releases = (array) json_decode($res->getBody(), true); | ||
|
||
$res = Internet::getURL("https://poggit.pmmp.io/releases.min.json?name=" . $this->name); | ||
|
||
$releases = (array) json_decode($res->getBody(), true); | ||
|
||
if ($releases !== null) { | ||
/** | ||
* @var array{'version': string, 'artifact_url': string} $release | ||
/** | ||
* @var array{'version': string, 'artifact_url': string} $release | ||
*/ | ||
foreach ($releases as $release) { | ||
if (version_compare($this->highestVersion, $release["version"], ">")) { | ||
continue; | ||
} | ||
|
||
} | ||
|
||
$this->highestVersion = $release["version"]; | ||
$this->artifactUrl = $release["artifact_url"]; | ||
} | ||
} | ||
|
||
} | ||
|
||
if ($this->highestVersion !== $this->currentVersion) { | ||
$this->setResult(false); | ||
} | ||
} | ||
|
||
} | ||
|
||
public function onCompletion() : void | ||
{ | ||
if (!$this->getResult()) { | ||
|
@@ -67,4 +67,4 @@ public function onCompletion() : void | |
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters