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); }
public function generateFile() { $file = new ClassGenerator($this->project->namespace, $this->getClassName()); $file->addImport($this->project->namespace . "\\resources\\GeneratedPluginCommandAbstract"); $file->setSuperClass("GeneratedPluginCommandAbstract"); $__construct = new GeneratedFunctionContainer(); $__construct->name = "__construct"; $file->addImport($this->project->namespace . "\\MainClass"); $__construct->params = ['MainClass $main']; $__construct->code = "parent::__construct({$this->ex($this->name)}, {$this->ex($this->desc)}, {$this->ex($this->usage)}, {$this->ex($this->aliases)}, {$this->ex($this->permission)}, \$main);"; $file->addFunction($__construct); $e = new GeneratedFunctionContainer(); $e->name = "e"; $e->params = ['CommandSender $sender', '$args']; $e->code = $this->executor->exportExecuteFunction(); $file->addFunction($e); return $file; }
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); }