@@ -37,6 +37,7 @@ static unordered_map<string, Vec4> warps;
37
37
38
38
static clock_t TPexpire = CLOCKS_PER_SEC * 10 ;
39
39
static clock_t TPratelimit = CLOCKS_PER_SEC * 2 ;
40
+ std::string LANGUAGE = " en-us" ;
40
41
static int MAX_HOMES = 5 ;
41
42
static int HOME_DISTANCE_LAND = 0 ;
42
43
static bool BACK_ENABLED, SUICIDE_ENABLED, TPA_ENABLED, HOME_ENABLED;
@@ -104,31 +105,37 @@ bool DoCloseReq(decltype(reqs.begin()) rq, TPCloseReason res) {
104
105
break ;
105
106
}
106
107
}
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);
109
120
reqs.erase (rq);
121
+ playerA->sendTextPacket (tr (" tpa.reason.accept" ), TextType::RAW);
122
+ playerB->sendTextPacket (tr (" tpa.reason.accept" ), TextType::RAW);
110
123
return true ;
111
124
}
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);
125
128
reqs.erase (rq);
126
- return true ;
127
- }
128
- else {
129
- // no such player
129
+ return false ;
130
130
}
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 ;
131
137
}
138
+
132
139
void DoMakeReq (ServerPlayer* _a, ServerPlayer* _b, direction dir) {
133
140
std::string a = _a->getRealName ();
134
141
std::string b = _b->getRealName ();
@@ -201,7 +208,7 @@ class TpaCommand : public Command {
201
208
switch (reqres) {
202
209
case TPFailReason::success:
203
210
{
204
- DoMakeReq ({ ori.getPlayer ()}, t, dir);
211
+ DoMakeReq ({ ori.getPlayer () }, t, dir);
205
212
return ;
206
213
}
207
214
break ;
@@ -265,7 +272,7 @@ class TpaCommand : public Command {
265
272
fm->addWidget ({ GUILabel (guiLabel.c_str ()) });
266
273
fm->addWidget ({ GUIDropdown (guiDropdown1.c_str () ,{" to" ," here" }) });
267
274
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) {
269
276
if (!data.set ) return ;
270
277
auto & [d1,d2] = data.val ();
271
278
P.runcmd (" tpa " + d2[0 ] + " " + d2[1 ]);
@@ -279,8 +286,8 @@ class TpaCommand : public Command {
279
286
using RegisterCommandHelper::makeMandatory;
280
287
using RegisterCommandHelper::makeOptional;
281
288
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} });
284
291
registry->registerOverload <TpaCommand>(" tpa" , makeMandatory<CommandParameterDataType::ENUM>(&TpaCommand::dir, " direction" , " TPAOP2" , &TpaCommand::dir_isSet), makeMandatory (&TpaCommand::target, " player" ));
285
292
registry->registerOverload <TpaCommand>(" tpa" , makeMandatory<CommandParameterDataType::ENUM>(&TpaCommand::op, " op" , " TPAOP" , &TpaCommand::tpaop_isSet));
286
293
}
@@ -372,7 +379,7 @@ class WarpCommand : public Command {
372
379
using RegisterCommandHelper::makeMandatory;
373
380
using RegisterCommandHelper::makeOptional;
374
381
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} });
376
383
registry->registerOverload <WarpCommand>(" warp" , makeMandatory<CommandParameterDataType::ENUM>(&WarpCommand::op, " op" , " WARPOP" ), makeOptional (&WarpCommand::val, " warp" , &WarpCommand::val_isSet));
377
384
}
378
385
};
@@ -513,14 +520,15 @@ class SuicideCommand : public Command {
513
520
void loadCfg () {
514
521
try {
515
522
ConfigJReader jr (" plugins\\ LLtpa\\ tpa.json" );
523
+ jr.bind (" language" , LANGUAGE);
516
524
jr.bind (" max_homes" , MAX_HOMES, 5 );
517
525
jr.bind (" tpa_timeout" , TPexpire, CLOCKS_PER_SEC * 20 );
518
526
jr.bind (" tpa_ratelimit" , TPratelimit, CLOCKS_PER_SEC * 5 );
519
527
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 );
524
532
}
525
533
catch (string e) {
526
534
logger.error (" JSON ERROR" , e);
@@ -549,15 +557,12 @@ void init() {
549
557
rs.apply (warps);
550
558
}
551
559
loadCfg ();
560
+ Translation::load (" plugins/LLtpa/langpack/" + LANGUAGE + " .json" );
552
561
reinitWARPGUI ();
553
562
}
554
563
555
564
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" );
559
565
db = KVDB::create (" plugins\\ LLtpa\\ data" , true , 8 );
560
- Translation::load (" plugins/LLtpa/langpack/tpa.json" );
561
566
init ();
562
567
schTask ();
563
568
Event::RegCmdEvent::subscribe ([](const Event::RegCmdEvent& e) {
@@ -572,7 +577,7 @@ void tpa_entry() {
572
577
return true ;
573
578
});
574
579
if (BACK_ENABLED) {
575
- Event::PlayerDieEvent::subscribe ([](const Event::PlayerDieEvent& ev) {
580
+ Event::PlayerDieEvent::subscribe ([](const Event::PlayerDieEvent& ev) {
576
581
ServerPlayer* sp = (ServerPlayer*)ev.mPlayer ;
577
582
deathPos[sp] = Vec4{ sp };
578
583
sp->sendTextPacket (tr (" tpa.back.use" ), TextType::RAW);
0 commit comments