Skip to content

Commit

Permalink
feat: add python binding for class PluginCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Mar 6, 2024
1 parent 15c1ad1 commit c247648
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
22 changes: 21 additions & 1 deletion python/src/endstone/_internal/endstone_python.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations
import typing
__all__ = ['ColorFormat', 'Command', 'CommandExecutor', 'CommandSender', 'Logger', 'Plugin', 'PluginDescription', 'PluginLoader', 'PluginManager', 'Server']
__all__ = ['ColorFormat', 'Command', 'CommandExecutor', 'CommandSender', 'Logger', 'Plugin', 'PluginCommand', 'PluginDescription', 'PluginLoader', 'PluginManager', 'Server']
class ColorFormat:
AQUA: typing.ClassVar[str] = '§b'
BLACK: typing.ClassVar[str] = '§0'
Expand Down Expand Up @@ -197,6 +197,10 @@ class Plugin(CommandExecutor):
...
def _get_description(self) -> PluginDescription:
...
def get_command(self, name: str) -> PluginCommand:
"""
Gets the command with the given name, specific to this plugin.
"""
def on_disable(self) -> None:
"""
Called when this plugin is disabled
Expand Down Expand Up @@ -234,6 +238,22 @@ class Plugin(CommandExecutor):
"""
Returns the Server instance currently running this plugin
"""
class PluginCommand(Command):
def __init__(self, command: Command, owner: Plugin) -> None:
...
@property
def executor(self) -> CommandExecutor:
"""
The CommandExecutor to run when parsing this command
"""
@executor.setter
def executor(self, arg1: CommandExecutor) -> None:
...
@property
def plugin(self) -> Plugin:
"""
Gets the owner of this PluginCommand
"""
class PluginDescription:
def __init__(self, name: str, version: str, description: str | None = None, authors: list[str] | None = None, prefix: str | None = None, *args, **kwargs) -> None:
...
Expand Down
2 changes: 1 addition & 1 deletion src/endstone_python/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PyCommandExecutor : public CommandExecutor {
bool onCommand(const endstone::CommandSender &sender, const endstone::Command &command,
const std::vector<std::string> &args) override
{
PYBIND11_OVERRIDE(bool, endstone::CommandExecutor, onCommand, sender, command, args);
PYBIND11_OVERRIDE_NAME(bool, endstone::CommandExecutor, "on_command", onCommand, sender, command, args);
}
};

Expand Down
12 changes: 11 additions & 1 deletion src/endstone_python/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ void init_plugin(py::module &m)

py_class<PluginLoader, PyPluginLoader>(m, "PluginLoader");

py_class<PluginCommand, Command>(m, "PluginCommand");

py_class<Plugin, CommandExecutor, PyPlugin>(m, "Plugin")
.def(py::init<>())
.def("on_load", &Plugin::onLoad, "Called after a plugin is loaded but before it has been enabled.")
Expand All @@ -136,7 +138,15 @@ void init_plugin(py::module &m)
"Returns the Server instance currently running this plugin")
.def_property_readonly("enabled", &Plugin::isEnabled,
"Returns a value indicating whether this plugin is currently enabled")
.def_property_readonly("name", &Plugin::getName, "Returns the name of the plugin.");
.def_property_readonly("name", &Plugin::getName, "Returns the name of the plugin.")
.def("get_command", &Plugin::getCommand, py::return_value_policy::reference, py::arg("name"),
"Gets the command with the given name, specific to this plugin.");

py_class<PluginCommand, Command>(m, "PluginCommand")
.def(py::init<const Command &, Plugin &>(), py::arg("command"), py::arg("owner"))
.def_property("executor", &PluginCommand::getExecutor, &PluginCommand::setExecutor,
"The CommandExecutor to run when parsing this command")
.def_property_readonly("plugin", &PluginCommand::getPlugin, "Gets the owner of this PluginCommand");

py_class<PluginLoader, PyPluginLoader>(m, "PluginLoader")
.def(py::init<Server &>(), py::arg("server"))
Expand Down

0 comments on commit c247648

Please sign in to comment.