Convert PluginLoadOrder into enum

This commit is contained in:
Dylan K. Taylor 2019-03-27 18:28:40 +00:00
parent 2091354927
commit 3de08bf452
5 changed files with 36 additions and 28 deletions

View File

@ -25,7 +25,6 @@ namespace pocketmine;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\plugin\PluginBase;
use pocketmine\plugin\PluginLoadOrder;
use pocketmine\plugin\PluginManager;
use pocketmine\utils\Utils;
use pocketmine\utils\VersionString;
@ -55,6 +54,7 @@ use function phpinfo;
use function phpversion;
use function str_split;
use function strpos;
use function strtoupper;
use function substr;
use function time;
use function zend_version;
@ -158,7 +158,7 @@ class CrashDump{
"depends" => $d->getDepend(),
"softDepends" => $d->getSoftDepend(),
"main" => $d->getMain(),
"load" => $d->getOrder() === PluginLoadOrder::POSTWORLD ? "POSTWORLD" : "STARTUP",
"load" => strtoupper($d->getOrder()->getEnumName()),
"website" => $d->getWebsite()
];
$this->addLine($d->getName() . " " . $d->getVersion() . " by " . implode(", ", $d->getAuthors()) . " for API(s) " . implode(", ", $d->getCompatibleApis()));

View File

@ -1260,7 +1260,7 @@ class Server{
$this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "update.pmmp.io"));
$this->enablePlugins(PluginLoadOrder::STARTUP);
$this->enablePlugins(PluginLoadOrder::STARTUP());
foreach((array) $this->getProperty("worlds", []) as $name => $options){
if($options === null){
@ -1313,7 +1313,7 @@ class Server{
$this->properties->save();
}
$this->enablePlugins(PluginLoadOrder::POSTWORLD);
$this->enablePlugins(PluginLoadOrder::POSTWORLD());
$this->network->registerInterface(new RakLibInterface($this));
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp(), $this->getPort()]));
@ -1559,16 +1559,16 @@ class Server{
}
/**
* @param int $type
* @param PluginLoadOrder $type
*/
public function enablePlugins(int $type) : void{
public function enablePlugins(PluginLoadOrder $type) : void{
foreach($this->pluginManager->getPlugins() as $plugin){
if(!$plugin->isEnabled() and $plugin->getDescription()->getOrder() === $type){
$this->pluginManager->enablePlugin($plugin);
}
}
if($type === PluginLoadOrder::POSTWORLD){
if($type === PluginLoadOrder::POSTWORLD()){
$this->commandMap->registerServerAliases();
DefaultPermissions::registerCorePermissions();
}

View File

@ -27,8 +27,6 @@ use pocketmine\permission\Permission;
use pocketmine\permission\PermissionParser;
use function array_map;
use function array_values;
use function constant;
use function defined;
use function extension_loaded;
use function is_array;
use function phpversion;
@ -36,7 +34,6 @@ use function preg_match;
use function str_replace;
use function stripos;
use function strlen;
use function strtoupper;
use function substr;
use function version_compare;
@ -63,7 +60,8 @@ class PluginDescription{
private $website = "";
/** @var string */
private $prefix = "";
private $order = PluginLoadOrder::POSTWORLD;
/** @var PluginLoadOrder */
private $order;
/**
* @var Permission[]
@ -129,13 +127,15 @@ class PluginDescription{
$this->prefix = (string) ($plugin["prefix"] ?? $this->prefix);
if(isset($plugin["load"])){
$order = strtoupper($plugin["load"]);
if(!defined(PluginLoadOrder::class . "::" . $order)){
throw new PluginException("Invalid PluginDescription load");
}else{
$this->order = constant(PluginLoadOrder::class . "::" . $order);
try{
$this->order = PluginLoadOrder::fromString($plugin["load"]);
}catch(\Error $e){
throw new PluginException("Invalid PluginDescription \"load\"");
}
}else{
$this->order = PluginLoadOrder::POSTWORLD();
}
$this->authors = [];
if(isset($plugin["author"])){
$this->authors[] = $plugin["author"];
@ -273,9 +273,9 @@ class PluginDescription{
}
/**
* @return int
* @return PluginLoadOrder
*/
public function getOrder() : int{
public function getOrder() : PluginLoadOrder{
return $this->order;
}

View File

@ -23,15 +23,23 @@ declare(strict_types=1);
namespace pocketmine\plugin;
use pocketmine\utils\EnumTrait;
abstract class PluginLoadOrder{
/*
* The plugin will be loaded at startup
*/
public const STARTUP = 0;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
*
* @method static self STARTUP()
* @method static self POSTWORLD()
*/
final class PluginLoadOrder{
use EnumTrait;
/*
* The plugin will be loaded after the first world has been loaded/created.
*/
public const POSTWORLD = 1;
protected static function setup() : array{
return [
new self("startup"),
new self("postworld")
];
}
}

@ -1 +1 @@
Subproject commit dafd417d0b601da926408f16a5e6fa341a54405b
Subproject commit 9a992364d4458ccf09640befeb0e991b5d67ad8a