Skip to content

Commit 73e2c96

Browse files
committed
Missed some API changes, thanks PHPStan
1 parent 9f9a63a commit 73e2c96

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed

src/commands/ExtractPluginCommand.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,14 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
6464
}
6565
$description = $plugin->getDescription();
6666

67-
if(!($plugin->getPluginLoader() instanceof PharPluginLoader)){
68-
$sender->sendMessage(TextFormat::RED . "Plugin " . $description->getName() . " is not in Phar structure.");
69-
return true;
70-
}
71-
7267
$folderPath = $this->getOwningPlugin()->getDataFolder() . DIRECTORY_SEPARATOR . $description->getName() . "_v" . $description->getVersion() . "/";
7368
if(file_exists($folderPath)){
7469
$sender->sendMessage("Plugin already exists, overwriting...");
7570
}else{
7671
@mkdir($folderPath);
7772
}
7873

79-
$reflection = new \ReflectionClass(PluginBase::class);
80-
$file = $reflection->getProperty("file");
81-
$file->setAccessible(true);
82-
$pharPath = str_replace("\\", "/", rtrim($file->getValue($plugin), "\\/"));
74+
$pharPath = str_replace("\\", "/", rtrim($plugin->getFile(), "\\/"));
8375

8476
foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($pharPath)) as $fInfo){
8577
$path = $fInfo->getPathname();

src/commands/GeneratePluginCommand.php

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
use pocketmine\utils\TextFormat;
2626
use function count;
2727
use function ctype_digit;
28-
use function fclose;
2928
use function file_exists;
29+
use function file_get_contents;
3030
use function file_put_contents;
3131
use function mkdir;
3232
use function preg_match;
3333
use function str_replace;
34-
use function stream_get_contents;
3534
use function yaml_emit;
3635
use const DIRECTORY_SEPARATOR;
3736

@@ -70,36 +69,30 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
7069

7170
mkdir($rootDirectory . $namespacePath, 0755, true); //create all the needed directories
7271

73-
$mainPhpTemplate = $this->getOwningPlugin()->getResource("plugin_skeleton/Main.php");
72+
$mainPhpTemplate = file_get_contents($this->getOwningPlugin()->getResourcePath("plugin_skeleton/Main.php"));
7473

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+
}
8078

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+
];
8886

89-
file_put_contents($rootDirectory . "plugin.yml", yaml_emit($manifest));
87+
file_put_contents($rootDirectory . "plugin.yml", yaml_emit($manifest));
9088

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+
));
9593

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;
10396
}
10497

10598
private static function correctNamespacePart(string $part) : string{

0 commit comments

Comments
 (0)