PocketMine-MP 5.37.2 git-aa47b7cd412ddb171ec53c035c2bbe84199be285
Loading...
Searching...
No Matches
ScriptPluginLoader.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\plugin;
25
27use function count;
28use function file;
29use function implode;
30use function is_file;
31use function pathinfo;
32use function str_contains;
33use function str_ends_with;
34use const FILE_IGNORE_NEW_LINES;
35use const FILE_SKIP_EMPTY_LINES;
36use const PATHINFO_FILENAME;
37
43
44 public const AUTOGENERATED_NAME_PREFIX = "ScriptPlugin_";
45
46 public function canLoadPlugin(string $path) : bool{
47 return is_file($path) && str_ends_with($path, ".php");
48 }
49
53 public function loadPlugin(string $path, PluginDescription $description) : void{
54 include_once $path;
55 }
56
60 public function getPluginDescription(string $path) : ?PluginDescription{
61 $content = @file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
62 if($content === false){
63 return null;
64 }
65
66 $insideHeader = false;
67
68 $docCommentLines = [];
69 foreach($content as $line){
70 if(!$insideHeader){
71 if(str_contains($line, "/**")){
72 $insideHeader = true;
73 }else{
74 continue;
75 }
76 }
77
78 $docCommentLines[] = $line;
79
80 if(str_contains($line, "*/")){
81 break;
82 }
83 }
84
85 $data = Utils::parseDocComment(implode("\n", $docCommentLines));
86 if(count($data) !== 0){
87 $data["version"] ??= "1.0.0";
88 $data["name"] ??= self::AUTOGENERATED_NAME_PREFIX . pathinfo($path, PATHINFO_FILENAME);
89 return new PluginDescription($data);
90 }
91
92 return null;
93 }
94
95 public function getAccessProtocol() : string{
96 return "";
97 }
98}
loadPlugin(string $path, PluginDescription $description)