Skip to content

Commit

Permalink
feat: supported custom land teleport pos #9
Browse files Browse the repository at this point in the history
  • Loading branch information
engsr6982 committed Feb 17, 2025
1 parent 56fdaa3 commit b853ef7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/md/CommandList.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a|b>
23:01:00.561 INFO [Server] - /pland set teleport_pos
23:01:00.561 INFO [Server] - /pland draw <disable|current_land|near_land>
17:35:08.110 INFO [Server] - /pland import <clearDb: Boolean> <relationship_file: string> <data_file: string>
```
Expand Down Expand Up @@ -49,6 +50,9 @@
- `/pland reload`
- 重载领地配置 (控制台)。

- `/pland set teleport_pos`
- 设置脚下领地的传送点为当前位置(领地主人、管理员)。

- `/pland draw <disable|current_land|near_land>`
- 开启绘制领地范围(需在 `Config.json` 中设置 `setupDrawCommand: true`)
- `disable` 关闭绘制(玩家执行关闭自己、控制台执行关闭所有玩家)
Expand Down
3 changes: 2 additions & 1 deletion include/pland/LandData.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ using LandData_sptr = std::shared_ptr<class LandData>; // 共享指针
using LandData_wptr = std::weak_ptr<class LandData>; // 弱指针
class LandData {
public:
int version{4}; // 版本号
int version{5}; // 版本号
LandPos mPos; // 领地对角坐标
PosBase mTeleportPos; // 领地传送坐标
LandID mLandID{static_cast<uint64_t>(-1)}; // 领地唯一ID (由 PLand::addLand() 时分配)
LandDimid mLandDimid; // 领地所在维度
bool mIs3DLand; // 是否为3D领地
Expand Down
2 changes: 2 additions & 0 deletions include/pland/LandPos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/Command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player*>(ori.getEntity());

auto& db = PLand::getInstance();
auto land = db.getLandAt(player.getPosition(), player.getDimensionId().id);
if (!land) {
mc::sendText<mc::LogLevel::Error>(out, "您当前不在领地内"_tr());
return;
}

auto uuid = player.getUuid().asString();
if (!land->isLandOwner(uuid) && !db.isOperator(uuid)) {
mc::sendText<mc::LogLevel::Error>(out, "您不是领地主人,无法设置传送点"_tr());
return;
}
land->mTeleportPos = player.getPosition();
};

}; // namespace Lambda

Expand Down Expand Up @@ -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&) {
Expand Down
7 changes: 6 additions & 1 deletion src/GUI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}


Expand Down
5 changes: 3 additions & 2 deletions src/LandPos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit b853ef7

Please sign in to comment.