Skip to content

Commit 92124ea

Browse files
committed
fix: fix setInterval & setTimeout
1 parent 9ae93eb commit 92124ea

File tree

8 files changed

+24
-20
lines changed

8 files changed

+24
-20
lines changed

src/legacy/api/EventAPI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
#include "mc/world/actor/player/Player.h"
5454
#include "mc/world/item/Item.h"
5555
#include "mc/world/item/VanillaItemNames.h"
56-
#include "mc/world/level/BlockSource.h"
5756
#include "mc/world/level/dimension/Dimension.h"
57+
#include "ll/api/thread/ServerThreadExecutor.h"
5858

5959
#include <list>
6060
#include <shared_mutex>
@@ -844,7 +844,7 @@ void InitBasicEventListeners() {
844844

845845
// 处理延迟注册
846846
ProcessRegCmdQueue();
847-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
847+
}).launch(ll::thread::ServerThreadExecutor::getDefault());
848848
});
849849

850850
// 植入tick
@@ -880,7 +880,7 @@ void InitBasicEventListeners() {
880880
IF_LISTENED(EVENT_TYPES::onTick) { CallEventUncancelable(EVENT_TYPES::onTick); }
881881
IF_LISTENED_END(EVENT_TYPES::onTick);
882882
}
883-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
883+
}).launch(ll::thread::ServerThreadExecutor::getDefault());
884884
}
885885

886886
bool MoneyBeforeEventCallback(LLMoneyEvent type, std::string from, std::string to, long long value) {

src/legacy/api/PlayerAPI.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3063,8 +3063,9 @@ Local<Value> PlayerClass::getAbilities(const Arguments&) {
30633063
Player* player = get();
30643064
if (!player) return Local<Value>();
30653065

3066-
CompoundTag tag = CompoundTag();
3066+
CompoundTag tag;
30673067
player->save(tag);
3068+
30683069
try {
30693070
return Tag2Value(&tag.at("abilities").get<CompoundTag>(), true);
30703071
} catch (...) {

src/legacy/engine/LocalShareData.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "engine/LocalShareData.h"
22

3-
#include <ll/api/thread/ThreadPoolExecutor.h>
43
#include <mutex>
54

65
// DLL本地共享数据

src/legacy/engine/LocalShareData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
#include "api/APIHelp.h"
3+
#include "ll/api/thread/ThreadPoolExecutor.h"
34

4-
#include <ll/api/thread/ThreadPoolExecutor.h>
55
#include <map>
66
#include <mutex>
77
#include <string>

src/legacy/engine/TimeTaskSystem.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "engine/EngineManager.h"
55
#include "engine/EngineOwnData.h"
66
#include "ll/api/service/GamingStatus.h"
7-
#include "ll/api/thread/ThreadPoolExecutor.h"
7+
#include "ll/api/thread/ServerThreadExecutor.h"
88
#include "ll/api/coro/CoroTask.h"
99

1010
#include <ll/api/service/ServerInfo.h>
@@ -77,7 +77,7 @@ int NewTimeout(Local<Function> func, std::vector<Local<Value>> paras, int timeou
7777
}
7878
TIMETASK_CATCH("setTimeout-Function");
7979
ClearTimeTask(tid);
80-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
80+
}).launch(ll::thread::ServerThreadExecutor::getDefault());
8181

8282
std::lock_guard lock(locker);
8383
timeTaskMap[tid] = std::move(data);
@@ -115,7 +115,7 @@ int NewTimeout(Local<String> func, int timeout) {
115115
}
116116
}
117117
TIMETASK_CATCH("setTimeout-String");
118-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
118+
}).launch(ll::thread::ServerThreadExecutor::getDefault());
119119

120120
std::lock_guard lock(locker);
121121
timeTaskMap[tid] = std::move(data);
@@ -152,7 +152,7 @@ int NewInterval(Local<Function> func, std::vector<Local<Value>> paras, int timeo
152152
}
153153
TIMETASK_CATCH("setInterval-Function");
154154
}
155-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
155+
}).launch(ll::thread::ServerThreadExecutor::getDefault());
156156

