diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 848000eeb..a3b5ad524 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1636,7 +1636,7 @@ class Server{ $this->resourceManager = new ResourcePackManager($this->getDataPath() . "resource_packs" . DIRECTORY_SEPARATOR, $this->logger); - $this->pluginManager = new PluginManager($this, $this->commandMap); + $this->pluginManager = new PluginManager($this, $this->commandMap, ((bool) $this->getProperty("plugins.legacy-data-dir", true)) ? null : $this->getDataPath() . "plugin_data" . DIRECTORY_SEPARATOR); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); $this->profilingTickRate = (float) $this->getProperty("settings.profile-report-trigger", 20); $this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader)); diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index ab9ff2df8..093e9f009 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -94,16 +94,28 @@ class PluginManager{ /** @var int */ private $eventCallDepth = 0; + /** @var string|null */ + private $pluginDataDirectory; + /** @var TimingsHandler */ public static $pluginParentTimer; /** * @param Server $server * @param SimpleCommandMap $commandMap + * @param null|string $pluginDataDirectory */ - public function __construct(Server $server, SimpleCommandMap $commandMap){ + public function __construct(Server $server, SimpleCommandMap $commandMap, ?string $pluginDataDirectory){ $this->server = $server; $this->commandMap = $commandMap; + $this->pluginDataDirectory = $pluginDataDirectory; + if($this->pluginDataDirectory !== null){ + if(!file_exists($this->pluginDataDirectory)){ + @mkdir($this->pluginDataDirectory, 0777, true); + }elseif(!is_dir($this->pluginDataDirectory)){ + throw new \RuntimeException("Plugin data path $this->pluginDataDirectory exists and is not a directory"); + } + } } /** @@ -133,6 +145,13 @@ class PluginManager{ return $this->plugins; } + private function getDataDirectory(string $pluginPath, string $pluginName) : string{ + if($this->pluginDataDirectory !== null){ + return $this->pluginDataDirectory . $pluginName; + } + return dirname($pluginPath) . DIRECTORY_SEPARATOR . $pluginName; + } + /** * @param string $path * @param PluginLoader[] $loaders @@ -152,7 +171,7 @@ class PluginManager{ return null; } - $dataFolder = dirname($path) . DIRECTORY_SEPARATOR . $description->getName(); + $dataFolder = $this->getDataDirectory($path, $description->getName()); if(file_exists($dataFolder) and !is_dir($dataFolder)){ $this->server->getLogger()->error("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory"); return null; diff --git a/src/pocketmine/resources/pocketmine.yml b/src/pocketmine/resources/pocketmine.yml index e74cd88d6..739f5194d 100644 --- a/src/pocketmine/resources/pocketmine.yml +++ b/src/pocketmine/resources/pocketmine.yml @@ -196,3 +196,9 @@ worlds: #world: # seed: 404 # generator: FLAT:2;7,59x1,3x3,2;1;decoration(treecount=80 grasscount=45) + +plugins: + #Setting this to true will cause the legacy structure to be used where plugin data is placed inside the --plugins dir. + #False will place plugin data under plugin_data under --data. + #This option exists for backwards compatibility with existing installations. + legacy-data-dir: false