Events ๐#
NovaUniverse.py being a feature rich api wrapper provides a collection of events that can be triggered by an action occurring on the Nova Universe Network. Like example a player joining the minecraft server.
This is how we register a player join event:
from novauniverse import EventClient, Events, NovaOnlinePlayer client = EventClient() @client.on_event(Events.PLAYER_JOIN) def on_player_join(player:NovaOnlinePlayer): print(f"{player.username} joined {player.server_name}!") client.start()If you would like to know the attributes of NovaOnlinePlayer, check this out: NovaOnlinePlayer.
EventClient Reference#
- class novauniverse.event_client.EventClient(debug=False)[source]#
Bases:
object
A basic NU.PY client used to listen into events on the network.
- get_event_instance(event: Event) Event | None [source]#
Gets the active instance of this event from the registered events pool in
EventClient
.
Events Reference#
- class novauniverse.events.EndpointEvent(event_name, endpoint: str | None)[source]#
Bases:
ABC
,Event
Allows you to easily create events from NovaUniverse.py endpoints.
- endpoint#
The eventโs endpoint. ๐
- abstract loop(data: dict | None) bool [source]#
This method is called each
EventClient
๐heartbeat if the event is in use. You will have to handle this to the accordance of your event.
Returning
True
indicates to theEventClient
that the data has changed and it can trigger the event.Returning
False
indicates to theEventClient
that the data has not changed and it shouldnโt trigger the event.
- class novauniverse.events.Events(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum
An enum class of all available events.
โญ Example:#
These can be used like so:
client = EventClient() @client.on_event(Events.CLIENT_READY) def client_is_ready(): print("Client is ready!") @client.on_event(Events.PLAYER_JOIN) def on_player_join(player:NovaOnlinePlayer): print(f"{player.username} joined {player.server_name}!") @client.on_event(Events.PLAYER_LEAVE) def on_player_join(player:NovaOnlinePlayer): print(f"{player.username} left {player.server_name}!") client.start()
- CLIENT_READY = <class 'novauniverse.events.client_ready.ClientReady'>#
Triggers when NovaClient is ready.
Used like so:
@client.on_event(Events.CLIENT_READY) def client_is_ready(): print("Client is ready!")
- PLAYER_JOIN = <class 'novauniverse.events.player_join.PlayerJoin'>#
Triggers each time a player joins any lobby on the Nova Universe network. Passes
NovaOnlinePlayer()
object to function.Used like so:
@client.on_event(Events.PLAYER_JOIN) def on_player_join(player: NovaOnlinePlayer): print(f"{player.username} joined {player.server_name}!")
- PLAYER_LEAVE = <class 'novauniverse.events.player_leave.PlayerLeave'>#
Triggers each time a player leaves any lobby on the Nova Universe network. Passes
NovaOnlinePlayer()
object to function.Used like so:
@client.on_event(Events.PLAYER_LEAVE) def on_player_join(player: NovaOnlinePlayer): print(f"{player.username} left {player.server_name}!")