private function cmdList(CommandSender $c, array $args) { $pageNumber = $this->getPageNumber($args); $signs = $this->owner->getSignCfg(); if (count($args) == 0) { $txt = [mc::n(mc::_("One LiveSign configured"), mc::_("%1% LiveSigns configured", count($signs)), count($signs))]; $cols = 8; $i = 0; foreach (array_keys($signs) as $n) { if ($i++ % $cols == 0) { $txt[] = $n; } else { $txt[count($txt) - 1] .= ", " . $n; } } return $this->paginateText($c, $pageNumber, $txt); } $txt = []; $count = 0; foreach ($args as $id) { if (!isset($signs[$id])) { $c->sendMessage(TextFormat::RED . mc::_("%1% not found", $id)); continue; } ++$count; $txt[] = TextFormat::AQUA . mc::_("LiveSign: ") . TextFormat::WHITE . $id; foreach (["type", "content"] as $tag) { if (isset($signs[$id][$tag])) { continue; } $txt[] = TextFormat::AQUA . mc::_("-Type: ") . TextFormat::RED . mc::_("*MISSING*"); } foreach ($signs[$id] as $tag => $val) { if (is_array($val)) { $txt[] = TextFormat::AQUA . "-{$tag}: "; if (self::isAssoc($val)) { foreach ($val as $j => $k) { $txt[] = TextFormat::AQUA . "- {$j}:" . TextFormat::WHITE . $k; } } else { foreach ($val as $k) { $txt[] = TextFormat::AQUA . "- -" . TextFormat::WHITE . $k; } } } else { $txt[] = TextFormat::AQUA . "-{$tag}: " . TextFormat::WHITE . $val; } } } if (count($txt) == 0) { $c->sendMessage(TextFormat::RED . mc::_("No matches")); return true; } if ($count > 1) { array_unshift($txt, mc::_("LiveSigns %1%", $count)); } return $this->paginateText($c, $pageNumber, $txt); }
public function onSCmd(CommandSender $c, $args) { if (count($args) == 0) { return false; } $scmd = strtolower(array_shift($args)); switch ($scmd) { case "ls": if (!MPMU::access($c, "floatsigns.cmd.ls")) { return true; } $pageNumber = $this->getPageNumber($args); $cfg = $this->owner->getFloats()->getCfg(); $pps = $this->owner->getFloats()->getParticles(); if (count($args)) { $level = $this->owner->getServer()->getLevelByName($n = implode(" ", $args)); if ($level == null) { $c->sendMessage(mc::_("%1% not found", $n)); return true; } } else { if (MPMU::inGame($c, false)) { $level = $c->getLevel(); } else { $level = $this->owner->getServer()->getDefaultLevel(); } } $world = $level->getName(); if (!isset($cfg[$world])) { $c->sendMessage(mc::_("No Floating Signs in %1%", $world)); return true; } $txt = [mc::n(mc::_("One configured sign in %1%", $world), mc::_("%1% configured signs in %2%", count($cfg[$world]), $world), count($cfg[$world]))]; foreach ($cfg[$world] as $id => $item) { $txt[] = TextFormat::GREEN . "- " . $id . " : " . (isset($pps[$world][$id]) ? TextFormat::BLUE . mc::_("Spawned") : TextFormat::WHITE . mc::_("N/A")); } return $this->paginateText($c, $pageNumber, $txt); case "add": if (!MPMU::access($c, "floatsigns.cmd.addrm")) { return true; } if (count($args) == 0) { return false; } if (($pl = $this->owner->getServer()->getPlayer($args[0])) !== null) { $pos = $pl; array_shift($args); } elseif (preg_match('/^(-?\\d+),(-?\\d+),(-?\\d+)$/', $args[0], $mv)) { if (MPMU::inGame($c, false)) { $level = $c->getLevel(); } else { $level = $this->owner->getServer()->getDefaultLevel(); } $pos = new Position($mv[1], $mv[2], $mv[3], $level); array_shift($args); } elseif (preg_match('/^(-?\\d+),(-?\\d+),(-?\\d+):(.+)$/', $args[0], $mv)) { $level = $this->owner->getServer()->getLevelByName($mv[4]); if ($level == null) { $c->sendMessage(mc::_("%1% not found", $mv[4])); return true; } $pos = new Position($mv[1], $mv[2], $mv[3], $level); array_shift($args); } else { if (MPMU::inGame($c, false)) { $pos = $c; } else { $c->sendMessage(mc::_("You must be in-game or specify a position")); return true; } } $text = implode(" ", $args); $cfg = $this->owner->getSignCfg(); if (!isset($cfg[$text])) { $c->sendMessage(mc::_("%1% is not a configured text id", $text)); return true; } $c->sendMessage(mc::_("Adding floating text sign")); $this->owner->getFloats()->addFloat($pos, $text, null); return true; case "rm": if (!MPMU::access($c, "floatsigns.cmd.addrm")) { return true; } if (count($args) == 0) { return false; } $cfg = $this->owner->getFloats()->getCfg(); $signs = $this->owner->getSignCfg(); if (isset($cfg[$args[0]]) && isset($signs[$args[1]])) { if (count($args) != 2) { return false; } return $this->idRm($c, $args[0], $args[1]); } if (isset($signs[$args[0]])) { if (count($args) != 1) { return false; } if (MPMU::inGame($c, false)) { $level = $c->getLevel(); } else { $level = $this->owner->getServer()->getDefaultLevel(); } return $this->idRm($c, $level->getName(), $args[0]); } if (count($args) > 2) { return false; } /* if (count($args) == 2) { if (!is_numeric($args[1])) return false; $r = array_pop($args); } else { $r = 0; }*/ if (count($args) != 1) { return false; } if (preg_match('/^(-?\\d+),(-?\\d+),(-?\\d+)$/', $args[0], $mv)) { return $this->posRm($c, new Vector3($mv[1], $mv[2], $mv[3]), null); } if (preg_match('/^(-?\\d+),(-?\\d+),(-?\\d+):(.+)$/', $args[0], $mv)) { if (!isset($cfg[$mv[4]])) { $c->sendMessage(mc::_("Unknown world %1%", $mv[4])); return true; } return $this->posRm($c, new Vector3($mv[1], $mv[2], $mv[3]), $mv[4]); } if (($pl = $this->owner->getServer()->getPlayer($args[0])) !== null) { return $this->posRm($c, new Vector3($pl->getFloorX(), $pl->getFloorY(), $pl->getFloorZ()), $pl->getLevel()->getName()); } break; default: $c->sendMessage(mc::_("Usage:")); $c->sendMessage(mc::_("/fs ls [world] - list worlds")); $c->sendMessage(mc::_("/fs add [x,y,z[:world]|player] <idtxt> - Add sign")); $c->sendMessage(mc::_("/fs rm <x,y,z[:world]|player|[world] idtxt> - Remove sign")); } return false; }