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

Plugin that does not load.

Discussion in 'Development' started by ZakousseMC, Dec 19, 2016.

  1. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Hi,

    I recently started PocketMine-MP plugin developpement but I can't figure out with this plugin does not load when the server starts, here's the code :

    PHP:
    class Main extends PluginBase{

        public function 
    onEnable()
        {
          @
    mkdir($this->saveDefaultConfig());
          
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
     
    Last edited: Dec 19, 2016
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    [PHP]Your Code[/PHP]
     
  3. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Oh, thanks !
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    "Does not load" can mean a lot. What exactly happens on console? Any error messages or anything uncommon? Also, what about other files like plugin.yml etc.?
     
    InspectorGadget likes this.
  5. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Plugin.yml should be accurate to prevent this from happening!
     
  6. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Plugin.yml folder is fine (I think, no error message mention it) I think the problem is in the Main.php folder (the one showed on the topic), only message shown in the console is " Coudn't load AFKCommand"

    (AFK Command) is the name of my plugin

    Can anyone tell me if there is a problem in the "onEnable" part
     
  7. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    You forgot the "use" statements on top of your code
     
  8. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Folder? Plugin.yml is a normal file. If there's an issue with plugin.yml, you server wouldn't tell the error. It wouldn't load either.
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    showing full code and plugin.yml helps
     
    Palente and HimbeersaftLP like this.
  10. kaliiks

    kaliiks Zombie

    Messages:
    250
    Have u Main.php in src file?:D
     
  11. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Not a folder, I mean a text
     
  12. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Yes
     
  13. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Here is the full code of :

    Main.php:

    PHP:
    <?php

    namespace: Main;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase{

        public function 
    onEnable()
        {
          @
    mkdir($this->saveDefaultConfig());
          
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        public function 
    translateColors($symbol$message){
     
            
    $message str_replace($symbol."0"TextFormat::BLACK$message);
            
    $message str_replace($symbol."1"TextFormat::DARK_BLUE$message);
            
    $message str_replace($symbol."2"TextFormat::DARK_GREEN$message);
            
    $message str_replace($symbol."3"TextFormat::DARK_AQUA$message);
            
    $message str_replace($symbol."4"TextFormat::DARK_RED$message);
            
    $message str_replace($symbol."5"TextFormat::DARK_PURPLE$message);
            
    $message str_replace($symbol."6"TextFormat::GOLD$message);
            
    $message str_replace($symbol."7"TextFormat::GRAY$message);
            
    $message str_replace($symbol."8"TextFormat::DARK_GRAY$message);
            
    $message str_replace($symbol."9"TextFormat::BLUE$message);
            
    $message str_replace($symbol."a"TextFormat::GREEN$message);
            
    $message str_replace($symbol."b"TextFormat::AQUA$message);
            
    $message str_replace($symbol."c"TextFormat::RED$message);
            
    $message str_replace($symbol."d"TextFormat::LIGHT_PURPLE$message);
            
    $message str_replace($symbol."e"TextFormat::YELLOW$message);
            
    $message str_replace($symbol."f"TextFormat::WHITE$message);
     
            
    $message str_replace($symbol."k"TextFormat::OBFUSCATED$message);
            
    $message str_replace($symbol."l"TextFormat::BOLD$message);
            
    $message str_replace($symbol."m"TextFormat::STRIKETHROUGH$message);
            
    $message str_replace($symbol."n"TextFormat::UNDERLINE$message);
            
    $message str_replace($symbol."o"TextFormat::ITALIC$message);
            
    $message str_replace($symbol."r"TextFormat::RESET$message);
     
            return 
    $message;
        }
            
    // Acces aux permissions.
        
    private function access(CommandSender $sender$permission) {
            if(
    $sender->hasPermission($permission)) return true;
            
    $sender->sendMessage("Vous n'avez pas la permission d'utiliser cette commande.");
            return 
    false;
        }
        private function 
    inGame(CommandSender $sender,$msg true) {
            if (
    $sender instanceof Player) return true;
            if (
    $msg$sender->sendMessage("Vous pouvez seulement utiliser cette commande en jeu.");
            return 
    false;
        }
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args)
        {
            if(
    count($args) < 0)
            {
                
    $sender->sendMessage(TextFormat::GREEN). " Vous etes desormais AFK.");
        }
    plugin.yml:
    PHP:
    nameAFKCommand
    main
    src/Main
    version
    1.0.0
    api
    2.0.0
    description
    Adds an /afk command that let you /afkThis is my first plugin.
    websitehttps://darknightpe.com
    authorZakousseMC
    commands
    :
     
    afk:
      
    descriptionVous rendre AFK.
      
    usage"/afk"
      
    permissionafk.command.afk
     
    permissions
    :
     
    afk:
      default: 
    op
      description
    "Vous laisse utiliser toutes les commandes que le plugin a."
      
    children:
       
    afk.command:
       
    description"Vous laisse utiliser la commande /afk"
       
    default: true
     
  14. kaliiks

    kaliiks Zombie

    Messages:
    250
    in plugin .yml do not use src/... create one file in src and put main.php to it and in plugin.yml use main: FileNameWhatIsInSrc/Main
     
    SOFe likes this.
  15. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Does not work

    PHP:
    nameAFKCommand
    main
    ZakousseMC/Main
    version
    1.0.0
    api
    2.0.0
    description
    Adds an /afk command that let you /afkThis is my first plugin.
    websitehttps://darknightpe.com
    authorZakousseMC
    commands
    :
     
    afk:
      
    descriptionVous rendre AFK.
      
    usage"/afk"
      
    permissionafk.command.afk
     
    permissions
    :
     
    afk:
      default: 
    op
      description
    "Vous laisse utiliser toutes les commandes que le plugin a."
      
    children:
       
    afk.command:
       
    description"Vous laisse utiliser la commande /afk"
       
    default: true
     
  16. imYannic

    imYannic Baby Zombie

    Messages:
    113
    It is namespace Main;
    Not namespace: Main;
     
    TheDragonRing likes this.
  17. TheDragonRing

    TheDragonRing Witch

    Messages:
    64
    GitHub:
    dragonwocky
    Also, in the plugin.yml 1 thing is wrong.
    Code:
    
    main: ZakousseMC/Main //you use a backslash here, not a normal one. Simply change it to:
    main: ZakousseMC\Main
    Other developers, please tell me if there's anything I've done wrong or missed!
     
    Last edited: Dec 22, 2016
  18. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I'm very sure that API 2.1.0 still supports API 2.0.0. It wouldn't make any difference if you have your API to 2.1.0 or 2.0.0
     
  19. Wii54

    Wii54 Silverfish

    Messages:
    16
    GitHub:
    wii54
    Where do you want to generate your config file? If you want it in the AFKCommand folder in plugins folder, you should just use the code below.
    PHP:
    @mkdir($this->getDataFolder());
    $this->saveDefaultConfig();
    $this->reloadConfig();
    Also, you need to create a resources folder in the same directory as your src folder. In the resources folder, create a config.yml file
     
  20. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Why is this happenning ?

    PHP:
    <?php

    namespace Main;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;

    class 
    ZakousseMC extends PluginBase{

        public function 
    onEnable()
        {
         @
    mkdir($this->getDataFolder());
        
    $this->saveDefaultConfig();
        
    $this->reloadConfig();
        }
        public function 
    translateColors($symbol$message){
       
            
    $message str_replace($symbol."0"TextFormat::BLACK$message);
            
    $message str_replace($symbol."1"TextFormat::DARK_BLUE$message);
            
    $message str_replace($symbol."2"TextFormat::DARK_GREEN$message);
            
    $message str_replace($symbol."3"TextFormat::DARK_AQUA$message);
            
    $message str_replace($symbol."4"TextFormat::DARK_RED$message);
            
    $message str_replace($symbol."5"TextFormat::DARK_PURPLE$message);
            
    $message str_replace($symbol."6"TextFormat::GOLD$message);
            
    $message str_replace($symbol."7"TextFormat::GRAY$message);
            
    $message str_replace($symbol."8"TextFormat::DARK_GRAY$message);
            
    $message str_replace($symbol."9"TextFormat::BLUE$message);
            
    $message str_replace($symbol."a"TextFormat::GREEN$message);
            
    $message str_replace($symbol."b"TextFormat::AQUA$message);
            
    $message str_replace($symbol."c"TextFormat::RED$message);
            
    $message str_replace($symbol."d"TextFormat::LIGHT_PURPLE$message);
            
    $message str_replace($symbol."e"TextFormat::YELLOW$message);
            
    $message str_replace($symbol."f"TextFormat::WHITE$message);
       
            
    $message str_replace($symbol."k"TextFormat::OBFUSCATED$message);
            
    $message str_replace($symbol."l"TextFormat::BOLD$message);
            
    $message str_replace($symbol."m"TextFormat::STRIKETHROUGH$message);
            
    $message str_replace($symbol."n"TextFormat::UNDERLINE$message);
            
    $message str_replace($symbol."o"TextFormat::ITALIC$message);
            
    $message str_replace($symbol."r"TextFormat::RESET$message);
       
            return 
    $message;
        }
            
    // Acces aux permissions.
        
    private function access(CommandSender $sender$permission) {
            if(
    $sender->hasPermission($permission)) return true;
            
    $sender->sendMessage("Vous n'avez pas la permission d'utiliser cette commande.");
            return 
    false;
        }
        private function 
    inGame(CommandSender $sender,$msg true) {
            if (
    $sender instanceof Player) return true;
            if (
    $msg$sender->sendMessage("Vous pouvez seulement utiliser cette commande en jeu.");
            return 
    false;
        }
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            if(
    count($args) < 0)
            
    $sender->sendMessage(TextFormat::GREEN)("Vous etes desormais AFK.");
            return 
    false;
        }
       
    }
    ?>   

    Screenshot_1.jpg
     
  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.