-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
9 changed files
with
209 additions
and
106 deletions.
There are no files selected for viewing
Binary file not shown.
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,8 @@ | ||
{ | ||
"plugin_name": "ProfanityFilter", | ||
"version": "0.0.7", | ||
"channel": "stable" | ||
"api": "4.0.0", | ||
"author": "ReinfyTeam", | ||
"artifactUrl": "https://github.com/ReinfyTeam/ProfanityFilter/releases/download/v0.0.7/ProfanityFilter.phar" | ||
} |
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
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,80 @@ | ||
<?php | ||
|
||
/* | ||
* | ||
* ____ _ __ _____ | ||
* | _ \ ___ (_) _ __ / _| _ _ |_ _| ___ __ _ _ __ ___ | ||
* | |_) | / _ \ | | | '_ \ | |_ | | | | | | / _ \ / _` | | '_ ` _ \ | ||
* | _ < | __/ | | | | | | | _| | |_| | | | | __/ | (_| | | | | | | | | ||
* |_| \_\ \___| |_| |_| |_| |_| \__, | |_| \___| \__,_| |_| |_| |_| | ||
* |___/ | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* @author ReinfyTeam | ||
* @link https://github.com/ReinfyTeam/ | ||
* | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ReinfyTeam\ProfanityFilter\Tasks; | ||
|
||
use pocketmine\scheduler\AsyncTask; | ||
use pocketmine\Server; | ||
use pocketmine\utils\Internet; | ||
use ReinfyTeam\ProfanityFilter\Utils\Language; | ||
use function json_decode; | ||
use function version_compare; | ||
use function vsprintf; | ||
|
||
class GithubUpdateTask extends AsyncTask { | ||
private const GIT_URL = "https://raw.githubusercontent.com/ReinfyTeam/ProfanityFilter/main/github.json"; | ||
|
||
public function __construct(private string $pluginName, private string $pluginVersion) { | ||
//NOOP | ||
} | ||
|
||
public function onRun() : void { | ||
$json = Internet::getURL(self::GIT_URL, 10, [], $err); | ||
|
||
if($json->getBody() != null){ | ||
$releases = json_decode($json->getBody(), true); | ||
if($releases != null){ | ||
$highestVersion = $releases["highestVersion"]; | ||
$artifactUrl = $releases["artifactUrl"]; | ||
$api = $releases["api"]; | ||
} else { | ||
$highestVersion = ""; | ||
$artifactUrl = ""; | ||
$api = ""; | ||
$err = "Unable to read json object properties."; | ||
} | ||
} | ||
|
||
$this->setResult([$highestVersion, $artifactUrl, $api, $err]); | ||
} | ||
|
||
public function onCompletion() : void { | ||
$lang = new Language(); | ||
[$highestVersion, $artifactUrl, $api, $err] = $this->getResult(); | ||
$plugin = Server::getInstance()->getPluginManager()->getPlugin($this->pluginName); | ||
if ($plugin === null) { | ||
return; | ||
} | ||
if ($err !== null) { | ||
Server::getInstance()->getLogger()->critical($lang->translateMessage("new-update-prefix") . " " . vsprintf($lang->translateMessage("update-error"), [$err . " Giving up..."])); | ||
return; | ||
} | ||
|
||
if ($highestVersion !== $this->pluginVersion) { | ||
Server::getInstance()->getLogger()->warning($lang->translateMessage("new-update-prefix") . " " . vsprintf($lang->translateMessage("new-update-found"), [$highestVersion, $api])); | ||
} else { | ||
Server::getInstance()->getLogger()->notice($lang->translateMessage("new-update-prefix") . " " . $lang->translateMessage("no-updates-found")); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.