diff --git a/docs/md/CommandList.md b/docs/md/CommandList.md index 5580d90..b73f9b7 100644 --- a/docs/md/CommandList.md +++ b/docs/md/CommandList.md @@ -16,6 +16,7 @@ 23:01:00.561 INFO [Server] - /pland new 23:01:00.561 INFO [Server] - /pland reload 23:01:00.561 INFO [Server] - /pland set +23:01:00.561 INFO [Server] - /pland set teleport_pos 23:01:00.561 INFO [Server] - /pland draw 17:35:08.110 INFO [Server] - /pland import ``` @@ -49,6 +50,9 @@ - `/pland reload` - 重载领地配置 (控制台)。 +- `/pland set teleport_pos` + - 设置脚下领地的传送点为当前位置(领地主人、管理员)。 + - `/pland draw ` - 开启绘制领地范围(需在 `Config.json` 中设置 `setupDrawCommand: true`) - `disable` 关闭绘制(玩家执行关闭自己、控制台执行关闭所有玩家) diff --git a/include/pland/LandData.h b/include/pland/LandData.h index fa4be57..8749c93 100644 --- a/include/pland/LandData.h +++ b/include/pland/LandData.h @@ -91,8 +91,9 @@ using LandData_sptr = std::shared_ptr; // 共享指针 using LandData_wptr = std::weak_ptr; // 弱指针 class LandData { public: - int version{4}; // 版本号 + int version{5}; // 版本号 LandPos mPos; // 领地对角坐标 + PosBase mTeleportPos; // 领地传送坐标 LandID mLandID{static_cast(-1)}; // 领地唯一ID (由 PLand::addLand() 时分配) LandDimid mLandDimid; // 领地所在维度 bool mIs3DLand; // 是否为3D领地 diff --git a/include/pland/LandPos.h b/include/pland/LandPos.h index 0e5549e..1dcc941 100644 --- a/include/pland/LandPos.h +++ b/include/pland/LandPos.h @@ -18,6 +18,8 @@ class PosBase { [[nodiscard]] LDAPI std::string toString() const; + [[nodiscard]] LDAPI bool isZero() const; // xyz是否都为0 + LDAPI PosBase& operator=(PosBase const& pos) = default; LDAPI bool operator==(PosBase const& pos) const; LDAPI bool operator!=(PosBase const& pos) const; diff --git a/src/Command.cc b/src/Command.cc index 4557db2..205348b 100644 --- a/src/Command.cc +++ b/src/Command.cc @@ -240,6 +240,24 @@ static auto const Import = [](CommandOrigin const& ori, CommandOutput& out, Impo } }; +static auto const SetLandTeleportPos = [](CommandOrigin const& ori, CommandOutput& out) { + CHECK_TYPE(ori, out, CommandOriginType::Player); + auto& player = *static_cast(ori.getEntity()); + + auto& db = PLand::getInstance(); + auto land = db.getLandAt(player.getPosition(), player.getDimensionId().id); + if (!land) { + mc::sendText(out, "您当前不在领地内"_tr()); + return; + } + + auto uuid = player.getUuid().asString(); + if (!land->isLandOwner(uuid) && !db.isOperator(uuid)) { + mc::sendText(out, "您不是领地主人,无法设置传送点"_tr()); + return; + } + land->mTeleportPos = player.getPosition(); +}; }; // namespace Lambda @@ -287,6 +305,9 @@ bool LandCommand::setup() { .required("data_file") .execute(Lambda::Import); + // pland set teleport_pos 设置传送点 + cmd.overload().text("set").text("teleport_pos").execute(Lambda::SetLandTeleportPos); + #ifdef LD_DEVTOOL // pland devtool cmd.overload().text("devtool").execute([](CommandOrigin const& ori, CommandOutput&) { diff --git a/src/GUI.cc b/src/GUI.cc index db97cd9..ca25cc4 100644 --- a/src/GUI.cc +++ b/src/GUI.cc @@ -817,7 +817,12 @@ void LandTeleportGui::run(Player& player, LandID id) { return; } - SafeTeleport::getInstance().teleportTo(player, land->mPos.mMin_A, land->getLandDimid()); + if (land->mTeleportPos.isZero()) { + SafeTeleport::getInstance().teleportTo(player, land->mPos.mMin_A, land->getLandDimid()); + return; + } + + player.teleport(land->mTeleportPos, land->getLandDimid()); } diff --git a/src/LandPos.cc b/src/LandPos.cc index 7f50bf4..71220a1 100644 --- a/src/LandPos.cc +++ b/src/LandPos.cc @@ -8,8 +8,9 @@ namespace land { // PosBase std::string PosBase::toString() const { return fmt::format("({},{},{})", x, y, z); } -PosBase::operator BlockPos() const { return BlockPos(x, y, z); } -PosBase::operator Vec3() const { return Vec3(x, y, z); } +bool PosBase::isZero() const { return x == 0 && y == 0 && z == 0; } +PosBase::operator BlockPos() const { return {x, y, z}; } +PosBase::operator Vec3() const { return {x, y, z}; } bool PosBase::operator==(const PosBase& pos) const { return this->x == pos.x && this->y == pos.y && this->z == pos.z; } bool PosBase::operator!=(const PosBase& pos) const { return !(*this == pos); } bool PosBase::operator==(const BlockPos& pos) const { return this->x == pos.x && this->y == pos.y && this->z == pos.z; }