From 71a14ffc53f0d77ce7a6d661ee03066f897c8646 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 8 Aug 2024 11:18:04 +0100 Subject: [PATCH] feat: add python bindings for Server::reload --- include/endstone/logger.h | 7 ++++++- include/endstone/server.h | 7 ++++++- python/src/endstone/_internal/endstone_python.pyi | 8 ++++++++ src/endstone_python/endstone_python.cpp | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/endstone/logger.h b/include/endstone/logger.h index beecbf2b4..30500d84b 100644 --- a/include/endstone/logger.h +++ b/include/endstone/logger.h @@ -77,7 +77,12 @@ class Logger { template void log(Level level, const fmt::format_string format, Args &&...args) const { - log(level, fmt::format(format, std::forward(args)...)); + try { + log(level, fmt::format(format, std::forward(args)...)); + } + catch (std::exception &e) { + log(Error, e.what()); + } } template diff --git a/include/endstone/server.h b/include/endstone/server.h index fb6725936..8fc933a0b 100644 --- a/include/endstone/server.h +++ b/include/endstone/server.h @@ -189,7 +189,12 @@ class Server { template void broadcastMessage(const fmt::format_string format, Args &&...args) const { - broadcastMessage(fmt::format(format, std::forward(args)...)); + try { + broadcastMessage(fmt::format(format, std::forward(args)...)); + } + catch (std::exception &e) { + getLogger().log(Logger::Error, e.what()); + } } /** diff --git a/python/src/endstone/_internal/endstone_python.pyi b/python/src/endstone/_internal/endstone_python.pyi index 87e3f614b..da5d366b1 100644 --- a/python/src/endstone/_internal/endstone_python.pyi +++ b/python/src/endstone/_internal/endstone_python.pyi @@ -2057,6 +2057,14 @@ class Server: """ Gets a PluginCommand with the given name or alias. """ + def reload(self) -> None: + """ + Reloads the server configuration, functions, scripts and plugins. + """ + def reload_data(self) -> None: + """ + Reload only the Minecraft data for the server. + """ def shutdown(self) -> None: """ Shutdowns the server, stopping everything. diff --git a/src/endstone_python/endstone_python.cpp b/src/endstone_python/endstone_python.cpp index a0c427c3d..7fd27f932 100644 --- a/src/endstone_python/endstone_python.cpp +++ b/src/endstone_python/endstone_python.cpp @@ -229,6 +229,8 @@ void init_server(py::class_ &server) py::arg("unique_id").noconvert(), py::return_value_policy::reference, "Gets the player with the given UUID.") .def("shutdown", &Server::shutdown, "Shutdowns the server, stopping everything.") + .def("reload", &Server::reload, "Reloads the server configuration, functions, scripts and plugins.") + .def("reload_data", &Server::reloadData, "Reload only the Minecraft data for the server.") .def("broadcast", &Server::broadcast, py::arg("message"), py::arg("permission"), "Broadcasts the specified message to every user with the given permission name.") .def(