Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit 9291f73

Browse files
committed
Lots of bug fix && config update
1 parent fead9d2 commit 9291f73

File tree

12 files changed

+89
-63
lines changed

12 files changed

+89
-63
lines changed

CHANGELOG.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
## Bug Fix
2-
- Warp/Home GUI problem
2+
**Please replace all config file with the new config file**
3+
### LLTpa
4+
- Fixed bug when target player offline
5+
- Optimized message
6+
- Update Language Pack && Config
7+
8+
### LLHelper
9+
- Optimized code
10+
- Update Language Pack
11+
12+
## LLMoney
13+
- Update Language Pack

LLHelper/Helper.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@ std::unordered_map<string, string> CMDMAP, CMDSCHEDULE;
66
int FAKE_SEED, MAX_CHAT_LEN;
77
std::unordered_set<short> logItems, banItems;
88
bool regABILITY, NO_EXPLOSION, EXP_PLAY, penderman, pfarm;
9+
std::string LANGUAGE = "en-us";
910
Logger logger("Helper");
1011

1112
void loadCfg() {
1213
try {
1314
CMDMAP.clear();
1415
ConfigJReader jr("plugins\\LLHelper\\LLHelper.json");
15-
jr.bind("CMDMAP", CMDMAP);
16+
jr.bind("language", LANGUAGE);
17+
jr.bind("command_map", CMDMAP);
1618
jr.bind("timer", CMDSCHEDULE);
17-
jr.bind("FAKE_SEED", FAKE_SEED, 114514);
18-
jr.bind("NO_EXPLOSION", NO_EXPLOSION, false);
19-
jr.bind("MAX_CHAT_LEN", MAX_CHAT_LEN, 96);
20-
jr.bind("NoEndermanTakeBlock", penderman, true);
21-
jr.bind("ProtectFarmBlock", pfarm, true);
19+
jr.bind("fake_seed", FAKE_SEED, 114514);
20+
jr.bind("no_explosion", NO_EXPLOSION, false);
21+
jr.bind("max_chat_length", MAX_CHAT_LEN, 96);
22+
jr.bind("no_enderman_take_block", penderman, true);
23+
jr.bind("protect_farm_block", pfarm, true);
2224
jr.bind("force_enable_ability", regABILITY, true);
2325
std::vector<int> items;
2426
logItems.clear();
2527
banItems.clear();
26-
jr.bind("logItems", items, {});
28+
jr.bind("log_items", items, {});
2729
for (auto i : items) logItems.insert(i);
2830
items.clear();
29-
jr.bind("banItems", items, {});
31+
jr.bind("ban_items", items, {});
3032
for (auto i : items) banItems.insert(i);
3133
}
3234
catch (string e) {

LLHelper/command.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
std::unique_ptr<KVDB> db;
1616
playerMap<string> ORIG_NAME;
1717
std::unordered_map<string, string> CNAME;
18+
extern std::string LANGUAGE;
1819

1920
void loadCNAME() {
2021
db = KVDB::create("plugins/LLHelper/data", false);
@@ -359,7 +360,7 @@ class ItemCommand : public Command {
359360

360361
void RegisterCommands() {
361362
loadCNAME();
362-
Translation::load("plugins\\LLHelper\\langpack\\helper.json");
363+
Translation::load("plugins\\LLHelper\\langpack\\" + LANGUAGE + ".json");
363364
Event::RegCmdEvent::subscribe([](Event::RegCmdEvent e) {
364365
TransferCommand::setup(e.mCommandRegistry);
365366
HelperCommand::setup(e.mCommandRegistry);

LLMoney/LLMoney.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using namespace RegisterCommandHelper;
1919

2020
Logger logger("LLMoney");
21+
std::string LANGUAGE = "en-us";
2122

2223
double MoneyFee;
2324
bool initDB();
@@ -311,12 +312,9 @@ class MoneySCommand : public Command {
311312
};
312313

313314
void entry() {
314-
std::filesystem::create_directory("plugins\\LLMoney");
315-
std::filesystem::create_directory("plugins\\LLMoney\\langpack");
316315
if (!initDB()) {
317-
exit(1);
316+
return;
318317
}
319-
Translation::load("plugins\\LLMoney\\langpack\\money.json");
320318
Event::RegCmdEvent::subscribe([](const Event::RegCmdEvent& ev) {
321319
MoneyCommand::setup(ev.mCommandRegistry);
322320
MoneySCommand::setup(ev.mCommandRegistry);
@@ -325,6 +323,7 @@ void entry() {
325323
try {
326324
ConfigJReader jr("plugins\\LLMoney\\money.json");
327325
int defmoney;
326+
jr.bind("language", LANGUAGE);
328327
jr.bind("def_money", defmoney, 0);
329328
jr.bind("pay_tax", MoneyFee, .0);
330329
DEF_MONEY = defmoney;
@@ -333,5 +332,6 @@ void entry() {
333332
Logger("LLMoney").error("Json error: {}", e);
334333
throw 0;
335334
}
335+
Translation::load("plugins\\LLMoney\\langpack\\" + LANGUAGE + ".json");
336336
Logger("LLMoney").info("Loaded version: {}", _ver);
337337
}

LLtpa/Teleport.cpp

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static unordered_map<string, Vec4> warps;
3737

3838
static clock_t TPexpire = CLOCKS_PER_SEC * 10;
3939
static clock_t TPratelimit = CLOCKS_PER_SEC * 2;
40+
std::string LANGUAGE = "en-us";
4041
static int MAX_HOMES = 5;
4142
static int HOME_DISTANCE_LAND = 0;
4243
static bool BACK_ENABLED, SUICIDE_ENABLED, TPA_ENABLED, HOME_ENABLED;
@@ -104,31 +105,37 @@ bool DoCloseReq(decltype(reqs.begin()) rq, TPCloseReason res) {
104105
break;
105106
}
106107
}
107-
if (playerA && playerB) {
108-
if (res == TPCloseReason::cancel) {
108+
if (res == TPCloseReason::cancel) {
109+
if (playerA)
110+
playerA->sendText(tr("tpa.reason.cancel"));
111+
if (playerB)
112+
playerB->sendText(tr("tpa.reason.cancel"));
113+
reqs.erase(rq);
114+
return true;
115+
}
116+
if (res == TPCloseReason::accept) {
117+
if (playerA && playerB) {
118+
Vec4 AP{ rq->dir == A_B ? playerB : playerA };
119+
AP.teleport(rq->dir == A_B ? playerA : playerB);
109120
reqs.erase(rq);
121+
playerA->sendTextPacket(tr("tpa.reason.accept"), TextType::RAW);
122+
playerB->sendTextPacket(tr("tpa.reason.accept"), TextType::RAW);
110123
return true;
111124
}
112-
if (res == TPCloseReason::accept) {
113-
if (playerA && playerB) {
114-
Vec4 AP{ rq->dir == A_B ? playerB : playerA };
115-
AP.teleport(rq->dir == A_B ? playerA : playerB);
116-
reqs.erase(rq);
117-
playerA->sendTextPacket(tr("tpa.reason.accept"), TextType::RAW);
118-
return true;
119-
}
120-
reqs.erase(rq);
121-
return false;
122-
}
123-
playerA->sendTextPacket(res == TPCloseReason::deny ? tr("tpa.reason.deny") : tr("tpa.reason.timeout"), TextType::RAW);
124-
playerB->sendTextPacket(res == TPCloseReason::deny ? tr("tpa.reason.deny") : tr("tpa.reason.timeout"), TextType::RAW);
125+
// When tpa sender offline
126+
if (playerB)
127+
playerB->sendTextPacket(tr("tpa.reason.notonline"), TextType::RAW);
125128
reqs.erase(rq);
126-
return true;
127-
}
128-
else {
129-
//no such player
129+
return false;
130130
}
131+
if (playerA)
132+
playerA->sendTextPacket(res == TPCloseReason::deny ? tr("tpa.reason.deny") : tr("tpa.reason.timeout"), TextType::RAW);
133+
if (playerB)
134+
playerB->sendTextPacket(res == TPCloseReason::deny ? tr("tpa.reason.deny") : tr("tpa.reason.timeout"), TextType::RAW);
135+
reqs.erase(rq);
136+
return true;
131137
}
138+
132139
void DoMakeReq(ServerPlayer* _a, ServerPlayer* _b, direction dir) {
133140
std::string a = _a->getRealName();
134141
std::string b = _b->getRealName();
@@ -201,7 +208,7 @@ class TpaCommand : public Command {
201208
switch (reqres) {
202209
case TPFailReason::success:
203210
{
204-
DoMakeReq({ ori.getPlayer()}, t, dir);
211+
DoMakeReq({ ori.getPlayer() }, t, dir);
205212
return;
206213
}
207214
break;
@@ -265,7 +272,7 @@ class TpaCommand : public Command {
265272
fm->addWidget({ GUILabel(guiLabel.c_str()) });
266273
fm->addWidget({ GUIDropdown(guiDropdown1.c_str() ,{"to","here"}) });
267274
fm->addWidget({ GUIDropdown(guiDropdown2.c_str() ,playerList()) });
268-
sendForm(*ori.getPlayer(), FullFormBinder{fm,{[](ServerPlayer& P, FullFormBinder::DType data) {
275+
sendForm(*ori.getPlayer(), FullFormBinder{ fm,{[](ServerPlayer& P, FullFormBinder::DType data) {
269276
if (!data.set) return;
270277
auto& [d1,d2] = data.val();
271278
P.runcmd("tpa " + d2[0] + " " + d2[1]);
@@ -279,8 +286,8 @@ class TpaCommand : public Command {
279286
using RegisterCommandHelper::makeMandatory;
280287
using RegisterCommandHelper::makeOptional;
281288
registry->registerCommand("tpa", "Teleport", CommandPermissionLevel::Any, { (CommandFlagValue)0 }, { (CommandFlagValue)0x80 });
282-
registry->addEnum<direction>("TPAOP2", { {"to", direction::A_B}, {"here", direction::B_A}});
283-
registry->addEnum<TpaCommand::TPAOP>("TPAOP", { {"ac", TPAOP::ac}, {"de", TPAOP::de}, {"cancel", TPAOP::cancel}, {"gui", TPAOP::gui}, {"toggle", TPAOP::toggle}});
289+
registry->addEnum<direction>("TPAOP2", { {"to", direction::A_B}, {"here", direction::B_A} });
290+
registry->addEnum<TpaCommand::TPAOP>("TPAOP", { {"ac", TPAOP::ac}, {"de", TPAOP::de}, {"cancel", TPAOP::cancel}, {"gui", TPAOP::gui}, {"toggle", TPAOP::toggle} });
284291
registry->registerOverload<TpaCommand>("tpa", makeMandatory<CommandParameterDataType::ENUM>(&TpaCommand::dir, "direction", "TPAOP2", &TpaCommand::dir_isSet), makeMandatory(&TpaCommand::target, "player"));
285292
registry->registerOverload<TpaCommand>("tpa", makeMandatory<CommandParameterDataType::ENUM>(&TpaCommand::op, "op", "TPAOP", &TpaCommand::tpaop_isSet));
286293
}
@@ -372,7 +379,7 @@ class WarpCommand : public Command {
372379
using RegisterCommandHelper::makeMandatory;
373380
using RegisterCommandHelper::makeOptional;
374381
registry->registerCommand("warp", "Teleport", CommandPermissionLevel::Any, { (CommandFlagValue)0 }, { (CommandFlagValue)0x80 });
375-
registry->addEnum<WarpCommand::WARPOP>("WARPOP", { {"add", WARPOP::add}, {"del", WARPOP::del}, {"go", WARPOP::go}, {"gui", WARPOP::gui}, {"ls", WARPOP::ls}});
382+
registry->addEnum<WarpCommand::WARPOP>("WARPOP", { {"add", WARPOP::add}, {"del", WARPOP::del}, {"go", WARPOP::go}, {"gui", WARPOP::gui}, {"ls", WARPOP::ls} });
376383
registry->registerOverload<WarpCommand>("warp", makeMandatory<CommandParameterDataType::ENUM>(&WarpCommand::op, "op", "WARPOP"), makeOptional(&WarpCommand::val, "warp", &WarpCommand::val_isSet));
377384
}
378385
};
@@ -513,14 +520,15 @@ class SuicideCommand : public Command {
513520
void loadCfg() {
514521
try {
515522
ConfigJReader jr("plugins\\LLtpa\\tpa.json");
523+
jr.bind("language", LANGUAGE);
516524
jr.bind("max_homes", MAX_HOMES, 5);
517525
jr.bind("tpa_timeout", TPexpire, CLOCKS_PER_SEC * 20);
518526
jr.bind("tpa_ratelimit", TPratelimit, CLOCKS_PER_SEC * 5);
519527
jr.bind("home_land_distance", HOME_DISTANCE_LAND, -1);
520-
jr.bind("BACK_ENABLED", BACK_ENABLED, true);
521-
jr.bind("SUICIDE_ENABLED", SUICIDE_ENABLED, true);
522-
jr.bind("TPA_ENABLED", TPA_ENABLED, true);
523-
jr.bind("HOME_ENABLED", HOME_ENABLED, true);
528+
jr.bind("back_enabled", BACK_ENABLED, true);
529+
jr.bind("suicide_enabled", SUICIDE_ENABLED, true);
530+
jr.bind("tpa_enabled", TPA_ENABLED, true);
531+
jr.bind("home_enabled", HOME_ENABLED, true);
524532
}
525533
catch (string e) {
526534
logger.error("JSON ERROR", e);
@@ -549,15 +557,12 @@ void init() {
549557
rs.apply(warps);
550558
}
551559
loadCfg();
560+
Translation::load("plugins/LLtpa/langpack/" + LANGUAGE + ".json");
552561
reinitWARPGUI();
553562
}
554563

555564
void tpa_entry() {
556-
std::filesystem::create_directory("plugins\\LLtpa");
557-
std::filesystem::create_directory("plugins\\LLtpa\\data");
558-
std::filesystem::create_directory("plugins\\LLtpa\\langpack");
559565
db = KVDB::create("plugins\\LLtpa\\data", true, 8);
560-
Translation::load("plugins/LLtpa/langpack/tpa.json");
561566
init();
562567
schTask();
563568
Event::RegCmdEvent::subscribe([](const Event::RegCmdEvent& e) {
@@ -572,7 +577,7 @@ void tpa_entry() {
572577
return true;
573578
});
574579
if (BACK_ENABLED) {
575-
Event::PlayerDieEvent::subscribe([](const Event::PlayerDieEvent& ev) {
580+
Event::PlayerDieEvent::subscribe([](const Event::PlayerDieEvent& ev) {
576581
ServerPlayer* sp = (ServerPlayer*)ev.mPlayer;
577582
deathPos[sp] = Vec4{ sp };
578583
sp->sendTextPacket(tr("tpa.back.use"), TextType::RAW);

plugins/LLHelper/LLHelper.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
2-
"CMDMAP": {
3-
"391": "me 114514"
2+
"language": "en-us",
3+
"command_map": {
4+
"393": "me I used clock"
45
},
56
"timer": {
67
"1200": "say Welcome to the server"
78
},
8-
"banItems": [],
9-
"logItems": [
9+
"ban_items": [],
10+
"log_items": [
1011
7
1112
],
1213
"force_enable_ability": false,
13-
"FAKE_SEED": 114514,
14-
"NO_EXPLOSION": false,
15-
"MAX_CHAT_LEN": 1919,
16-
"NoEndermanTakeBlock": true,
17-
"ProtectFarmBlock": true
14+
"fake_seed": 114514,
15+
"no_explosion": false,
16+
"max_chat_length": 1919,
17+
"no_enderman_take_block": true,
18+
"protect_farm_block": true
1819
}

plugins/LLMoney/money.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"language": "en-us",
23
"def_money": 0,
34
"pay_tax": 0.0
45
}

plugins/LLtpa/langpack/tpa.json renamed to plugins/LLtpa/langpack/en-us.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"tpa.reason.deny": "Tpa request deny",
1515
"tpa.reason.timeout": "Tpa request timeout",
1616
"tpa.reason.accept": "Tpa request accepted",
17+
"tpa.reason.notonline": "Target player not online",
18+
"tpa.reason.cancel": "Tpa request cancelled",
1719
"tpa.back.use": "Using /back to back to your death point",
1820
"tpa.request.title": "Tpa request",
1921
"tpa.request.accept": "Accept",

plugins/LLtpa/langpack/zh-cn.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
"warp.gui.content": "选择一个传送点",
1212
"tpa.req.A_B": " 发起了一个传送到你的请求,使用/tpa ac接受,/tpa de拒绝",
1313
"tpa.req.B_A": " 发起了一个传送到他的请求,使用/tpa ac接受,/tpa de拒绝",
14-
"tpa.reason.deny": "TPA请求被拒绝",
15-
"tpa.reason.timeout": "TPA请求因超时自动取消",
16-
"tpa.reason.accept": "TPA请求已经被接受",
14+
"tpa.reason.deny": "Tpa请求被拒绝",
15+
"tpa.reason.timeout": "Tpa请求因超时自动取消",
16+
"tpa.reason.accept": "Tpa请求已经被接受",
17+
"tpa.reason.notonline": "目标玩家不在线",
18+
"tpa.reason.cancel": "Tpa请求已取消",
1719
"tpa.back.use": "可以使用/back返回上一个死亡点!",
1820
"tpa.request.title": "Tpa请求",
1921
"tpa.request.accept": "接受",

plugins/LLtpa/tpa.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2+
"language": "en-us",
23
"max_homes": 3,
34
"tpa_timeout": 20000,
45
"tpa_ratelimit": 5000,
56
"home_land_distance": 8,
6-
"BACK_ENABLED": true,
7-
"SUICIDE_ENABLED": true,
8-
"TPA_ENABLED": true,
9-
"HOME_ENABLED": true
7+
"back_enabled": true,
8+
"suicide_enabled": true,
9+
"tpa_enabled": true,
10+
"home_enabled": true
1011
}

0 commit comments

Comments
 (0)