I create class test extends Generator, but gives an error message: Code: [Server thread/CRITICAL]: Error: "Class name must be a valid object or a string" (EXCEPTION) in "/src/pocketmine/Server" at line 1109 PHP: <?phpnamespace custom_gen;use pocketmine\level\generator\Generator;use pocketmine\plugin\PluginBase;class main extends PluginBase{ public function onLoad() { Generator::addGenerator(test::class, test::NAME); $this->getServer()->generateLevel('test', null, \custom_gen\test::class, []); //this not works }}
Why would it work if test::class is not an object? If you have made a test class, add a use statement for it.
the last [] is unneeded https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Server.php#L992
This should work: PHP: <?phpnamespace custom_gen;use pocketmine\level\generator\Generator;use pocketmine\plugin\PluginBase;class main extends PluginBase { public function onLoad() { Generator::addGenerator(test::class, "Test"); $this->getServer()->generateLevel("Test", null, test::class); }}
Well that makes no difference You need to pass a string not a class as the generator https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Server.php#L1003 http://php.net/manual/en/function.class-exists.php