| 42 | } // namespace |
| 43 | |
| 44 | void init_command(py::module &m, py::class_<CommandSender, Permissible> &command_sender) |
| 45 | { |
| 46 | command_sender |
| 47 | .def( |
| 48 | "send_message", [](const CommandSender &self, const Message &message) { self.sendMessage(message); }, |
| 49 | py::arg("message"), "Sends this sender a message") |
| 50 | .def( |
| 51 | "send_error_message", |
| 52 | [](const CommandSender &self, const Message &message) { self.sendErrorMessage(message); }, |
| 53 | py::arg("message"), "Sends this sender an error message") |
| 54 | .def_property_readonly("server", &CommandSender::getServer, py::return_value_policy::reference, |
| 55 | "Returns the server instance that this command is running on") |
| 56 | .def_property_readonly("name", &CommandSender::getName, "Gets the name of this command sender"); |
| 57 | |
| 58 | py::class_<BlockCommandSender, CommandSender>(m, "BlockCommandSender", "Represents a block command sender.") |
| 59 | .def_property_readonly("block", &BlockCommandSender::getBlock, |
| 60 | "Returns the block this command sender belongs to"); |
| 61 | |
| 62 | py::class_<CommandSenderWrapper, CommandSender>( |
| 63 | m, "CommandSenderWrapper", |
| 64 | "Represents a wrapper that forwards commands to the wrapped CommandSender and captures its output") |
| 65 | .def(py::init<CommandSender &, CommandSenderWrapper::Callback, CommandSenderWrapper::Callback>(), |
| 66 | py::arg("sender"), py::arg("on_message") = CommandSenderWrapper::Callback{}, |
| 67 | py::arg("on_error") = CommandSenderWrapper::Callback{}); |
| 68 | |
| 69 | py::class_<ConsoleCommandSender, CommandSender>(m, "ConsoleCommandSender", "Represents a console command sender."); |
| 70 | |
| 71 | py::class_<Command, std::shared_ptr<Command>>(m, "Command", |
| 72 | "Represents a Command, which executes various tasks upon user input") |
| 73 | .def(py::init(&createCommand), py::arg("name"), py::arg("description") = py::none(), |
| 74 | py::arg("usages") = py::none(), py::arg("aliases") = py::none(), py::arg("permissions") = py::none()) |
| 75 | .def("execute", &Command::execute, py::arg("sender"), py::arg("args"), |
| 76 | "Executes the command, returning its success") |
| 77 | .def("test_permission", &Command::testPermission, py::arg("target"), |
| 78 | "Tests the given CommandSender to see if they can perform this command.") |
| 79 | .def("test_permission_silently", &Command::testPermissionSilently, py::arg("target"), |
| 80 | "Tests the given CommandSender to see if they can perform this command. No error is sent to the sender.") |
| 81 | .def_property("name", &Command::getName, &Command::setName, "Name of this command.") |
| 82 | .def_property("description", &Command::getDescription, &Command::setDescription, |
| 83 | "Brief description of this command") |
| 84 | .def_property( |
| 85 | "aliases", &Command::getAliases, |
| 86 | [](Command &self, const std::vector<std::string> &aliases) { self.setAliases(aliases); }, |
| 87 | "List of aliases of this command") |
| 88 | .def_property( |
| 89 | "usages", &Command::getUsages, |
| 90 | [](Command &self, const std::vector<std::string> &usages) { self.setUsages(usages); }, |
| 91 | "List of usages of this command") |
| 92 | .def_property( |
| 93 | "permissions", &Command::getPermissions, |
| 94 | [](Command &self, const std::vector<std::string> &permissions) { self.setPermissions(permissions); }, |
| 95 | "The permissions required by users to be able to perform this command") |
| 96 | .def_property_readonly("is_registered", &Command::isRegistered, |
| 97 | "Returns the current registered state of this command"); |
| 98 | |
| 99 | py::class_<CommandExecutor, PyCommandExecutor, py::smart_holder>( |
| 100 | m, "CommandExecutor", "Represents a class which contains a single method for executing commands") |
| 101 | .def(py::init<>()) |
no test coverage detected