Skip to content

Commit

Permalink
Update library package
Browse files Browse the repository at this point in the history
  • Loading branch information
HUYDGD committed Nov 15, 2020
1 parent 7621fd4 commit 36cb4b5
Show file tree
Hide file tree
Showing 26 changed files with 2,101 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Commando/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Commando/.idea/Commando.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Commando/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Commando/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Commando/.idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Commando/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Commando/.poggit.yml
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
...
9 changes: 9 additions & 0 deletions ConfigUpdater/.poggit.yml
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
...
674 changes: 674 additions & 0 deletions ConfigUpdater/LICENSE

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions ConfigUpdater/README.md
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.
119 changes: 119 additions & 0 deletions ConfigUpdater/src/JackMD/ConfigUpdater/ConfigUpdater.php
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);
}
}
6 changes: 6 additions & 0 deletions ConfigUpdater/virion.yml
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]
10 changes: 10 additions & 0 deletions InvMenu/.poggit.yml
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
...
10 changes: 10 additions & 0 deletions ScoreFactory-main/.poggit.yml
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
...
Loading

0 comments on commit 36cb4b5

Please sign in to comment.