Skip to content

Commit df874e1

Browse files
committed
refactor: rename Plugin to ScriptPlugin
fix: fix onLeft crash on client fix: fix registerCommands not clear when disable on client
1 parent 838ca02 commit df874e1

8 files changed

Lines changed: 26 additions & 26 deletions

File tree

src-client/lse/PluginManager.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "ll/api/utils/ErrorUtils.h"
1010
#include "ll/api/utils/StringUtils.h"
1111
#include "lse/Entry.h"
12-
#include "lse/Plugin.h"
12+
#include "lse/ScriptPlugin.h"
1313

1414
#include <ScriptX/ScriptX.h>
1515
#include <exception>
@@ -65,7 +65,7 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
6565
return ll::makeStringError("Plugin has already loaded");
6666
}
6767

68-
auto plugin = std::make_shared<Plugin>(manifest);
68+
auto plugin = std::make_shared<ScriptPlugin>(manifest);
6969

7070
return plugin->onLoad().transform([&, this] { addMod(manifest.name, plugin); });
7171
}
@@ -131,7 +131,7 @@ ll::Expected<> PluginManager::enable(std::string_view name) {
131131
}
132132
}
133133
#endif
134-
auto plugin = std::static_pointer_cast<Plugin>(getMod(name));
134+
auto plugin = std::static_pointer_cast<ScriptPlugin>(getMod(name));
135135
if (!plugin) {
136136
return ll::makeStringError("Plugin {0} not found"_tr(name));
137137
}
@@ -280,8 +280,11 @@ ll::Expected<> PluginManager::disable(std::string_view name) {
280280
NodeJsHelper::stopEngine(scriptEngine);
281281
#endif
282282

283-
if (auto res = std::static_pointer_cast<Plugin>(getMod(name))->onDisable(); !res) {
284-
return res;
283+
if (auto plugin = std::static_pointer_cast<ScriptPlugin>(getMod(name))) {
284+
plugin->registeredCommands.clear();
285+
if (auto res = plugin->onDisable(); !res) {
286+
return res;
287+
}
285288
}
286289
return {};
287290
} catch (const Exception&) {
@@ -292,7 +295,7 @@ ll::Expected<> PluginManager::disable(std::string_view name) {
292295
}
293296

294297
ll::Expected<> PluginManager::unload(std::string_view name) {
295-
if (auto res = std::static_pointer_cast<Plugin>(getMod(name))->onUnload(); !res) {
298+
if (auto res = std::static_pointer_cast<ScriptPlugin>(getMod(name))->onUnload(); !res) {
296299
return res;
297300
}
298301
eraseMod(name);

src-server/lse/PluginManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "ll/api/service/GamingStatus.h"
99
#include "ll/api/utils/StringUtils.h"
1010
#include "lse/Entry.h"
11-
#include "lse/Plugin.h"
11+
#include "lse/ScriptPlugin.h"
1212

1313
#include <ScriptX/ScriptX.h>
1414
#include <exception>
@@ -125,7 +125,7 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
125125
}
126126

127127
auto scriptEngine = EngineManager::newEngine(manifest.name);
128-
auto plugin = std::make_shared<Plugin>(manifest);
128+
auto plugin = std::make_shared<ScriptPlugin>(manifest);
129129

130130
try {
131131
EngineScope engineScope(scriptEngine.get());
@@ -271,7 +271,7 @@ ll::Expected<> PluginManager::unload(std::string_view name) {
271271
NodeJsHelper::stopEngine(scriptEngine);
272272
#endif
273273

274-
if (auto res = std::static_pointer_cast<Plugin>(getMod(name))->onUnload(); !res) {
274+
if (auto res = std::static_pointer_cast<ScriptPlugin>(getMod(name))->onUnload(); !res) {
275275
return res;
276276
}
277277
eraseMod(name);

src/legacy/api/EventAPI.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#include "mc/world/item/VanillaItemNames.h"
5555
#include "mc/world/level/dimension/Dimension.h"
5656

57+
#include <ll/api/service/GamingStatus.h>
58+
5759
#ifdef LSE_BACKEND_NODEJS
5860
#include "legacy/main/NodeJsHelper.h"
5961
#endif
@@ -184,7 +186,7 @@ void EnableEventListener(int eventId) {
184186
case EVENT_TYPES::onLeft:
185187
bus.emplaceListener<PlayerDisconnectEvent>([](PlayerDisconnectEvent& ev) {
186188
IF_LISTENED(EVENT_TYPES::onLeft) {
187-
if (checkClientIsServerThread()) {
189+
if (checkClientIsServerThread() && ll::getGamingStatus() != ll::GamingStatus::Stopping) {
188190
CallEvent(EVENT_TYPES::onLeft, PlayerClass::newPlayer(&ev.self())); // Not cancellable
189191
}
190192
}

src/legacy/engine/EngineOwnData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include "legacy/main/Global.h"
3-
#include "lse/Plugin.h"
3+
#include "lse/ScriptPlugin.h"
44
#include "utils/UsingScriptX.h"
55

66
#include <ll/api/Expected.h>
@@ -34,7 +34,7 @@ struct EngineOwnData {
3434
ll::i18n::I18n i18n;
3535
std::string defaultLocaleName;
3636

37-
std::shared_ptr<lse::Plugin> plugin;
37+
std::shared_ptr<lse::ScriptPlugin> plugin;
3838

3939
// Use standalone logger in EngineOwnData instead of plugin.getLogger() for allowing modify logger title.
4040
std::shared_ptr<ll::io::Logger> logger;

src/lse/Entry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void loadDebugEngine(const ll::mod::NativeMod& self) {
151151
// Init plugin instance for debug engine to prevent something unexpected.
152152
ll::mod::Manifest manifest;
153153
manifest.name = "DebugEngine";
154-
getEngineOwnData()->plugin = std::make_shared<lse::Plugin>(manifest);
154+
getEngineOwnData()->plugin = std::make_shared<lse::ScriptPlugin>(manifest);
155155
// Init logger
156156
getEngineOwnData()->logger = ll::io::LoggerRegistry::getInstance().getOrCreate("DebugEngine");
157157

src/lse/Entry.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ class LegacyScriptEngine {
2424

2525
bool enable();
2626

27-
// bool disable();
28-
29-
// bool unload();
30-
3127
private:
3228
ll::mod::NativeMod& mSelf;
3329
Config config; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
#include "lse/Plugin.h"
2-
3-
#include "lse/Entry.h"
41
#include "legacy/engine/EngineOwnData.h"
52
#include "ll/api/mod/Manifest.h"
63
#include "ll/api/mod/Mod.h"
4+
#include "lse/Entry.h"
5+
#include "lse/ScriptPlugin.h"
76

87
namespace lse {
98

10-
Plugin::Plugin(ll::mod::Manifest manifest) : ll::mod::Mod(std::move(manifest)) {}
9+
ScriptPlugin::ScriptPlugin(ll::mod::Manifest manifest) : ll::mod::Mod(std::move(manifest)) {}
1110

12-
Plugin::~Plugin() { release(); }
11+
ScriptPlugin::~ScriptPlugin() { release(); }
1312

14-
std::shared_ptr<ll::mod::Mod> Plugin::current() {
13+
std::shared_ptr<ll::mod::Mod> ScriptPlugin::current() {
1514
return lse::LegacyScriptEngine::getInstance().getManager().getMod(getEngineOwnData()->pluginName);
1615
}
1716
} // namespace lse
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace lse {
99

10-
class Plugin : public ll::mod::Mod {
10+
class ScriptPlugin : public ll::mod::Mod {
1111
friend PluginManager;
1212

1313
public:
@@ -22,8 +22,8 @@ class Plugin : public ll::mod::Mod {
2222

2323
std::unordered_map<std::string, std::vector<ParamInfo>> registeredCommands;
2424

25-
explicit Plugin(ll::mod::Manifest manifest);
26-
~Plugin();
25+
explicit ScriptPlugin(ll::mod::Manifest manifest);
26+
~ScriptPlugin();
2727

2828
static std::shared_ptr<ll::mod::Mod> current();
2929
};

0 commit comments

Comments
 (0)