48    private bool $isEnabled = 
false;
 
   50    private string $resourceFolder;
 
   52    private ?
Config $config = 
null;
 
   53    private string $configFile;
 
   58    public function __construct(
 
   62        private string $dataFolder,
 
   66        $this->dataFolder = rtrim($dataFolder, 
"/" . DIRECTORY_SEPARATOR) . 
"/";
 
   68        $this->file = rtrim($file, 
"/" . DIRECTORY_SEPARATOR) . 
"/";
 
   69        $this->resourceFolder = Path::join($this->file, 
"resources") . 
"/";
 
   71        $this->configFile = Path::join($this->dataFolder, 
"config.yml");
 
   73        $prefix = $this->description->getPrefix();
 
   74        $this->logger = 
new PluginLogger($server->getLogger(), $prefix !== 
"" ? $prefix : $this->getName());
 
   79        $this->registerYamlCommands();
 
  104    final public function isEnabled() : bool{
 
  105        return $this->isEnabled;
 
  116        if($this->isEnabled !== $enabled){
 
  117            $this->isEnabled = $enabled;
 
  118            if($this->isEnabled){
 
 
  126    final public function isDisabled() : bool{
 
  127        return !$this->isEnabled;
 
  131        return $this->dataFolder;
 
 
  135        return $this->description;
 
  139        return $this->logger;
 
  145    private function registerYamlCommands() : void{
 
  148        foreach(Utils::stringifyKeys($this->description->getCommands()) as $key => $data){
 
  149            if(str_contains($key, 
":")){
 
  150                $this->logger->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_commandError($key, $this->description->getFullName(), 
":")));
 
  154            $newCmd = 
new PluginCommand($key, $this, $this);
 
  155            if(($description = $data->getDescription()) !== 
null){
 
  156                $newCmd->setDescription($description);
 
  159            if(($usageMessage = $data->getUsageMessage()) !== 
null){
 
  160                $newCmd->setUsage($usageMessage);
 
  164            foreach($data->getAliases() as $alias){
 
  165                if(str_contains($alias, 
":")){
 
  166                    $this->logger->error($this->
server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_aliasError($alias, $this->description->getFullName(), 
":")));
 
  169                $aliasList[] = $alias;
 
  172            $newCmd->setAliases($aliasList);
 
  174            $newCmd->setPermission($data->getPermission());
 
  176            if(($permissionDeniedMessage = $data->getPermissionDeniedMessage()) !== 
null){
 
  177                $newCmd->setPermissionMessage($permissionDeniedMessage);
 
  180            $pluginCmds[] = $newCmd;
 
  183        if(count($pluginCmds) > 0){
 
  184            $this->
server->getCommandMap()->registerAll($this->description->getName(), $pluginCmds);
 
  193        $command = $this->
server->getPluginCommand($name);
 
  194        if($command === 
null || $command->getOwningPlugin() !== $this){
 
  195            $command = $this->
server->getPluginCommand(strtolower($this->description->getName()) . 
":" . $name);
 
  198        if($command instanceof 
PluginOwned && $command->getOwningPlugin() === $this){
 
 
  217        return $this->resourceFolder;
 
 
  227        return Path::join($this->getResourceFolder(), $filename);
 
 
  240        return $this->resourceProvider->getResource($filename);
 
 
  246    public function saveResource(
string $filename, 
bool $replace = 
false) : bool{
 
  247        if(trim($filename) === 
""){
 
  251        $source = Path::join($this->resourceFolder, $filename);
 
  252        if(!file_exists($source)){
 
  256        $destination = Path::join($this->dataFolder, $filename);
 
  257        if(file_exists($destination) && !$replace){
 
  261        if(!file_exists(dirname($destination))){
 
  262            mkdir(dirname($destination), 0755, 
true);
 
  265        return copy($source, $destination);
 
 
  274        return $this->resourceProvider->getResources();
 
 
  277    public function getConfig() : 
Config{
 
  278        if($this->config === null){
 
  279            $this->reloadConfig();
 
  282        return $this->config;
 
  285    public function saveConfig() : void{
 
  286        $this->getConfig()->save();
 
  289    public function saveDefaultConfig() : bool{
 
  290        if(!file_exists($this->configFile)){
 
  291            return $this->saveResource(
"config.yml", 
false);
 
  296    public function reloadConfig() : void{
 
  297        $this->saveDefaultConfig();
 
  298        $this->config = 
new Config($this->configFile);
 
  301    final public function getServer() : Server{
 
  305    final public function getName() : string{
 
  306        return $this->description->getName();
 
  309    final public function getFullName() : string{
 
  310        return $this->description->getFullName();
 
  313    protected function getFile() : string{
 
  317    public function getPluginLoader() : PluginLoader{
 
  318        return $this->loader;
 
  321    public function getScheduler() : TaskScheduler{
 
  322        return $this->scheduler;