PocketMine-MP 5.37.4 git-07e225b0bd0d389de8a3d035fbd0ae8730a06053
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
42
43 public const AUTOGENERATED_NAME_PREFIX = "ScriptPlugin_";
44
45 public function canLoadPlugin(string $path) : bool{
46 return is_file($path) && str_ends_with($path, ".php");
47 }
48
52 public function loadPlugin(string $path, PluginDescription $description) : void{
53 include_once $path;
54 }
55
59 public function getPluginDescription(string $path) : ?PluginDescription{
60 $content = @file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
61 if($content === false){
62 return null;
63 }
64
65 $insideHeader = false;
66
67 $docCommentLines = [];
68 foreach($content as $line){
69 if(!$insideHeader){
70 if(str_contains($line, "/**")){
71 $insideHeader = true;
72 }else{
73 continue;
74 }
75 }
76
77 $docCommentLines[] = $line;
78
79 if(str_contains($line, "*/")){
80 break;
81 }
82 }
83
84 $data = Utils::parseDocComment(implode("\n", $docCommentLines));
85 if(count($data) !== 0){
86 $data["version"] ??= "1.0.0";
87 $data["name"] ??= self::AUTOGENERATED_NAME_PREFIX . pathinfo($path, PATHINFO_FILENAME);
88 return new PluginDescription($data);
89 }
90
91 return null;
92 }
93
94 public function getAccessProtocol() : string{
95 return "";
96 }
97}
loadPlugin(string $path, PluginDescription $description)