Skip to content

Commit

Permalink
feat: 添加查找无主地皮功能
Browse files Browse the repository at this point in the history
  • Loading branch information
engsr6982 committed Oct 28, 2024
1 parent ac3140c commit 75957d2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
2 changes: 2 additions & 0 deletions include/plotcraft/data/PlotDBStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "plotcraft/data/PlotMetadata.h"
#include "plotcraft/math/PlotPos.h"
#include <memory>
#include <optional>
#include <thread>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -93,6 +94,7 @@ class PlotDBStorage {

PLAPI PlotPermission getPlayerPermission(UUIDs const& uuid, PlotID const& pid, bool ignoreAdmin = false) const;

PLAPI std::optional<PlotPos> findUnownedPlot() const;

// 特殊数据 Key (统一定义Key,请勿修改)
string const DB_ArchivedPrefix = "Archived_";
Expand Down
32 changes: 26 additions & 6 deletions src/plotcraft/command/Command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const auto LambdaOP = [](CommandOrigin const& origin, CommandOutput& output, Par
struct ParamGo {
enum GoDimension { overworld, plot } dim;
};
const auto LambdaGo = [](CommandOrigin const& origin, CommandOutput& output, ParamGo const& param) {
static const auto LambdaGo = [](CommandOrigin const& origin, CommandOutput& output, ParamGo const& param) {
CHECK_COMMAND_TYPE(output, origin, CommandOriginType::Player);
Player& player = *static_cast<Player*>(origin.getEntity());

Expand All @@ -72,7 +72,7 @@ const auto LambdaGo = [](CommandOrigin const& origin, CommandOutput& output, Par
#endif


const auto LambdaPlot = [](CommandOrigin const& origin, CommandOutput& output) {
static const auto LambdaPlot = [](CommandOrigin const& origin, CommandOutput& output) {
CHECK_COMMAND_TYPE(output, origin, CommandOriginType::Player);
Player& player = *static_cast<Player*>(origin.getEntity());
if (player.getDimensionId() != getPlotWorldDimensionId()) {
Expand All @@ -94,30 +94,46 @@ const auto LambdaPlot = [](CommandOrigin const& origin, CommandOutput& output) {
};


const auto LambdaDefault = [](CommandOrigin const& origin, CommandOutput& output) {
static const auto LambdaDefault = [](CommandOrigin const& origin, CommandOutput& output) {
CHECK_COMMAND_TYPE(output, origin, CommandOriginType::Player);
Player& player = *static_cast<Player*>(origin.getEntity());
gui::MainGUI(player);
};


const auto LambdaDBSave = [](CommandOrigin const& origin, CommandOutput& output) {
static const auto LambdaDBSave = [](CommandOrigin const& origin, CommandOutput& output) {
CHECK_COMMAND_TYPE(output, origin, CommandOriginType::DedicatedServer);
data::PlotDBStorage::getInstance().save();
sendText<LogLevel::Success>(output, "操作完成!");
};

const auto LambdaMgr = [](CommandOrigin const& origin, CommandOutput& output) {
static const auto LambdaMgr = [](CommandOrigin const& origin, CommandOutput& output) {
CHECK_COMMAND_TYPE(output, origin, CommandOriginType::Player);
Player& player = *static_cast<Player*>(origin.getEntity());
gui::PluginSettingGUI(player);
};
const auto LambdaSetting = [](CommandOrigin const& origin, CommandOutput& output) {
static const auto LambdaSetting = [](CommandOrigin const& origin, CommandOutput& output) {
CHECK_COMMAND_TYPE(output, origin, CommandOriginType::Player);
Player& player = *static_cast<Player*>(origin.getEntity());
gui::PlayerSettingGUI(player);
};

static const auto LambdaFindUnownedPlot = [](CommandOrigin const& origin, CommandOutput& output) {
CHECK_COMMAND_TYPE(output, origin, CommandOriginType::Player);
Player& player = *static_cast<Player*>(origin.getEntity());
if (player.getDimensionId() != getPlotWorldDimensionId()) {
sendText<LogLevel::Error>(player, "此命令只能在地皮世界使用!");
return;
}

auto result = data::PlotDBStorage::getInstance().findUnownedPlot();
if (!result) {
sendText<LogLevel::Error>(player, "插件异常, 未找到无主地皮!");
}

player.teleport(result->getSafestPos(), getPlotWorldDimensionId());
};


bool registerCommand() {
auto& cmd = ll::command::CommandRegistrar::getInstance().getOrCreateCommand(COMMAND_NAME, "PlotCraft");
Expand All @@ -130,6 +146,10 @@ bool registerCommand() {
cmd.overload().text("setting").execute(LambdaSetting); // plot setting
cmd.overload().execute(LambdaDefault); // plot

// 查找无主地皮
// plot find unowned_plot
cmd.overload().text("find").text("unowned_plot").execute(LambdaFindUnownedPlot);

_setupTemplateCommand();

// MergeCommand.cc
Expand Down
16 changes: 16 additions & 0 deletions src/plotcraft/data/PlotDBStorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#include "plotcraft/math/PlotCross.h"
#include "plotcraft/math/PlotPos.h"
#include "plotcraft/math/PlotRoad.h"
#include "plotcraft/private/NodeTree.h"
#include "plotcraft/utils/JsonHelper.h"
#include "plugin/MyPlugin.h"
#include <memory>
#include <optional>
#include <stdexcept>
#include <stop_token>
#include <thread>
Expand Down Expand Up @@ -321,5 +323,19 @@ bool PlotDBStorage::refreshMergeMap() {
return true;
}

std::optional<PlotPos> PlotDBStorage::findUnownedPlot() const {
NodeTree tree;

for (auto const& [_, ptr] : mPlotList) {
tree.insert(NodeTree::Node(ptr->getX(), ptr->getZ()));
}

auto result = tree.findNearestUnmarkedNodeFromRoot();
if (result) {
return PlotPos(result->x, result->z);
}
return std::nullopt;
}


} // namespace plot::data
File renamed without changes.
7 changes: 0 additions & 7 deletions src/plotcraft/utils/Debugger.h

This file was deleted.

0 comments on commit 75957d2

Please sign in to comment.