Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src-client/lse/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ bool LLSECallEventsOnUnload(std::shared_ptr<ScriptEngine> const& engine);

namespace lse {

PluginManager::PluginManager() : ll::mod::ModManager(PluginManagerName) {}
PluginManager::PluginManager(std::filesystem::path loadDirectory)
: ll::mod::ModManager(PluginManagerName, std::move(loadDirectory)) {}
PluginManager::~PluginManager() = default;

void PluginManager::enableAllPlugins() {
Expand All @@ -79,7 +80,7 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
return ll::makeStringError("Plugin has already loaded");
}

auto plugin = std::make_shared<ScriptPlugin>(manifest);
auto plugin = std::make_shared<ScriptPlugin>(manifest, getLoadDirectory());

return plugin->onLoad().transform([&, this] { addMod(manifest.name, plugin); });
}
Expand All @@ -92,7 +93,8 @@ ll::Expected<> PluginManager::enableScriptPlugin(std::string_view name, bool isH
auto manifest = plugin->getManifest();
#ifdef LSE_BACKEND_PYTHON
auto& logger = lse::LegacyScriptEngine::getLogger();
std::filesystem::path dirPath = ll::mod::getModsRoot() / manifest.name; // Plugin path
std::filesystem::path dirPath = LegacyScriptEngine::getInstance().getManager().getLoadDirectory()
/ ll::string_utils::str2u8str(manifest.name); // Plugin path
std::string entryPath =
PythonHelper::findEntryScript(ll::string_utils::u8str2str(dirPath.u8string())); // Plugin entry
// if (entryPath.empty()) return false;
Expand Down Expand Up @@ -127,7 +129,8 @@ ll::Expected<> PluginManager::enableScriptPlugin(std::string_view name, bool isH
#endif
#ifdef LSE_BACKEND_NODEJS
auto& logger = lse::LegacyScriptEngine::getLogger();
std::filesystem::path dirPath = ll::mod::getModsRoot() / manifest.name; // Plugin path
std::filesystem::path dirPath = LegacyScriptEngine::getInstance().getManager().getLoadDirectory()
/ ll::string_utils::str2u8str(manifest.name); // Plugin path
// std::string entryPath = NodeJsHelper::findEntryScript(dirPath.string()); // Plugin entry
// if (entryPath.empty()) return false;
// std::string pluginName = NodeJsHelper::getPluginPackageName(dirPath.string()); // Plugin name
Expand Down
2 changes: 1 addition & 1 deletion src-client/lse/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace lse {

class PluginManager final : public ll::mod::ModManager {
public:
PluginManager();
explicit PluginManager(std::filesystem::path loadDirectory);
~PluginManager() override;
void enableAllPlugins();
void disableAllPlugins();
Expand Down
11 changes: 7 additions & 4 deletions src-server/lse/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ bool LLSECallEventsOnUnload(std::shared_ptr<ScriptEngine> const& engine);

namespace lse {

PluginManager::PluginManager() : ll::mod::ModManager(PluginManagerName) {}
PluginManager::PluginManager(std::filesystem::path loadDirectory)
: ll::mod::ModManager(PluginManagerName, std::move(loadDirectory)) {}
PluginManager::~PluginManager() = default;

ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
#ifdef LSE_BACKEND_PYTHON
auto& logger = lse::LegacyScriptEngine::getLogger();
std::filesystem::path dirPath = ll::mod::getModsRoot() / manifest.name; // Plugin path
std::filesystem::path dirPath = LegacyScriptEngine::getInstance().getManager().getLoadDirectory()
/ ll::string_utils::str2u8str(manifest.name); // Plugin path
std::string entryPath =
PythonHelper::findEntryScript(ll::string_utils::u8str2str(dirPath.u8string())); // Plugin entry
// if (entryPath.empty()) return false;
Expand Down Expand Up @@ -96,7 +98,8 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
#endif
#ifdef LSE_BACKEND_NODEJS
auto& logger = lse::LegacyScriptEngine::getLogger();
std::filesystem::path dirPath = ll::mod::getModsRoot() / manifest.name; // Plugin path
std::filesystem::path dirPath = LegacyScriptEngine::getInstance().getManager().getLoadDirectory()
/ ll::string_utils::str2u8str(manifest.name); // Plugin path
// std::string entryPath = NodeJsHelper::findEntryScript(dirPath.string()); // Plugin entry
// if (entryPath.empty()) return false;
// std::string pluginName = NodeJsHelper::getPluginPackageName(dirPath.string()); // Plugin name
Expand Down Expand Up @@ -124,7 +127,7 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
}

auto scriptEngine = EngineManager::newEngine(manifest.name);
auto plugin = std::make_shared<ScriptPlugin>(manifest);
auto plugin = std::make_shared<ScriptPlugin>(manifest, getLoadDirectory());

try {
EngineScope engineScope(scriptEngine.get());
Expand Down
2 changes: 1 addition & 1 deletion src-server/lse/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace lse {

class PluginManager final : public ll::mod::ModManager {
public:
PluginManager();
explicit PluginManager(std::filesystem::path loadDirectory);
~PluginManager() override;

private:
Expand Down
6 changes: 5 additions & 1 deletion src/legacy/api/LlAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#include "ll/api/mod/ModManagerRegistry.h"
#include "ll/api/reflection/Serialization.h"
#include "ll/api/utils/SystemUtils.h"
#include "lse/Entry.h"

#include <string>


//////////////////// Classes ////////////////////

ClassDefine<void> LlClassBuilder = defineClass("ll")
Expand Down Expand Up @@ -160,7 +162,7 @@ Local<Value> LlClass::getVersionStatus() {

Local<Value> LlClass::getPluginsRoot() {
try {
return String::newString(ll::mod::getModsRoot().u8string());
return String::newString(lse::LegacyScriptEngine::getInstance().getManager().getLoadDirectory().u8string());
}
CATCH_AND_THROW
}
Expand Down Expand Up @@ -392,6 +394,8 @@ Local<Value> LlClass::getAllPluginInfo(Arguments const&) {
pluginObject.set("others", others);
}

pluginObject.set("modDir", ll::string_utils::u8str2str(mod.getModDir().u8string()));

// Add plugin object to list
plugins.add(pluginObject);
}
Expand Down
9 changes: 7 additions & 2 deletions src/lse/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ constexpr auto BaseLibFileName = "BaseLib.py";

#endif

constexpr auto PluginsRootDir = "./plugins";

using namespace ll::i18n_literals;

// Do not use legacy headers directly, otherwise there will be tons of errors.
Expand Down Expand Up @@ -105,7 +107,7 @@ bool LegacyScriptEngine::load() {
auto result = ll::i18n::getInstance().load(getSelf().getLangDir());

config = Config();
pluginManager = std::make_shared<PluginManager>();
pluginManager = std::make_shared<PluginManager>(PluginsRootDir);

loadConfig(getSelf(), config);

Expand Down Expand Up @@ -163,7 +165,10 @@ void loadDebugEngine(ll::mod::NativeMod const& self) {
// Init plugin instance for debug engine to prevent something unexpected.
ll::mod::Manifest manifest;
manifest.name = "DebugEngine";
getEngineOwnData()->plugin = std::make_shared<lse::ScriptPlugin>(manifest);
getEngineOwnData()->plugin = std::make_shared<lse::ScriptPlugin>(
manifest,
LegacyScriptEngine::getInstance().getManager().getLoadDirectory()
);
// Init logger
getEngineOwnData()->logger = ll::io::LoggerRegistry::getInstance().getOrCreate("DebugEngine");

Expand Down
4 changes: 2 additions & 2 deletions src/lse/PluginMigration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ auto migratePlugin(PluginManager const& pluginManager, std::filesystem::path con

auto const& pluginFileName = path.filename();
auto const& pluginFileBaseName = path.stem();
auto const& pluginDir = ll::mod::getModsRoot() / pluginFileBaseName;
auto const& pluginDir = LegacyScriptEngine::getInstance().getManager().getLoadDirectory() / pluginFileBaseName;

if (std::filesystem::exists(pluginDir / pluginFileName)) {
throw std::runtime_error(
Expand Down Expand Up @@ -126,7 +126,7 @@ auto migratePlugins(PluginManager const& pluginManager) -> void {
// Discover plugins.
// logger.info("Discovering legacy plugins..."_tr());

auto const& pluginBaseDir = ll::mod::getModsRoot();
auto const& pluginBaseDir = LegacyScriptEngine::getInstance().getManager().getLoadDirectory();

for (auto const& entry : std::filesystem::directory_iterator(pluginBaseDir)) {
if (!entry.is_regular_file() || entry.path().extension() != PluginExtName) {
Expand Down
3 changes: 2 additions & 1 deletion src/lse/ScriptPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

namespace lse {

ScriptPlugin::ScriptPlugin(ll::mod::Manifest manifest) : ll::mod::Mod(std::move(manifest)) {}
ScriptPlugin::ScriptPlugin(ll::mod::Manifest manifest, std::filesystem::path loadDirectory)
: ll::mod::Mod(std::move(manifest), std::move(loadDirectory)) {}

ScriptPlugin::~ScriptPlugin() { release(); }

Expand Down
2 changes: 1 addition & 1 deletion src/lse/ScriptPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ScriptPlugin : public ll::mod::Mod {

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

explicit ScriptPlugin(ll::mod::Manifest manifest);
explicit ScriptPlugin(ll::mod::Manifest manifest, std::filesystem::path loadDirectory);
~ScriptPlugin();

static std::shared_ptr<ll::mod::Mod> current();
Expand Down
1 change: 1 addition & 0 deletions src/lse/events/BlockEventsHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "legacy/api/PlayerAPI.h"
#include "ll/api/memory/Hook.h"
#include "lse/api/Thread.h"
#include "mc/scripting/modules/minecraft/events/ScriptBlockBreakingEventListener.h"
#include "mc/scripting/modules/minecraft/events/ScriptBlockGlobalEventListener.h"
#include "mc/server/commands/CommandOrigin.h"
#include "mc/server/commands/CommandOriginType.h"
Expand Down
5 changes: 2 additions & 3 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ add_rules("mode.debug", "mode.release")

add_repositories("levimc-repo " .. (get_config("levimc_repo") or "https://github.com/LiteLDev/xmake-repo.git"))

add_requires("levilamina 26.51.*", {configs = {target_type = get_config("target_type")}})

add_requires("levilamina feat/custom-mod-directories", {configs = {target_type = get_config("target_type")}})
add_requires("levibuildscript")

add_requires("legacyremotecall 0.22.*", {configs = {target_type = get_config("target_type")}})
Expand Down Expand Up @@ -65,7 +64,7 @@ option("backend")
target("LegacyScriptEngine")
add_rules("@levibuildscript/linkrule")
if is_plat("windows") then
add_defines("NOMINMAX", "UNICODE", "_AMC64_")
add_defines("NOMINMAX", "UNICODE", "_AMC64_", "_HAS_CXX23=1")
set_exceptions("none") -- To avoid conflicts with /EHa.
add_cxflags( "/EHa", "/utf-8", "/W4", "/w44265", "/w44289", "/w44296", "/w45263", "/w44738", "/w45204")
add_cxflags(
Expand Down
Loading