Skip to content

Commit

Permalink
feat: add python bindings for Server::reload
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Aug 8, 2024
1 parent 26c6f00 commit 71a14ff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion include/endstone/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ class Logger {
template <typename... Args>
void log(Level level, const fmt::format_string<Args...> format, Args &&...args) const
{
log(level, fmt::format(format, std::forward<Args>(args)...));
try {
log(level, fmt::format(format, std::forward<Args>(args)...));
}
catch (std::exception &e) {
log(Error, e.what());
}
}

template <typename... Args>
Expand Down
7 changes: 6 additions & 1 deletion include/endstone/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ class Server {
template <typename... Args>
void broadcastMessage(const fmt::format_string<Args...> format, Args &&...args) const
{
broadcastMessage(fmt::format(format, std::forward<Args>(args)...));
try {
broadcastMessage(fmt::format(format, std::forward<Args>(args)...));
}
catch (std::exception &e) {
getLogger().log(Logger::Error, e.what());
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions python/src/endstone/_internal/endstone_python.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/endstone_python/endstone_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ void init_server(py::class_<Server> &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(
Expand Down

0 comments on commit 71a14ff

Please sign in to comment.