Exemple #1
0
 public function execute(Player $player)
 {
     $command = $this->compiledCommand;
     $type = $this->executionMode;
     $command = str_replace("%p", $player->getName(), $command);
     $command = str_replace("%x", $player->getX(), $command);
     $command = str_replace("%y", $player->getY(), $command);
     $command = str_replace("%z", $player->getZ(), $command);
     $command = str_replace("%l", $player->getLevel()->getName(), $command);
     $command = str_replace("%ip", $player->getAddress(), $command);
     $command = str_replace("%n", $player->getDisplayName(), $command);
     if ($type === Command::AS_OP_TYPE && $player->isOp()) {
         $type = Command::AS_PLAYER_TYPE;
     }
     switch ($type) {
         case Command::AS_CONSOLE_TYPE:
             $this->plugin->getServer()->dispatchCommand(new ConsoleCommandSender(), $command);
             break;
         case Command::AS_OP_TYPE:
             $player->setOp(true);
             $this->plugin->getServer()->dispatchCommand($player, $command);
             $player->setOp(false);
             break;
         case Command::AS_PLAYER_TYPE:
             $this->plugin->getServer()->dispatchCommand($player, $command);
             break;
     }
 }
Exemple #2
0
 public function deleteCommand($cmd)
 {
     $ret = false;
     for ($i = count($this->commands); $i >= 0; $i--) {
         if ($this->commands[$i]->getOriginalCommand() === $cmd || $this->commands[$i]->getCompiledCommand() === $cmd) {
             unset($this->commands[$i]);
             $ret = true;
         }
     }
     if ($ret) {
         $this->plugin->saveBlock($this);
     }
     return $ret;
 }
 public function checkConfig()
 {
     if ($this->version > ConfigUpdater::CONFIG_VERSION) {
         $this->tapToDo->getLogger()->warning("The config loaded is not supported. It may not function correctly. ");
     }
     while ($this->version < ConfigUpdater::CONFIG_VERSION) {
         switch ($this->version) {
             case 0:
                 $this->tapToDo->getLogger()->info("Updating config from version 0 to 1...");
                 $blocks = $this->config->getAll();
                 foreach ($blocks as $id => $block) {
                     foreach ($block["commands"] as $i => $command) {
                         if (strpos($command, "%safe") === false && strpos($command, "%op") === false) {
                             $command .= "%pow";
                         }
                         $block["commands"][$i] = str_replace("%safe", "", $command);
                     }
                     $blocks[$id] = $block;
                 }
                 unlink($this->tapToDo->getDataFolder() . "blocks.yml");
                 $this->tapToDo->saveResource("blocks.yml");
                 $this->config = new Config($this->tapToDo->getDataFolder() . "blocks.yml", Config::YAML);
                 $this->config->set("version", 1);
                 $this->config->set("blocks", $blocks);
                 $this->config->save();
                 $this->version = 1;
                 break;
         }
     }
     return $this->config;
 }