MCPcopy Create free account
hub / github.com/EndstoneMC/endstone / init_event

Function init_event

src/endstone/python/event.cpp:21–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19namespace endstone::python {
20
21void 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.");

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 8

valueMethod · 0.80
setCancelledMethod · 0.80
isCancelledMethod · 0.45
getMethod · 0.45
clearMethod · 0.45
cloneMethod · 0.45
getPayloadMethod · 0.45
setPayloadMethod · 0.45

Tested by

no test coverage detected