Solved main class not found

Discussion in 'Development' started by XCodeMCPE, Jan 19, 2018.

  1. XCodeMCPE

    XCodeMCPE Slime

    Messages:
    96
    GitHub:
    xcodemcpe
    Can someone help me out here? Every time I go to put my plugin on my server it keeps sending me an error saying, main class not found.

    Here's the code so far.

    PHP:
    <?php

    namespace FlyUI;

    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase as Base;
    use 
    pocketmine\utils\TextFormat as TF;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    jojoe77777\FormAPI;

    class 
    Main extends Base implements Listener{
     
        public function 
    onEnable(){
            
    $this->getLogger()->info("FlyUI Activated");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool{
            if(
    strtolower($command->getName()) == "fly"){
              if(
    $sender->hasPermission("fly.permission") || $sender->isOp()){
              }
        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool{
            
    $player $sender->getPlayer();
            switch (
    $cmd->getName()){
                case 
    "fly":
                    
    $this->mainFrom($player);
                    break;
            }
            return 
    true;
        }
        public function 
    mainFrom($player){
            
    $plugin $this->getServer()->getPluginManager();
            
    $formapi $plugin->getPlugin("FormAPI");
            
    $form $formapi->createSimpleForm(function (Player $event, array $args){
                
    $result $args[0];
                
    $player $event->getPlayer();
                if(
    $result === null){
                }
                switch(
    $result){
                    case 
    0:
                        return;
                    case 
    1:
                        
    $this->enableForm($player);
                        return;
                    case 
    2:
                        
    $this->disableForm($player);
                        return;
                }
            });
            
    $form->setTitle(TF::BOLD TF::BLACK "FlyUI Menu");
            
    $form->setContent(TF::GRAY "Enable/Disable Fly Mode!");
            
    $form->addButton(TF::GREEN "Enable");
            
    $form->addButton(TF::RED "Disable");
            
    $form->addButton(TF::WHITE "Cancel");
            
    $form->sendToPlayer($player);
        }
        public function 
    enableForm($player){
            
    $sender->setAllowFlight(true);
            
    $sender->setFlying(true);
            
    $sender->addTitle(TF::GREEN "Fly Mode Enabled");
          } 
        public function 
    disabeForm($player){
            
    $sender->setAllowFlight(false);
            
    $sender->setFlying(false);
            
    $sender->addTitle(TF::RED "Fly Mode Disabled!");
          }
        }
     
  2. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Send your plugin.yml
     
    xXNiceAssassinlo YT likes this.
  3. XCodeMCPE

    XCodeMCPE Slime

    Messages:
    96
    GitHub:
    xcodemcpe
    PHP:
    nameFlyUI-JazzyDevZ
    main
    JazzyDevZ/Main
    version
    0.0.2
    api
    : [3.0.0-ALPHA10]
    authorJazzyDevZ

    commands
    :
      
    fly:
        
    description"Sends a form to you that enables fly mode"
    permissions:
      
    fly.permission:
        default: 
    false
     
  4. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    The namespace used in your main(from your plugin.yml) differs from the one in your Main class.

    Make sure that they reflect an accurate folder structure. The only difference between your value in your Main class and your main key from your plugin.yml is that your plugin.yml contains the class name along with the folder structure, while the namespace in your Main class IS the folder structure.

    Let me give you an example.

    Say I had a source plugin labeled TestPlugin. Inside of the TestPlugin folder was a folder labeled "src" and a file labeled "plugin.yml."
    upload_2018-1-19_23-14-20.png

    Inside of the src folder there was a folder labeled "sys" and inside the sys folder contained another folder labeled "jordan."
    upload_2018-1-19_23-14-37.png
    upload_2018-1-19_23-15-6.png

    Now, inside of the jordan folder contained the Main file, which in turn contained our Main class.
    upload_2018-1-19_23-15-18.png

    I want to make sure that my plugin loads without any errors, so I'm going to make sure my namespace reflects my folder structure. So since the Main class is inside of the jordan folder and the jordan folder is located in the sys folder, I'm going to label my namespace as "sys\jordan". The best way to describe the namespace is the folders(excluding the src folder) that your PHP file is contained in. Here is what my skeleton class with my namespace would look like:
    upload_2018-1-19_23-15-29.png

    Now, the main in the plugin.yml reflects the namespace plus the class name. I'd hope you realize that when you create a PHP class, the thing that says "class YourClassNameHere" will be your class name. So for my example, Main is my class name. Make sure to NOT put the file extension in the main key contained inside of your plugin.yml. Here is what my plugin.yml looks like:
    upload_2018-1-19_23-15-54.png

    Don't worry about the values under the api key, that's just another way to do arrays.

    But if I load my plugin, you can see there's no errors and it boots correctly(assuming you have DevTools loaded) :D
    upload_2018-1-19_23-16-9.png

    I hope this resolves any issues you have, if you have any questions about namespaces, feel free to ask!
     

    Attached Files:

  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Put your plugin on GitHub and let Poggit inspect it. Detecting the main class is probably the only thing Poggit is good at :p
     
    Teamblocket likes this.
  6. XCodeMCPE

    XCodeMCPE Slime

    Messages:
    96
    GitHub:
    xcodemcpe
    Still doesn't work
     
  7. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    "namespace FlyUI;" must be "namespace JazzyDevZ.
    Make sure sure you have in your your folder plugin:
    (Folder)src -> (Folder)JazzyDevZ -> (PHP File)Main.php
    (YAML File)plugin.yml
     
  8. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    506
    GitHub:
    xXNiceYT
    Your plugin.yml must be this:
    PHP:
    nameFlyUI-JazzyDevZ
    main
    sys\jordan\Main
    version
    0.0.2
    api
    : [3.0.0-ALPHA10]
    authorJazzyDevZ

    commands
    :
      
    fly:
        
    description"Sends a form to you that enables fly mode"
    permissions:
      
    fly.permission:
        default: 
    false
     
  9. MuditIsOP

    MuditIsOP Creeper

    Messages:
    1
    Screenshot_2021-11-10-01-26-22-22.jpg Hey, I am having same error, Can you help me Screenshot_2021-11-10-01-26-41-85.jpg
    My Plugin Structure

    >MagicalSBMenu
    ___>src
    _______>MuditIsOP
    _____________>MagicalSBMenu
    ____________________>Main.php
    ___>resources
    __________>config.yml
    ___>plugin.yml
     
    Primus likes this.

Share This Page

  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.