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.

add_event(event: Type[Event]) None[source]#

Registers event on the client and starts running it.

get_event_instance(event: Event) Event | None[source]#

Gets the active instance of this event from the registered events pool in EventClient.

on_event(event: Events) None[source]#

Decorator that allows you to run a function when an event occurs on NovaUniverse network.

start() NoReturn[source]#

Runs client and starts listening to events.

stop()[source]#

Stops the client from running. ๐Ÿ˜If you can even get to this method.

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 the EventClient that the data has changed and it can trigger the event.

Returning False indicates to the EventClient that the data has not changed and it shouldnโ€™t trigger the event.

abstract trigger_event() None[source]#

This method is ran when NovaClient gets an indication that the data has changed from Event.loop.

class novauniverse.events.Event(event_name: str)[source]#

Bases: object

add_function(func: Callable)[source]#

Used by EventClient to add functions to events.

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}!")