Skip to content

Commit 6bc5b02

Browse files
authored
Merge pull request #199 from JulienLavocat/main
GH-198 Add guide to send notifications
2 parents 7f4ebbf + 2bffd27 commit 6bc5b02

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "Sending notifications"
3+
description: "Learn how to send notifications (similar to item pickup) with your Hytale Plugin"
4+
authors:
5+
- name: "BeerBag"
6+
---
7+
8+
## Overview
9+
10+
In this guide, you will learn how to send notifications to players, similar to
11+
the notification received when picking up an item from the ground.
12+
13+
![notification-example](/assets/guides/notification-example.png)
14+
15+
## Structure of a Notification
16+
17+
A notification consists of three main components:
18+
19+
1. **Primary Message**: The main `Message` displayed in the notification.
20+
2. **Secondary Message**: Additional `Message`, displayed below the primary message.
21+
3. **Icon**: An item icon that visually represents the notification, shown on
22+
the left side.
23+
24+
## Sending Notifications
25+
26+
You can use the `NotificationUtil` class to send notifications to players.
27+
You will need access to the `PacketHandler` of the player, which can be obtained
28+
from the `PlayerRef` using the `getPacketHandler()` method (in this example,
29+
we get the `PlayerRef` from the `Universe` using the player's UUID).
30+
31+
```java
32+
public static void onPlayerReady(PlayerReadyEvent event) {
33+
var player = event.getPlayer();
34+
35+
var playerRef = Universe.get().getPlayer(player.getUuid());
36+
var packetHandler = playerRef.getPacketHandler();
37+
38+
var primaryMessage = Message.raw("THIS WORKS!!!").color("#00FF00");
39+
var secondaryMessage = Message.raw("This is the secondary message").color("#228B22");
40+
var icon = new ItemStack("Weapon_Sword_Mithril", 1).toPacket();
41+
42+
NotificationUtil.sendNotification(
43+
packetHandler,
44+
primaryMessage,
45+
secondaryMessage,
46+
(ItemWithAllMetadata) icon);
47+
}
48+
```
94 KB
Loading

0 commit comments

Comments
 (0)