Skip to content

Commit

Permalink
fix: ensure the correct plugin loader is selected when loading from f…
Browse files Browse the repository at this point in the history
…ile (#110)

* fix: fix EndstonePluginManager::loadPlugin #98

* refactor: improve plugin loading logic in EndstonePluginManager

* refactor: revert back to range-based loop for plugin loading

---------

Co-authored-by: Vincent <[email protected]>
  • Loading branch information
engsr6982 and wu-vincent authored Dec 18, 2024
1 parent 9821ee5 commit bb56db7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/endstone_core/plugin/plugin_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ Plugin *EndstonePluginManager::loadPlugin(std::string file)
{
Plugin *result = nullptr;
for (const auto &loader : plugin_loaders_) {
if (auto *plugin = loader->loadPlugin(file); plugin) {
if (initPlugin(*plugin, *loader, fs::path(file).parent_path())) {
result = plugin;
for (const auto &pattern : loader->getPluginFileFilters()) {
if (std::regex r(pattern); std::regex_search(file, r)) {
if (auto *plugin = loader->loadPlugin(file); plugin) {
if (initPlugin(*plugin, *loader, fs::path(file).parent_path())) {
result = plugin;
}
break;
}
}
break;
}
}
return result;
Expand All @@ -104,7 +108,7 @@ std::vector<Plugin *> EndstonePluginManager::loadPlugins(std::string directory)
// TODO(plugin): handling logic for depend, soft_depend, load_before and provides
for (const auto &loader : plugin_loaders_) {
auto plugins = loader->loadPlugins(directory);
for (const auto &plugin : plugins) {
for (auto *plugin : plugins) {
if (!plugin) {
continue;
}
Expand Down

0 comments on commit bb56db7

Please sign in to comment.