|
25 | 25 | use pocketmine\utils\TextFormat;
|
26 | 26 | use function count;
|
27 | 27 | use function ctype_digit;
|
28 |
| -use function fclose; |
29 | 28 | use function file_exists;
|
| 29 | +use function file_get_contents; |
30 | 30 | use function file_put_contents;
|
31 | 31 | use function mkdir;
|
32 | 32 | use function preg_match;
|
33 | 33 | use function str_replace;
|
34 |
| -use function stream_get_contents; |
35 | 34 | use function yaml_emit;
|
36 | 35 | use const DIRECTORY_SEPARATOR;
|
37 | 36 |
|
@@ -70,36 +69,30 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
|
70 | 69 |
|
71 | 70 | mkdir($rootDirectory . $namespacePath, 0755, true); //create all the needed directories
|
72 | 71 |
|
73 |
| - $mainPhpTemplate = $this->getOwningPlugin()->getResource("plugin_skeleton/Main.php"); |
| 72 | + $mainPhpTemplate = file_get_contents($this->getOwningPlugin()->getResourcePath("plugin_skeleton/Main.php")); |
74 | 73 |
|
75 |
| - try{ |
76 |
| - if($mainPhpTemplate === null){ |
77 |
| - $sender->sendMessage(TextFormat::RED . "Error: missing template files"); |
78 |
| - return true; |
79 |
| - } |
| 74 | + if($mainPhpTemplate === false){ |
| 75 | + $sender->sendMessage(TextFormat::RED . "Error: missing template files"); |
| 76 | + return true; |
| 77 | + } |
80 | 78 |
|
81 |
| - $manifest = [ |
82 |
| - "name" => $pluginName, |
83 |
| - "version" => "0.0.1", |
84 |
| - "main" => $namespace . "\\Main", |
85 |
| - "api" => $this->getOwningPlugin()->getServer()->getApiVersion(), |
86 |
| - "src-namespace-prefix" => $namespace |
87 |
| - ]; |
| 79 | + $manifest = [ |
| 80 | + "name" => $pluginName, |
| 81 | + "version" => "0.0.1", |
| 82 | + "main" => $namespace . "\\Main", |
| 83 | + "api" => $this->getOwningPlugin()->getServer()->getApiVersion(), |
| 84 | + "src-namespace-prefix" => $namespace |
| 85 | + ]; |
88 | 86 |
|
89 |
| - file_put_contents($rootDirectory . "plugin.yml", yaml_emit($manifest)); |
| 87 | + file_put_contents($rootDirectory . "plugin.yml", yaml_emit($manifest)); |
90 | 88 |
|
91 |
| - file_put_contents($rootDirectory . $namespacePath . "Main.php", str_replace( |
92 |
| - "#%{Namespace}", "namespace " . $namespace . ";", |
93 |
| - stream_get_contents($mainPhpTemplate) |
94 |
| - )); |
| 89 | + file_put_contents($rootDirectory . $namespacePath . "Main.php", str_replace( |
| 90 | + "#%{Namespace}", "namespace " . $namespace . ";", |
| 91 | + $mainPhpTemplate |
| 92 | + )); |
95 | 93 |
|
96 |
| - $sender->sendMessage("Created skeleton plugin $pluginName in " . $rootDirectory); |
97 |
| - return true; |
98 |
| - }finally{ |
99 |
| - if($mainPhpTemplate !== null){ |
100 |
| - fclose($mainPhpTemplate); |
101 |
| - } |
102 |
| - } |
| 94 | + $sender->sendMessage("Created skeleton plugin $pluginName in " . $rootDirectory); |
| 95 | + return true; |
103 | 96 | }
|
104 | 97 |
|
105 | 98 | private static function correctNamespacePart(string $part) : string{
|
|
0 commit comments