Esempio n. 1
0
 public function onCommand(CommandSender $i, Command $cmd, $label, array $sub)
 {
     $output = "[WorldEditor]";
     if (!$i instanceof Player) {
         return true;
     }
     switch ($cmd->getName()) {
         case "/pos1":
             $pos = $i->floor();
             self::$pos[$i->getName()][0] = $pos;
             $output .= "Pos1 지점을 선택했어요 ({$pos->x}, {$pos->y}, {$pos->z})";
             break;
         case "/pos2":
             $pos = $i->floor();
             self::$pos[$i->getName()][1] = $pos;
             $output .= "Pos2 지점을 선택했어요 ({$pos->x}, {$pos->y}, {$pos->z})";
             break;
         case "/set":
             if (!isset($sub[0])) {
                 $output .= "사용법: //set <id[:meta]>";
                 break;
             }
             if (!isset(self::$pos[$i->getName()]) or count(self::$pos[$i->getName()]) < 2) {
                 $output .= "지역을 먼저 설정해주세요";
                 break;
             }
             $set = explode(":", $sub[0]);
             $block = self::$pos[$i->getName()];
             $endX = max($block[0]->x, $block[1]->x);
             $endY = max($block[0]->y, $block[1]->y);
             $endZ = max($block[0]->z, $block[1]->z);
             $startX = min($block[0]->x, $block[1]->x);
             $startY = min($block[0]->y, $block[1]->y);
             $startZ = min($block[0]->z, $block[1]->z);
             $output .= "블럭 설정을 시작했어요";
             if ($this->getData("debug", false)) {
                 self::core()->getLogger()->info("[WorldEditor]{$i->getName()}님이 블럭설정을 시작했어요");
             }
             $callback = "setBlock";
             $params = [$startX, $startY, $startZ, $endX, $endY, $endZ, Block::get($set[0], isset($set[1]) ? $set[1] : 0, $i->getPosition()), $i];
             break;
         case "/replace":
             if (!isset($sub[0]) or !isset($sub[1])) {
                 $output .= "사용법: //replace <(선택)id[:meta]> <(바꿀)id[:meta>]";
                 break;
             }
             if (!isset(self::$pos[$i->getName()]) or count(self::$pos[$i->getName()]) < 2) {
                 $output .= "지역을 먼저 설정해주세요";
                 break;
             }
             $get = explode(":", $sub[0]);
             $set = explode(":", $sub[1]);
             $block = self::$pos[$i->getName()];
             $endX = max($block[0]->x, $block[1]->x);
             $endY = max($block[0]->y, $block[1]->y);
             $endZ = max($block[0]->z, $block[1]->z);
             $startX = min($block[0]->x, $block[1]->x);
             $startY = min($block[0]->y, $block[1]->y);
             $startZ = min($block[0]->z, $block[1]->z);
             $output .= "블럭 변경을 시작했어요";
             if ($this->getData("debug", false)) {
                 self::core()->getLogger()->info("[WorldEditor]{$i->getName()}님이 블럭변경을 시작했어요");
             }
             $callback = "replaceBlock";
             $params = [$startX, $startY, $startZ, $endX, $endY, $endZ, Block::get($get[0], isset($get[1]) ? $get[1] : 0, $i->getPosition()), Block::get($set[0], isset($set[1]) ? $set[1] : 0, $i->getPosition()), $i];
             break;
         case "/undo":
             if (!isset(self::$pos[$i->getName()]) or count(self::$pos[$i->getName()]) < 2) {
                 $output .= "지역을 먼저 설정해주세요";
                 break;
             }
             $block = self::$pos[$i->getName()];
             $endX = max($block[0]->x, $block[1]->x);
             $endY = max($block[0]->y, $block[1]->y);
             $endZ = max($block[0]->z, $block[1]->z);
             $startX = min($block[0]->x, $block[1]->x);
             $startY = min($block[0]->y, $block[1]->y);
             $startZ = min($block[0]->z, $block[1]->z);
             $output .= "블럭을 되돌리는 중입니다";
             if ($this->getData("debug", false)) {
                 self::core()->getLogger()->info("[WorldEditor]{$i->getName()}님이 블럭을 복구하기 시작했어요");
             }
             $callback = "undoBlock";
             $params = [$startX, $startY, $startZ, $endX, $endY, $endZ, $i];
             break;
         case "/redo":
             if (!isset(self::$pos[$i->getName()]) or count(self::$pos[$i->getName()]) < 2) {
                 $output .= "지역을 먼저 설정해주세요";
                 break;
             }
             $block = self::$pos[$i->getName()];
             $endX = max($block[0]->x, $block[1]->x);
             $endY = max($block[0]->y, $block[1]->y);
             $endZ = max($block[0]->z, $block[1]->z);
             $startX = min($block[0]->x, $block[1]->x);
             $startY = min($block[0]->y, $block[1]->y);
             $startZ = min($block[0]->z, $block[1]->z);
             $output .= "블럭 설정을 시작했어요";
             if ($this->getData("debug", false)) {
                 self::core()->getLogger()->info("[WorldEditor]{$i->getName()}님이 복구한 블럭을 되돌리기 시작했어요");
             }
             $callback = "redoBlock";
             $params = [$startX, $startY, $startZ, $endX, $endY, $endZ, $i];
             break;
         case "/copy":
             if (!isset(self::$pos[$i->getName()]) or count(self::$pos[$i->getName()]) < 2) {
                 $output .= "지역을 먼저 설정해주세요";
                 break;
             }
             $block = self::$pos[$i->getName()];
             $endX = max($block[0]->x, $block[1]->x);
             $endY = max($block[0]->y, $block[1]->y);
             $endZ = max($block[0]->z, $block[1]->z);
             $startX = min($block[0]->x, $block[1]->x);
             $startY = min($block[0]->y, $block[1]->y);
             $startZ = min($block[0]->z, $block[1]->z);
             $output .= "블럭 복사를 시작했어요";
             if ($this->getData("debug", false)) {
                 self::core()->getLogger()->info("[WorldEditor]{$i->getName()}님이 블럭 복사를 시작했어요");
             }
             $this->copyBlock($startX, $startY, $startZ, $endX, $endY, $endZ, $i);
             break;
         case "/paste":
             $output .= "블럭 붙여넣기를 시작했어요";
             if ($this->getData("debug", false)) {
                 self::core()->getLogger()->info("[WorldEditor]{$i->getName()}님이 블럭 붙여넣기를 시작했어요");
             }
             $callback = "pasteBlock";
             $params = [$i->floor(), $i];
             break;
         case "/cut":
             if (!isset(self::$pos[$i->getName()]) or count(self::$pos[$i->getName()]) < 2) {
                 $output .= "지역을 먼저 설정해주세요";
                 break;
             }
             $block = self::$pos[$i->getName()];
             $endX = max($block[0]->x, $block[1]->x);
             $endY = max($block[0]->y, $block[1]->y);
             $endZ = max($block[0]->z, $block[1]->z);
             $startX = min($block[0]->x, $block[1]->x);
             $startY = min($block[0]->y, $block[1]->y);
             $startZ = min($block[0]->z, $block[1]->z);
             $output .= "블럭 복사를 시작했어요";
             if ($this->getData("debug", false)) {
                 self::core()->getLogger()->info("[WorldEditor]{$i->getName()}님이 블럭 복사를 시작했어요");
             }
             $callback = "cutBlock";
             $params = [$startX, $startY, $startZ, $endX, $endY, $endZ, $i];
             break;
     }
     if ($output !== "[WorldEditor]") {
         $i->sendMessage($output);
     }
     if (isset($callback) && isset($params) && is_array($params)) {
         $this->{$callback}(...$params);
     }
     return true;
 }