mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-26 21:29:55 +00:00
ResourcePackManager: Remove Server constructor dependency
This commit is contained in:
parent
8f811c29d7
commit
1896576a24
@ -1635,7 +1635,7 @@ class Server{
|
|||||||
Attribute::init();
|
Attribute::init();
|
||||||
$this->craftingManager = new CraftingManager();
|
$this->craftingManager = new CraftingManager();
|
||||||
|
|
||||||
$this->resourceManager = new ResourcePackManager($this, $this->getDataPath() . "resource_packs" . DIRECTORY_SEPARATOR);
|
$this->resourceManager = new ResourcePackManager($this->getDataPath() . "resource_packs" . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
$this->pluginManager = new PluginManager($this, $this->commandMap);
|
$this->pluginManager = new PluginManager($this, $this->commandMap);
|
||||||
$this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender);
|
$this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender);
|
||||||
|
@ -24,15 +24,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\resourcepacks;
|
namespace pocketmine\resourcepacks;
|
||||||
|
|
||||||
|
|
||||||
use pocketmine\Server;
|
|
||||||
use pocketmine\utils\Config;
|
use pocketmine\utils\Config;
|
||||||
|
use pocketmine\utils\MainLogger;
|
||||||
|
|
||||||
class ResourcePackManager{
|
class ResourcePackManager{
|
||||||
|
|
||||||
/** @var Server */
|
|
||||||
private $server;
|
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $path;
|
private $path;
|
||||||
|
|
||||||
@ -46,15 +42,15 @@ class ResourcePackManager{
|
|||||||
private $uuidList = [];
|
private $uuidList = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
|
||||||
* @param string $path Path to resource-packs directory.
|
* @param string $path Path to resource-packs directory.
|
||||||
*/
|
*/
|
||||||
public function __construct(Server $server, string $path){
|
public function __construct(string $path){
|
||||||
$this->server = $server;
|
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
|
|
||||||
|
$logger = MainLogger::getLogger();
|
||||||
|
|
||||||
if(!file_exists($this->path)){
|
if(!file_exists($this->path)){
|
||||||
$this->server->getLogger()->debug("Resource packs path $path does not exist, creating directory");
|
$logger->debug("Resource packs path $path does not exist, creating directory");
|
||||||
mkdir($this->path);
|
mkdir($this->path);
|
||||||
}elseif(!is_dir($this->path)){
|
}elseif(!is_dir($this->path)){
|
||||||
throw new \InvalidArgumentException("Resource packs path $path exists and is not a directory");
|
throw new \InvalidArgumentException("Resource packs path $path exists and is not a directory");
|
||||||
@ -68,7 +64,7 @@ class ResourcePackManager{
|
|||||||
|
|
||||||
$this->serverForceResources = (bool) $resourcePacksConfig->get("force_resources", false);
|
$this->serverForceResources = (bool) $resourcePacksConfig->get("force_resources", false);
|
||||||
|
|
||||||
$this->server->getLogger()->info("Loading resource packs...");
|
$logger->info("Loading resource packs...");
|
||||||
|
|
||||||
foreach($resourcePacksConfig->get("resource_stack", []) as $pos => $pack){
|
foreach($resourcePacksConfig->get("resource_stack", []) as $pos => $pack){
|
||||||
try{
|
try{
|
||||||
@ -77,7 +73,7 @@ class ResourcePackManager{
|
|||||||
$newPack = null;
|
$newPack = null;
|
||||||
//Detect the type of resource pack.
|
//Detect the type of resource pack.
|
||||||
if(is_dir($packPath)){
|
if(is_dir($packPath)){
|
||||||
$this->server->getLogger()->warning("Skipped resource entry $pack due to directory resource packs currently unsupported");
|
$logger->warning("Skipped resource entry $pack due to directory resource packs currently unsupported");
|
||||||
}else{
|
}else{
|
||||||
$info = new \SplFileInfo($packPath);
|
$info = new \SplFileInfo($packPath);
|
||||||
switch($info->getExtension()){
|
switch($info->getExtension()){
|
||||||
@ -86,7 +82,7 @@ class ResourcePackManager{
|
|||||||
$newPack = new ZippedResourcePack($packPath);
|
$newPack = new ZippedResourcePack($packPath);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->server->getLogger()->warning("Skipped resource entry $pack due to format not recognized");
|
$logger->warning("Skipped resource entry $pack due to format not recognized");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,14 +92,14 @@ class ResourcePackManager{
|
|||||||
$this->uuidList[strtolower($newPack->getPackId())] = $newPack;
|
$this->uuidList[strtolower($newPack->getPackId())] = $newPack;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$this->server->getLogger()->warning("Skipped resource entry $pack due to file or directory not found");
|
$logger->warning("Skipped resource entry $pack due to file or directory not found");
|
||||||
}
|
}
|
||||||
}catch(\Throwable $e){
|
}catch(\Throwable $e){
|
||||||
$this->server->getLogger()->logException($e);
|
$logger->logException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getLogger()->debug("Successfully loaded " . count($this->resourcePacks) . " resource packs");
|
$logger->debug("Successfully loaded " . count($this->resourcePacks) . " resource packs");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user