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); }
"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.?
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
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.
Here is the full code of : Main.php: PHP: <?phpnamespace: 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 $sender, Command $cmd, $label, array $args) { if(count($args) < 0) { $sender->sendMessage(TextFormat::GREEN). " Vous etes desormais AFK."); } plugin.yml: PHP: name: AFKCommandmain: src/Mainversion: 1.0.0api: 2.0.0description: Adds an /afk command that let you /afk. This is my first plugin.website: https://darknightpe.comauthor: ZakousseMCcommands: afk: description: Vous rendre AFK. usage: "/afk" permission: afk.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
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
Does not work PHP: name: AFKCommandmain: ZakousseMC/Mainversion: 1.0.0api: 2.0.0description: Adds an /afk command that let you /afk. This is my first plugin.website: https://darknightpe.comauthor: ZakousseMCcommands: afk: description: Vous rendre AFK. usage: "/afk" permission: afk.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
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!
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
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
Why is this happenning ? PHP: <?phpnamespace 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 $sender, Command $cmd, $label, array $args) { if(count($args) < 0) $sender->sendMessage(TextFormat::GREEN)("Vous etes desormais AFK."); return false; } }?>