1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Error: "Class name must be a valid object or a string" When Generating a New Level

Discussion in 'Plugin Help' started by CortexPE, Oct 23, 2017.

  1. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    Whenever I try to generate a level with a plugin:
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    CortexPE;

    use 
    pocketmine\level\generator\Generator;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase {
        public function 
    onLoad(){
           
    $this->generateLevels();
        }

        public function 
    generateLevels(){
           
    $this->getServer()->generateLevel("test"nullGenerator::getGenerator("FLAT"));
        }
    }
    I only get this error:
    Code:
    [08:33:36] [Server thread/ERROR]: pocketmine.level.generateError
    [08:33:36] [Server thread/CRITICAL]: Error: "Class name must be a valid object or a string" (EXCEPTION) in "src/pocketmine/Server" at line 1076
    [08:33:36] [Server thread/DEBUG]: #0 plugins/TESTERPLUGIN/src/CortexPE/Main(17): pocketmine\Server->generateLevel(string test, integer -613950673, string pocketmine\level\generator\normal\Normal)
    [08:33:36] [Server thread/DEBUG]: #1 plugins/TESTERPLUGIN/src/CortexPE/Main(13): CortexPE\Main->generateLevels()
    [08:33:36] [Server thread/DEBUG]: #2 plugins/DevTools.phar/src/FolderPluginLoader/FolderPluginLoader(115): CortexPE\Main->onLoad()
    [08:33:36] [Server thread/DEBUG]: #3 plugins/DevTools.phar/src/FolderPluginLoader/FolderPluginLoader(66): FolderPluginLoader\FolderPluginLoader->initPlugin(CortexPE\Main object, pocketmine\plugin\PluginDescription object, string C:\Users\CortexPE\Desktop\MCPE Server Softwares\PocketMine-MP\plugins\TESTERPLUGIN, string C:\Users\CortexPE\Desktop\MCPE Server Softwares\PocketMine-MP\plugins\TESTERPLUGIN)
    [08:33:36] [Server thread/DEBUG]: #4 src/pocketmine/plugin/PluginManager(161): FolderPluginLoader\FolderPluginLoader->loadPlugin(string C:\Users\CortexPE\Desktop\MCPE Server Softwares\PocketMine-MP\plugins\TESTERPLUGIN)
    [08:33:36] [Server thread/DEBUG]: #5 src/pocketmine/plugin/PluginManager(305): pocketmine\plugin\PluginManager->loadPlugin(string C:\Users\CortexPE\Desktop\MCPE Server Softwares\PocketMine-MP\plugins\TESTERPLUGIN, array Array())
    [08:33:36] [Server thread/DEBUG]: #6 plugins/DevTools.phar/src/DevTools/DevTools(47): pocketmine\plugin\PluginManager->loadPlugins(string C:\Users\CortexPE\Desktop\MCPE Server Softwares\PocketMine-MP\plugins\, array Array())
    [08:33:36] [Server thread/DEBUG]: #7 src/pocketmine/plugin/PluginBase(90): DevTools\DevTools->onEnable()
    [08:33:36] [Server thread/DEBUG]: #8 src/pocketmine/plugin/PharPluginLoader(122): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    [08:33:36] [Server thread/DEBUG]: #9 src/pocketmine/plugin/PluginManager(610): pocketmine\plugin\PharPluginLoader->enablePlugin(DevTools\DevTools object)
    [08:33:36] [Server thread/DEBUG]: #10 src/pocketmine/Server(1940): pocketmine\plugin\PluginManager->enablePlugin(DevTools\DevTools object)
    [08:33:36] [Server thread/DEBUG]: #11 src/pocketmine/Server(1926): pocketmine\Server->enablePlugin(DevTools\DevTools object)
    [08:33:36] [Server thread/DEBUG]: #12 src/pocketmine/Server(1635): pocketmine\Server->enablePlugins(integer 0)
    [08:33:36] [Server thread/DEBUG]: #13 src/pocketmine/PocketMine(558): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\CortexPE\Desktop\MCPE Server Softwares\PocketMine-MP\, string C:\Users\CortexPE\Desktop\MCPE Server Softwares\PocketMine-MP\, string C:\Users\CortexPE\Desktop\MCPE Server Softwares\PocketMine-MP\plugins\)
    Any suggestions on why the error occurs?
    I'm using PMMP's latest commit...
     
  2. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
  3. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    upload_2017-10-23_10-34-59.png
    PocketMine generated this world but it Worked...

    upload_2017-10-23_10-36-22.png
    The plugin generated one however, didn't.

    And yeah... they're the same type.
    upload_2017-10-23_10-39-37.png
     
  4. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    According to this, Generator::getGenerator() returns a Generator object, which you are passing to generateLevel(), which expects a string, a " Class name that extends pocketmine\level\generator\Noise".

    Also, check this.
     
    Last edited: Oct 23, 2017
  5. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
  6. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Maybe the PHPDocs are inaccurate? So what happens when you use "default" instead of "FLAT"?
     
    Last edited: Oct 24, 2017
  7. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    Still the same error...
     
  8. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    I just tested, it works fine in onEnable() but not in onLoad(), so you were calling it too early.
     
    Last edited: Oct 24, 2017
  9. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    Tried onEnable (Just updated a minute ago) and it still didn't work for me... SAME ERROR.

    Updated via:
    Code:
    git fetch origin && git reset --hard origin
    Using:
    Code:
    $this->getServer()->generateLevel("test", null, Generator::getGenerator("FLAT"));
    wtf.
     
  10. KnownUnown

    KnownUnown Spider Jockey Poggit Reviewer

    Messages:
    47
    GitHub:
    knownunown
    Awzaw likes this.
  11. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    It's on the default setting...
     

    Attached Files:

  12. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    Jack Noordhuis, CortexPE and Awzaw like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.