-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/CortexPE/Commando | ||
branches: | ||
- master | ||
projects: | ||
Commando: | ||
model: virion | ||
type: library | ||
lint: | ||
phpstan: false | ||
... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/JackMD/ConfigUpdater | ||
branches: | ||
- master | ||
projects: | ||
ConfigUpdater: | ||
path: "" | ||
model: virion | ||
type: library | ||
... |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# ConfigUpdater | ||
|
||
| HitCount | License | | ||
|:--:|:--:| | ||
|[![HitCount](http://hits.dwyl.io/JackMD/ConfigUpdater.svg)](http://hits.dwyl.io/JackMD/ConfigUpdater)|[![GitHub license](https://img.shields.io/github/license/JackMD/ConfigUpdater.svg)](https://github.com/JackMD/ConfigUpdater/blob/master/LICENSE)| | ||
|
||
### A handy virion for PocketMine-MP plugin developers that checks if a new version of config is available. If so then it notifies the user about the new update and updates the config. | ||
|
||
### Features | ||
|
||
- Super simple virion to be used in your plugins. | ||
- It checks if a new version of config is available and if so it then updates and notifies the user. | ||
|
||
### API | ||
|
||
```php | ||
JackMD\ConfigUpdater\ConfigUpdater::checkUpdate(Plugin $plugin, Config $config, string $configKey, int $latestVersion, string $updateMessage = ""); | ||
``` | ||
|
||
- **$plugin** is the plugin whom you are calling the function from. | ||
- **$config** is the config you want to update. | ||
- **$configKey** is the version key that needs to be checked in the config. | ||
- **$latestVersion** is the latest version of the config. Needs to be integer. | ||
- **$updateMessage** is the update message that would be shown on console if the plugin is outdated. | ||
|
||
<br /> | ||
|
||
- For information regarding how to use a virion in a plugin please refer [here](https://poggit.github.io/support/virion.html) | ||
|
||
### Disclaimer | ||
|
||
This plugin is designed to be used only by PocketMine-MP developers who wish to provide their users with the info of when an update to the config is available. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
/** | ||
* _____ __ _ _ _ _ _ | ||
* / __ \ / _(_) | | | | | | | | | ||
* | / \/ ___ _ __ | |_ _ __ _| | | |_ __ __| | __ _| |_ ___ _ __ | ||
* | | / _ \| '_ \| _| |/ _` | | | | '_ \ / _` |/ _` | __/ _ \ '__| | ||
* | \__/\ (_) | | | | | | | (_| | |_| | |_) | (_| | (_| | || __/ | | ||
* \____/\___/|_| |_|_| |_|\__, |\___/| .__/ \__,_|\__,_|\__\___|_| | ||
* __/ | | | | ||
* |___/ |_| | ||
* | ||
* ConfigUpdater, a updater virion for PocketMine-MP | ||
* Copyright (c) 2018 JackMD < https://github.com/JackMD > | ||
* | ||
* Discord: JackMD#3717 | ||
* Twitter: JackMTaylor_ | ||
* | ||
* This software is distributed under "GNU General Public License v3.0". | ||
* | ||
* ConfigUpdater is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License v3.0 for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License v3.0 | ||
* along with this program. If not, see | ||
* <https://opensource.org/licenses/GPL-3.0>. | ||
* ------------------------------------------------------------------------ | ||
*/ | ||
|
||
namespace JackMD\ConfigUpdater; | ||
|
||
use pocketmine\plugin\Plugin; | ||
use pocketmine\scheduler\ClosureTask; | ||
use pocketmine\utils\Config; | ||
|
||
class ConfigUpdater{ | ||
|
||
/** | ||
* @param Plugin $plugin The plugin you are calling this from. | ||
* @param Config $config The config you want to update. | ||
* @param string $configKey The version key that needs to be checked in the config. | ||
* @param int $latestVersion The latest version of the config. Needs to be integer. | ||
* @param string $updateMessage The update message that would be shown on console if the plugin is outdated. | ||
* @return bool | ||
* @throws \ReflectionException | ||
*/ | ||
public static function checkUpdate(Plugin $plugin, Config $config, string $configKey, int $latestVersion, string $updateMessage = ""): bool{ | ||
if(($config->exists($configKey)) && ((int) $config->get($configKey) === $latestVersion)){ | ||
return false; | ||
} | ||
|
||
$configData = self::getConfigData($config); | ||
$configPath = $configData["configPath"]; | ||
$originalConfig = $configData["configName"]; | ||
$oldConfig = $configData["oldConfigName"]; | ||
|
||
if(trim($updateMessage) === ""){ | ||
$updateMessage = "Your $originalConfig file is outdated. Your old $originalConfig has been saved as $oldConfig and a new $originalConfig file has been generated. Please update accordingly."; | ||
} | ||
|
||
rename($configPath . $originalConfig, $configPath . $oldConfig); | ||
|
||
$plugin->saveResource($originalConfig); | ||
|
||
$task = new ClosureTask(function(int $currentTick) use ($plugin, $updateMessage): void{ | ||
$plugin->getLogger()->critical($updateMessage); | ||
}); | ||
|
||
/* This task is here so that the update message can be sent after full server load */ | ||
$plugin->getScheduler()->scheduleDelayedTask($task, 3 * 20); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Pretty self explanatory I guess... | ||
* | ||
* @param Config $config | ||
* @return array | ||
* @throws \ReflectionException | ||
*/ | ||
private static function getConfigData(Config $config): array{ | ||
$configPath = self::getConfigPath($config); | ||
$configData = explode(".", basename($configPath)); | ||
|
||
$configName = $configData[0]; | ||
$configExtension = $configData[1]; | ||
|
||
$originalConfigName = $configName . "." . $configExtension; | ||
$oldConfigName = $configName . "_old." . $configExtension; | ||
|
||
$configPath = str_replace($originalConfigName, "", $configPath); | ||
$pluginPath = str_replace("plugin_data", "plugins", $configPath); | ||
|
||
return [ | ||
"configPath" => $configPath, | ||
"pluginPath" => $pluginPath, | ||
"configName" => $originalConfigName, | ||
"oldConfigName" => $oldConfigName | ||
]; | ||
} | ||
|
||
/** | ||
* This function is here until PM adds the function to get file path. | ||
* | ||
* @param Config $config | ||
* @return string | ||
* @throws \ReflectionException | ||
*/ | ||
private static function getConfigPath(Config $config): string{ | ||
$pathReflection = new \ReflectionProperty(Config::class, 'file'); | ||
$pathReflection->setAccessible(true); | ||
|
||
return $pathReflection->getValue($config); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: ConfigUpdater | ||
version: 1.2.0 | ||
api: [3.0.0] | ||
antigen: JackMD\ConfigUpdater | ||
author: JackMD | ||
php: [7.2, 7.3, 7.4] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/Muqsit/InvMenu | ||
branches: | ||
- master | ||
- master-invmenu-4.0 | ||
- "4.0" | ||
projects: | ||
InvMenu: | ||
model: virion | ||
type: library | ||
... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/buchwasa/ScoreFactory | ||
branches: | ||
- main | ||
- pm4 | ||
projects: | ||
ScoreFactory: | ||
path: "" | ||
model: virion | ||
type: library | ||
... |