Example #1
0
 private function generateMainClass()
 {
     $class = new ClassGenerator($this->project->namespace, "MainClass");
     $class->addImport("pocketmine\\plugin\\PluginBase");
     $class->setSuperClass("PluginBase");
     $onEnable = new GeneratedFunctionContainer();
     $onEnable->name = "onEnable";
     foreach ($this->project->cmds as $cmd) {
         $pluginName = strtolower(str_replace([":", " "], "-", $this->project->getDesc()->getName()));
         $onEnable->code .= '$this->getServer()->getCommandMap()->register(' . var_export($pluginName, true) . ', new cmds\\' . $cmd->getClassName() . '($this)); // this line registers the command /' . str_replace(["\r", "\n"], "<br>", $cmd->name);
     }
     $class->addFunction($onEnable);
     $this->addFile("src/" . $this->project->namespace . "/MainClass.php", $class);
 }
 private function generateMainClass()
 {
     $class = new ClassGenerator($this->project->namespace, "MainClass");
     $class->addImport("pocketmine\\plugin\\PluginBase");
     $class->addImport("pocketmine\\utils\\TextFormat");
     $class->setSuperClass("PluginBase");
     $onEnable = new GeneratedFunctionContainer();
     $onEnable->name = "onEnable";
     $onEnable->code .= '$this->getLogger()->info(TextFormat::YELLOW . "This plugin is auto-generated by http://pmt.mcpe.me/pg, an online tool written by PEMapModder. Use at your own risk. If this plugin misbehaves, the user should bear his/her own responsibilities.");' . ClassGenerator::STANDARD_EOL;
     foreach ($this->project->cmds as $cmd) {
         $pluginName = strtolower(str_replace([":", " "], "-", $this->project->getDesc()->getName()));
         $onEnable->code .= '$this->getServer()->getCommandMap()->register(' . beautified_var_export($pluginName, true) . ', new cmds\\' . $cmd->getClassName() . '($this)); // this line registers the command /' . str_replace(["\r", "\n"], "<br>", $cmd->name) . ClassGenerator::STANDARD_EOL;
     }
     if (count($this->project->events) > 0) {
         $onEnable->code .= '$this->getServer()->getPluginManager()->registerEvents(new EventHandler($this), $this);' . ClassGenerator::STANDARD_EOL;
     }
     $class->addFunction($onEnable);
     $this->addFile("src/" . $this->project->namespace . "/MainClass.php", $class);
 }