-
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.
Finish listing installed plugins command
- Loading branch information
toby7002
committed
Oct 19, 2023
1 parent
e84c0f6
commit 9d3ce90
Showing
6 changed files
with
191 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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\cache; | ||
|
||
use function count; | ||
use function sort; | ||
|
||
class InstalledPluginCache | ||
{ | ||
public function __construct(private string $name, private string $version, private string $description) | ||
{ | ||
} | ||
|
||
public function getName() : string { | ||
return $this->name; | ||
} | ||
|
||
public function getVersion() : string { | ||
return $this->version; | ||
} | ||
|
||
public function getDescription(): string { | ||
return $this->description; | ||
} | ||
} |
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,54 @@ | ||
<?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\cache; | ||
|
||
use Generator; | ||
use SplObjectStorage; | ||
|
||
final class InstalledPluginsPool { | ||
/** @var ?SplObjectStorage<InstalledPluginCache, mixed> $storage */ | ||
private static ?SplObjectStorage $storage = null; | ||
|
||
/** | ||
* @return SplObjectStorage<InstalledPluginCache, mixed> | ||
*/ | ||
public static function getStorage() : SplObjectStorage{ | ||
if(self::$storage === null){ | ||
self::$storage = new SplObjectStorage(); /** @phpstan-ignore-line */ | ||
} | ||
|
||
return self::$storage; /** @phpstan-ignore-line */ | ||
} | ||
|
||
/** | ||
* @param SplObjectStorage<InstalledPluginCache, mixed> $storage | ||
*/ | ||
public static function setStorage(SplObjectStorage $storage) : void{ | ||
self::$storage = $storage; | ||
} | ||
|
||
public static function add(InstalledPluginCache $pluginCache) : void { | ||
self::getStorage()->attach($pluginCache); | ||
} | ||
|
||
/** | ||
* @param InstalledPluginCache[] $array | ||
*/ | ||
public static function addMultiple(array $array) : void { | ||
foreach ($array as $plugin) { | ||
if ($plugin instanceof InstalledPluginCache) { | ||
self::getStorage()->attach($plugin); | ||
} | ||
} | ||
} | ||
|
||
} |
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,51 @@ | ||
<?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; | ||
|
||
use pocketmine\utils\InternetException; | ||
use thebigcrafter\Iodine\Future; | ||
use thebigcrafter\Iodine\Iodine; | ||
use thebigcrafter\omp\cache\InstalledPluginCache; | ||
use thebigcrafter\omp\cache\InstalledPluginsPool; | ||
use thebigcrafter\omp\cache\PluginCache; | ||
use thebigcrafter\omp\cache\PluginsPool; | ||
use thebigcrafter\omp\cache\PluginVersion; | ||
use thebigcrafter\omp\OhMyPMMP; | ||
use thebigcrafter\omp\utils\Internet; | ||
use thebigcrafter\omp\Vars; | ||
use function array_merge; | ||
use function count; | ||
use function json_decode; | ||
use function sort; | ||
|
||
class CacheInstalledPlugins | ||
{ | ||
public static function run() : Future { | ||
return Iodine::async(function() { | ||
$plugins = OhMyPMMP::getInstance()->getServer()->getPluginManager()->getPlugins(); | ||
|
||
sort($plugins); | ||
$pluginCaches = []; | ||
|
||
foreach ($plugins as $plugin) { | ||
$name = $plugin->getName(); | ||
$version = $plugin->getDescription()->getVersion(); | ||
$description = $plugin->getDescription()->getDescription(); | ||
// TODO: Deps | ||
$pluginCaches[] = new InstalledPluginCache($name, $version, $description); | ||
} | ||
|
||
InstalledPluginsPool::addMultiple($pluginCaches); | ||
OhMyPMMP::getInstance()->getLogger()->info(OhMyPMMP::getLanguage()->translate("text.cache.installed.successfully", ["count" => count($pluginCaches)])); | ||
}); | ||
} | ||
} |