Skip to content

Commit 4538381

Browse files
committed
fix: fix some issue
1 parent 676a1a4 commit 4538381

File tree

5 files changed

+42
-13
lines changed

5 files changed

+42
-13
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,35 @@
22

33
高性能、多线程的 BDS 侧边栏插件。
44

5-
# 开源许可
5+
## 命令
66

7-
## 源代码可用性
7+
- `/gmsidebar [true/false]` - 开关自己的侧边栏
8+
- `/gmsidebar cache` - 清除自己的缓存
9+
- `/gmsidebar disable` - 禁用侧边栏模组
10+
- `/gmsidebar enable` - 启用侧边栏模组
11+
- `/gmsidebar reload` - 重载侧边栏配置和数据文件
12+
- `/gmsidebar as <player> [true/false]` - 开关指定玩家的侧边栏
13+
- `/gmsidebar as <player> status` - 查看指定玩家的侧边栏状态
14+
- `/gmsidebar as <player> cache` - 清除指定玩家的缓存
15+
16+
## 开源许可
17+
18+
### 源代码可用性
819

920
- 您可以自由地获取、使用和修改本插件的源代码,无论是个人使用还是商业目的。
1021

11-
## 修改发布
22+
### 修改发布
1223

1324
- 如果您对本插件进行了修改或衍生创作,并打算分发、发布该修改或衍生作品,您必须开源并且以 GPL3.0 协议下相同的许可证条件进行分发。
1425

15-
## 版权声明
26+
### 版权声明
1627

1728
- 在您分发或发布基于 GPL3.0 协议的软件时(包括但不限于本插件以及本插件的衍生作品),您必须保留原始版权声明、许可证说明和免责声明。
1829

19-
## 引用链接
30+
### 引用链接
2031

2132
- 如果您在一个作品中使用了本插件或者本插件的源码,您需要提供一个明确的引用链接,指向软件的许可证和源代码。
2233

23-
## 对整体的影响
34+
### 对整体的影响
2435

2536
- 如果您将基于本插件与其他插件结合使用,或整合成一个单一的插件,那么整个插件都需要遵守 GPL3.0 协议进行开源。

