Skip to main content
Version: Next

Notification

info

Since v0.2-beta

Why use the notification system provided by MessageChain?

It might be not so useful, but I think it would be better to use different methods to process different messages, Instead of putting them together by invoking ServerPlayNetworking and ClientPlayNetworking.

It will improve code readability.

There might be moments when you want to push something to players, so we built a simple notification system.

Process

In short, refer to this link to view the example source code.

Client-side notification receiver registration

In NotificationManager, use the following method to register a notification receiver:

NotificationManager.getInstance().registerHandler(Identifier, AbstractNotificationHandler, boolean);

The last parameter indicates whether the notification receiver should be removed once it has been invoked.

Be aware that the receiver will run on the main thread instead of creating a new thread, and you have no other options so far.

Server-side notification push

On server side, use the following method to push a notification:

NotificationManager.getInstance().sendNotification(Identifier, TPayload, ServerPlayerEntity);

The receiver must be a game client.

There will be a method to broadcast notifications in future versions (maybe in v0.3-beta).

Remove an existing notification handler

To remove an existing notification handler, use the following method:

NotificationManager.getInstance().unregisterHandler(Identifier);