Esempio n. 1
0
 private function generateEvents()
 {
     $class = new ClassGenerator($this->project->namespace, "EventHandler");
     $class->addImport("pocketmine\\event\\Listener");
     $class->addInterface("Listener");
     $constructor = new GeneratedFunctionContainer();
     $constructor->name = "__construct";
     $constructor->params = ['MainClass $main'];
     $constructor->code = '$this->main = $main;';
     $class->addFunction($constructor);
     $class->addField(\T_PRIVATE, "main");
     $i = 0;
     foreach ($this->project->events as $event) {
         $fx = new GeneratedFunctionContainer();
         $fx->name = "h_{$i}";
         $i++;
         $class->addImport($event->eventClassName);
         $fx->params = [$event->eventName . ' $event'];
         foreach ($event->eventHandler as $stmt) {
             $fx->code .= $stmt->getPhpCode(0);
             $fx->code .= ClassGenerator::STANDARD_EOL;
         }
         $class->addFunction($fx);
     }
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
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);
 }