From 86f72dba0eb0e7821aea5aa3d392aef0975a2e35 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 5 Mar 2024 05:01:40 +0000 Subject: [PATCH] feat: add 'name' property to Plugin class --- include/endstone/plugin/plugin.h | 13 +++++++++++++ python/src/endstone/plugin.pyi | 2 ++ src/endstone_python/plugin/plugin.cpp | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/endstone/plugin/plugin.h b/include/endstone/plugin/plugin.h index 536c10c5b..f7797f49c 100644 --- a/include/endstone/plugin/plugin.h +++ b/include/endstone/plugin/plugin.h @@ -99,6 +99,19 @@ class Plugin : public CommandExecutor { return *server_; } + /** + * Returns the name of the plugin. + * + * This should return the bare name of the plugin and should be used for + * comparison. + * + * @return name of the plugin + */ + [[nodiscard]] std::string getName() const + { + return getDescription().getName(); + }; + private: friend class PluginLoader; diff --git a/python/src/endstone/plugin.pyi b/python/src/endstone/plugin.pyi index db8c37d3d..026481ff2 100644 --- a/python/src/endstone/plugin.pyi +++ b/python/src/endstone/plugin.pyi @@ -50,6 +50,8 @@ class Plugin: def plugin_loader(self) -> PluginLoader: ... @property def server(self) -> Server: ... + @property + def name(self) -> str: ... class PluginManager: def register_loader(self, loader: PluginLoader) -> None: ... diff --git a/src/endstone_python/plugin/plugin.cpp b/src/endstone_python/plugin/plugin.cpp index 02c47b6d7..73d12bea1 100644 --- a/src/endstone_python/plugin/plugin.cpp +++ b/src/endstone_python/plugin/plugin.cpp @@ -85,7 +85,8 @@ void def_plugin(py::module &m) .def_property_readonly("logger", &Plugin::getLogger, py::return_value_policy::reference) .def_property_readonly("plugin_loader", &Plugin::getPluginLoader, py::return_value_policy::reference) .def_property_readonly("server", &Plugin::getServer, py::return_value_policy::reference) - .def_property_readonly("enabled", &Plugin::isEnabled); + .def_property_readonly("enabled", &Plugin::isEnabled) + .def_property_readonly("name", &Plugin::getName); } } // namespace endstone::detail