src/gmsidebar/ApiExport.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ void Entry::exportApi() {
2020
LegacyRemoteCall::exportAs("GMSidebar", "saveConfigFromPath", [](std::string const& path) {
2121
GMSidebar::getInstance().saveConfig(path);
2222
});
23+
LegacyRemoteCall::exportAs("GMSidebar", "loadData", []() { GMSidebar::getInstance().loadData(std::nullopt); });
24+
LegacyRemoteCall::exportAs("GMSidebar", "saveData", []() { GMSidebar::getInstance().saveData(std::nullopt); });
25+
LegacyRemoteCall::exportAs("GMSidebar", "loadDataFromPath", [](std::string const& path) {
26+
GMSidebar::getInstance().loadData(path);
27+
});
28+
LegacyRemoteCall::exportAs("GMSidebar", "saveDataFromPath", [](std::string const& path) {
29+
GMSidebar::getInstance().saveData(path);
30+
});
2331
LegacyRemoteCall::exportAs("GMSidebar", "isPlayerSidebarEnabled", [](std::string const& uuid) {
2432
return GMSidebar::getInstance().isPlayerSidebarEnabled(mce::UUID::fromString(uuid));
2533
});

src/gmsidebar/Command.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <ll/api/i18n/I18n.h>
1010
#include <mc/world/actor/player/Player.h>
1111

12-
1312
namespace gmsidebar {
1413

1514
void Entry::registerCmd() {
@@ -79,6 +78,8 @@ void Entry::registerCmd() {
7978
if (auto& instance = GMSidebar::getInstance(); instance.isEnabled()) {
8079
instance.loadConfig(std::nullopt);
8180
instance.saveConfig(std::nullopt);
81+
instance.loadData(std::nullopt);
82+
instance.saveData(std::nullopt);
8283
output.success("The sidebar config has been reloaded."_trl(origin.getLocaleCode()));
8384
} else {
8485
output.error("The sidebar mod is not enabled."_trl(origin.getLocaleCode()));

src/gmsidebar/GMSidebar.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ struct GMSidebar::Impl {
125125
}
126126
}
127127
void saveConfig(std::filesystem::path const& path) { ll::config::saveConfig(mConfig, path); }
128-
void loadData() {
129-
auto& selfMod = Entry::getInstance().getSelf();
130-
auto& logger = selfMod.getLogger();
131-
auto path = selfMod.getDataDir() / u8"data.nbt";
128+
void loadData(std::filesystem::path const& path) {
129+
auto& logger = Entry::getInstance().getSelf().getLogger();
132130
try {
133131
if (auto content = ll::file_utils::readFile(path, true); content) {
134132
if (auto nbt = CompoundTag::fromBinaryNbt(*content); nbt) {
@@ -150,9 +148,9 @@ struct GMSidebar::Impl {
150148
ll::error_utils::printCurrentException(logger);
151149
}
152150
}
153-
void saveData() {
151+
void saveData(std::filesystem::path const& path) {
154152
ll::file_utils::writeFile(
155-
Entry::getInstance().getSelf().getDataDir() / u8"data.nbt",
153+
path,
156154
ll::reflection::serialize<CompoundTagVariant>(mPlayerSidebarEnabled)->get<CompoundTag>().toBinaryNbt(),
157155
true
158156
);
@@ -328,6 +326,14 @@ void GMSidebar::saveConfig(std::optional<std::filesystem::path> const& path) {
328326
if (!pImpl) throw std::runtime_error("GMSidebar is not enabled");
329327
pImpl->saveConfig(path.value_or(Entry::getInstance().getSelf().getConfigDir() / u8"config.json"));
330328
}
329+
void GMSidebar::loadData(std::optional<std::filesystem::path> const& path) {
330+
if (!pImpl) throw std::runtime_error("GMSidebar is not enabled");
331+
pImpl->loadData(path.value_or(Entry::getInstance().getSelf().getConfigDir() / u8"data.nbt"));
332+
}
333+
void GMSidebar::saveData(std::optional<std::filesystem::path> const& path) {
334+
if (!pImpl) throw std::runtime_error("GMSidebar is not enabled");
335+
pImpl->saveData(path.value_or(Entry::getInstance().getSelf().getConfigDir() / u8"data.nbt"));
336+
}
331337
bool GMSidebar::isPlayerSidebarEnabled(mce::UUID const& uuid) {
332338
if (!pImpl) throw std::runtime_error("GMSidebar is not enabled");
333339
if (auto it = pImpl->mPlayerSidebarEnabled.find(uuid); it != pImpl->mPlayerSidebarEnabled.end()) {
@@ -349,6 +355,7 @@ void GMSidebar::setPlayerSidebarEnabled(mce::UUID const& uuid, bool enable) {
349355
}
350356
}
351357
}
358+
saveData(std::nullopt);
352359
}
353360
void GMSidebar::clearPlayerCache(mce::UUID const& uuid) {
354361
if (!pImpl) throw std::runtime_error("GMSidebar is not enabled");

src/gmsidebar/GMSidebar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class GMSidebar {
9797
virtual Config& getConfig();
9898
virtual void loadConfig(std::optional<std::filesystem::path> const& path);
9999
virtual void saveConfig(std::optional<std::filesystem::path> const& path);
100+
virtual void loadData(std::optional<std::filesystem::path> const& path);
101+
virtual void saveData(std::optional<std::filesystem::path> const& path);
100102
virtual bool isPlayerSidebarEnabled(mce::UUID const& uuid);
101103
virtual void setPlayerSidebarEnabled(mce::UUID const& uuid, bool enable);
102104
virtual void clearPlayerCache(mce::UUID const& uuid);

0 commit comments

Comments
 (0)