| 19 | namespace endstone::python { |
| 20 | |
| 21 | void init_event(py::module_ &m, py::class_<Event> &event) |
| 22 | { |
| 23 | py::native_enum<EventResult>(m, "EventResult", "enum.Enum") |
| 24 | .value("DENY", EventResult::Deny) |
| 25 | .value("DEFAULT", EventResult::Default) |
| 26 | .value("ALLOW", EventResult::Allow) |
| 27 | .finalize(); |
| 28 | |
| 29 | event.def_property_readonly("event_name", &Event::getEventName, "Gets a user-friendly identifier for this event.") |
| 30 | .def_property_readonly("is_asynchronous", &Event::isAsynchronous, "Whether the event fires asynchronously."); |
| 31 | |
| 32 | py::class_<ICancellable>(m, "Cancellable", "Represents an event that may be cancelled by a plugin or the server.") |
| 33 | .def_property( |
| 34 | "cancelled", |
| 35 | [](const ICancellable &self) { |
| 36 | PyErr_WarnEx(PyExc_FutureWarning, |
| 37 | "The event.cancelled property is deprecated and will be removed from endstone in a future " |
| 38 | "version. Use event.is_cancelled instead.", |
| 39 | 1); |
| 40 | return self.isCancelled(); |
| 41 | }, |
| 42 | [](ICancellable &self, const bool value) { |
| 43 | PyErr_WarnEx(PyExc_FutureWarning, |
| 44 | "The event.cancelled property is deprecated and will be removed from endstone in a future " |
| 45 | "version. Use event.is_cancelled instead.", |
| 46 | 1); |
| 47 | self.setCancelled(value); |
| 48 | }, |
| 49 | "Gets or sets the cancellation state of this event. A cancelled event will not be executed in " |
| 50 | "the server, but will still pass to other plugins. [Warning] Deprecated: Use is_cancelled instead.") |
| 51 | .def_property("is_cancelled", &ICancellable::isCancelled, &ICancellable::setCancelled, |
| 52 | "Gets or sets the cancellation state of this event. A cancelled event will not be executed in " |
| 53 | "the server, but will still pass to other plugins.") |
| 54 | .def("cancel", &ICancellable::cancel, |
| 55 | "Cancel this event. A cancelled event will not be executed in the server, but will still pass to other " |
| 56 | "plugins."); |
| 57 | |
| 58 | // Actor events |
| 59 | py::class_<ActorEvent<Actor>, Event>(m, "ActorEvent", "Represents an Actor-related event.") |
| 60 | .def_property_readonly("actor", &ActorEvent<Actor>::getActor, py::return_value_policy::reference, |
| 61 | "Returns the Actor involved in this event"); |
| 62 | py::class_<ActorEvent<Mob>, Event>(m, "MobEvent", "Represents an Mob-related event.") |
| 63 | .def_property_readonly("actor", &ActorEvent<Mob>::getActor, py::return_value_policy::reference, |
| 64 | "Returns the Mob involved in this event"); |
| 65 | py::class_<ActorDamageEvent, ActorEvent<Mob>, ICancellable>(m, "ActorDamageEvent", |
| 66 | "Called when an Actor is damaged.") |
| 67 | .def_property("damage", &ActorDamageEvent::getDamage, &ActorDamageEvent::setDamage, |
| 68 | "Gets or sets the amount of damage caused by the event") |
| 69 | .def_property_readonly("damage_source", &ActorDamageEvent::getDamageSource, py::return_value_policy::reference, |
| 70 | "Gets the source of damage."); |
| 71 | py::class_<ActorDeathEvent, ActorEvent<Mob>>(m, "ActorDeathEvent", "Called when an Actor dies.") |
| 72 | .def_property_readonly("damage_source", &ActorDeathEvent::getDamageSource, py::return_value_policy::reference, |
| 73 | "Gets the source of damage which caused the death."); |
| 74 | py::class_<PlayerDeathEvent, ActorDeathEvent>(m, "PlayerDeathEvent", "Called when a player dies") |
| 75 | .def_property_readonly("player", &PlayerDeathEvent::getPlayer, py::return_value_policy::reference, |
| 76 | "Gets the Player that is breaking the block involved in this event.") |
| 77 | .def_property("death_message", &PlayerDeathEvent::getDeathMessage, &PlayerDeathEvent::setDeathMessage, |
| 78 | "Gets or sets the death message that will appear to everyone on the server."); |
no test coverage detected