Skip to content

Commit

Permalink
fix: python plugin's on_command not getting called
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Mar 7, 2024
1 parent a6bcee8 commit 96f657a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion include/endstone/plugin/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ class PluginCommand : public Command {
return getExecutor().onCommand(sender, *this, args);
}
catch (std::exception &e) {
getPlugin().getLogger().error("Cannot execute command '{}'. {}", getName(), e.what());
getPlugin().getLogger().error("Unhandled exception executing command '{}' in plugin {}", getName(),
owner_.getDescription().getFullName());
getPlugin().getLogger().error(e.what());
return false;
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/endstone_python/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ class PyCommandExecutor : public CommandExecutor {
public:
using CommandExecutor::CommandExecutor;

bool onCommand(const endstone::CommandSender &sender, const endstone::Command &command,
const std::vector<std::string> &args) override
bool onCommand(const CommandSender &sender, const Command &command, const std::vector<std::string> &args) override
{
PYBIND11_OVERRIDE_NAME(bool, endstone::CommandExecutor, "on_command", onCommand, std::ref(sender),
std::ref(command), std::ref(args));
PYBIND11_OVERRIDE_NAME(bool, CommandExecutor, "on_command", onCommand, std::ref(sender), std::ref(command),
std::ref(args));
}
};

Expand Down Expand Up @@ -78,13 +77,13 @@ void init_command(py::module &m)
"usages", &Command::getUsages,
[](Command &self, const std::vector<std::string> &usages) { self.setUsages(usages); },
"List of usages of this command")
.def_property_readonly("registered", &endstone::Command::isRegistered,
.def_property_readonly("registered", &Command::isRegistered,
"Returns the current registered state of this command");

py_class<CommandExecutor, PyCommandExecutor, std::shared_ptr<CommandExecutor>>(m, "CommandExecutor")
.def(py::init<>())
.def("on_command", &endstone::CommandExecutor::onCommand, py::arg("sender"), py::arg("command"),
py::arg("args"), "Executes the given command, returning its success.");
.def("on_command", &CommandExecutor::onCommand, py::arg("sender"), py::arg("command"), py::arg("args"),
"Executes the given command, returning its success.");
}

} // namespace endstone::detail
6 changes: 6 additions & 0 deletions src/endstone_python/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class PyPlugin : public Plugin {
getLogger().error(e.what());
}
}

bool onCommand(const CommandSender &sender, const Command &command, const std::vector<std::string> &args) override
{
PYBIND11_OVERRIDE_NAME(bool, Plugin, "on_command", onCommand, std::ref(sender), std::ref(command),
std::ref(args));
}
};

class PyPluginLoader : public PluginLoader {
Expand Down

0 comments on commit 96f657a

Please sign in to comment.