Skip to content

Commit

Permalink
feat(python): CommandSender class now inherits from the `Permissibl…
Browse files Browse the repository at this point in the history
…e` base class
  • Loading branch information
wu-vincent committed Mar 14, 2024
1 parent d8663f7 commit bbd3999
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
23 changes: 11 additions & 12 deletions 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', 'Permissible', 'PermissionDefault', 'Plugin', 'PluginCommand', 'PluginDescription', 'PluginLoader', 'PluginManager', 'Server', 'ServerOperator']
__all__ = ['ColorFormat', 'Command', 'CommandExecutor', 'CommandSender', 'Logger', 'Permissible', 'PermissionDefault', 'Plugin', 'PluginCommand', 'PluginDescription', 'PluginLoader', 'PluginManager', 'Server']
class ColorFormat:
AQUA: typing.ClassVar[str] = '§b'
BLACK: typing.ClassVar[str] = '§0'
Expand Down Expand Up @@ -98,7 +98,7 @@ class CommandExecutor:
"""
Executes the given command, returning its success.
"""
class CommandSender:
class CommandSender(Permissible):
def send_message(self, message: str) -> None:
"""
Sends this sender a message
Expand Down Expand Up @@ -206,7 +206,7 @@ class Logger:
"""
Get the name of this Logger instance.
"""
class Permissible(ServerOperator):
class Permissible:
@typing.overload
def add_attachment(self, plugin: Plugin, name: str, value: bool) -> ...:
"""
Expand Down Expand Up @@ -250,6 +250,14 @@ class Permissible(ServerOperator):
"""
Gets effective permissions.
"""
@property
def op(self) -> bool:
"""
The operator status of this object
"""
@op.setter
def op(self, arg1: bool) -> None:
...
class PermissionDefault:
"""
Members:
Expand Down Expand Up @@ -483,12 +491,3 @@ class Server:
"""
Gets the version of this server implementation.
"""
class ServerOperator:
@property
def op(self) -> bool:
"""
The operator status of this object
"""
@op.setter
def op(self, arg1: bool) -> None:
...
3 changes: 1 addition & 2 deletions src/endstone_python/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class PyCommandExecutor : public CommandExecutor {

void init_command(py::module &m)
{
// TODO: add base class Permissible
py::class_<CommandSender>(m, "CommandSender")
py::class_<CommandSender, Permissible>(m, "CommandSender")
.def(
"send_message",
[](const CommandSender &sender, const std::string &message) { sender.sendMessage(message); },
Expand Down
7 changes: 5 additions & 2 deletions src/endstone_python/endstone_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <pybind11/pybind11.h>

#include "endstone/permissions/permissible.h"
#include "endstone/server.h"

namespace py = pybind11;
Expand All @@ -23,7 +24,7 @@ namespace endstone::detail {
void init_command(py::module_ &);
void init_logger(py::module_ &);
void init_plugin(py::module_ &);
void init_permissions(py::module_ &);
void init_permissions(py::module_ &, py::class_<Permissible> &permissible);
void init_server(py::class_<Server> &server);
void init_util(py::module_ &);

Expand All @@ -33,10 +34,12 @@ PYBIND11_MODULE(endstone_python, m) // NOLINT(*-use-anonymous-namespace)
// Forward declaration, see:
// https://pybind11.readthedocs.io/en/stable/advanced/misc.html#avoiding-c-types-in-docstrings
auto server = py::class_<Server>(m, "Server");
auto permissible = py::class_<Permissible>(m, "Permissible");

init_command(m);
init_logger(m);
init_plugin(m);
init_permissions(m);
init_permissions(m, permissible);
init_server(server);
init_util(m);
}
Expand Down
8 changes: 2 additions & 6 deletions src/endstone_python/permissions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@
#include "endstone/permissions/permission_attachment.h"
#include "endstone/permissions/permission_attachment_info.h"
#include "endstone/permissions/permission_default.h"
#include "endstone/permissions/server_operator.h"
#include "endstone/plugin/plugin.h"

namespace py = pybind11;

namespace endstone::detail {

void init_permissions(py::module &m)
void init_permissions(py::module &m, py::class_<Permissible> &permissible)
{
py::class_<ServerOperator>(m, "ServerOperator")
.def_property("op", &ServerOperator::isOp, &ServerOperator::setOp, "The operator status of this object");

py::enum_<PermissionDefault>(m, "PermissionDefault")
.value("TRUE", PermissionDefault::True)
.value("FALSE", PermissionDefault::False)
Expand All @@ -41,7 +37,7 @@ void init_permissions(py::module &m)
.value("NOT_OP", PermissionDefault::Operator)
.value("NOT_OPERATOR", PermissionDefault::NotOperator);

py::class_<Permissible, ServerOperator>(m, "Permissible")
permissible.def_property("op", &Permissible::isOp, &Permissible::setOp, "The operator status of this object")
.def("is_permission_set", py::overload_cast<std::string>(&Permissible::isPermissionSet, py::const_),
py::arg("name"), "Checks if a permissions is set by name.")
.def("is_permission_set", py::overload_cast<const Permission &>(&Permissible::isPermissionSet, py::const_),
Expand Down

0 comments on commit bbd3999

Please sign in to comment.