157157
std::lock_guard lock(locker);
158158
timeTaskMap[tid] = std::move(data);
@@ -199,7 +199,7 @@ int NewInterval(Local<String> func, int timeout) {
199199
}
200200
TIMETASK_CATCH("setInterval-String");
201201
}
202-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
202+
}).launch(ll::thread::ServerThreadExecutor::getDefault());
203203

204204
std::lock_guard lock(locker);
205205
timeTaskMap[tid] = std::move(data);

src/legacy/legacyapi/command/DynamicCommand.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,13 @@ DynamicCommand::preSetup(CommandRegistry& registry, std::unique_ptr<class Dynami
528528
if (!commandInstance->alias_.empty()) registry.registerAlias(commandInstance->name_, commandInstance->alias_);
529529
auto builder = commandInstance->builder->get();
530530
for (auto& overload : commandInstance->overloads) {
531-
auto& si = *registry.findCommand(commandInstance->name_);
532-
si.overloads.emplace_back(CommandVersion{}, builder).params = commandInstance->buildOverload(overload);
533-
registry.registerOverloadInternal(si, si.overloads.back());
531+
auto si = registry.findCommand(commandInstance->name_);
532+
if (!si) {
533+
OutputError(name);
534+
return nullptr;
535+
}
536+
si->overloads.emplace_back(CommandVersion{}, builder).params = commandInstance->buildOverload(overload);
537+
registry.registerOverloadInternal(*si, si->overloads.back());
534538
}
535539
// commandInstance->overloads.clear();
536540
auto res = dynamicCommandInstances.emplace(commandInstance->name_, std::move(commandInstance));

src/legacy/legacyapi/command/DynamicCommand.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ class DynamicCommand : public Command {
426426
&CommandRegistry::parse<T>,
427427
name,
428428
getCommandParameterDataType<type>(),
429-
description == "" ? nullptr : description.data(),
430-
identifier == "" ? nullptr : identifier.data(),
429+
description.empty() ? nullptr : description.data(),
430+
identifier.empty() ? nullptr : identifier.data(),
431431
(int)offset,
432432
optional,
433433
(int)offset + std::max(8, (int)sizeof(T)),
@@ -453,7 +453,7 @@ class DynamicCommand : public Command {
453453
std::string const& identifer = "",
454454
CommandParameterOption parameterOption = CommandParameterOption::None
455455
)
456-
: ParameterData(name, type, (std::string const&)enumOptions, identifer, parameterOption){};
456+
: ParameterData(name, type, (std::string const&)enumOptions, identifer, parameterOption) {};
457457
};
458458

459459
using callback_fn = std::function<void(
@@ -581,7 +581,7 @@ class DynamicCommandInstance {
581581
struct ParameterIndex {
582582
DynamicCommandInstance* instance;
583583
size_t index;
584-
ParameterIndex(DynamicCommandInstance* instance, size_t index) : instance(instance), index(index){};
584+
ParameterIndex(DynamicCommandInstance* instance, size_t index) : instance(instance), index(index) {};
585585
operator size_t() const { return index; }
586586
DynamicCommand::ParameterData& operator->() { return instance->parameterDatas.at(index); }
587587
bool isValid() const {

src/legacy/main/NodeJsHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "ll/api/coro/CoroTask.h"
1414
#include "ll/api/io/FileUtils.h"
1515
#include "ll/api/service/ServerInfo.h"
16-
#include "ll/api/thread/ThreadPoolExecutor.h"
16+
#include "ll/api/thread/ServerThreadExecutor.h"
1717
#include "ll/api/utils/StringUtils.h"
1818
#include "main/Global.h"
1919
#include "uv/uv.h"
@@ -180,7 +180,7 @@ bool loadPluginCode(script::ScriptEngine* engine, std::string entryScriptPath, s
180180
}
181181
}
182182
}
183-
).launch(ll::thread::ThreadPoolExecutor::getDefault());
183+
).launch(ll::thread::ServerThreadExecutor::getDefault());
184184

185185
return true;
186186
} catch (...) {

0 commit comments

Comments
 (0)