Sends in-game notifications to players in Hytale plugins using NotificationUtil. Use when displaying item pickup-style notifications, toast messages, alert messages with icons, or any player notification with primary/secondary text. Triggers - notification, toast, alert, NotificationUtil, sendNotification, item pickup, player notification, message popup.
Use this skill when sending in-game notifications to players in Hytale plugins. Notifications appear similar to item pickup messages and consist of a primary message, secondary message, and an optional icon.
| Concept | Description |
|---|---|
| NotificationUtil | Utility class for sending notifications to players |
| Primary Message | Main Message displayed in the notification |
| Secondary Message | Additional Message displayed below the primary |
| Icon | An item icon shown on the left side of the notification |
| PacketHandler | Required to send notifications to a specific player |
A notification consists of three main components:
Message displayed prominently in the notificationMessage displayed below the primary messageimport com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.Universe;
import com.hypixel.hytale.server.item.ItemStack;
import com.hypixel.hytale.server.item.ItemWithAllMetadata;
import com.hypixel.hytale.server.player.PlayerRef;
import com.hypixel.hytale.server.util.NotificationUtil;
Use the NotificationUtil class to send notifications to players. You need access to the PacketHandler of the player.
The PacketHandler can be obtained from a PlayerRef using the getPacketHandler() method:
// From an event
PlayerRef playerRef = Universe.get().getPlayer(player.getUuid());
var packetHandler = playerRef.getPacketHandler();
| Parameter | Type | Description |
|---|---|---|
packetHandler | PacketHandler | The player's packet handler |
primaryMessage | Message | Main notification text |
secondaryMessage | Message | Secondary text below primary |
icon | ItemWithAllMetadata | Item icon to display |
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.Universe;
import com.hypixel.hytale.server.event.player.PlayerReadyEvent;
import com.hypixel.hytale.server.item.ItemStack;
import com.hypixel.hytale.server.item.ItemWithAllMetadata;
import com.hypixel.hytale.server.util.NotificationUtil;
public class NotificationExample {
public static void onPlayerReady(PlayerReadyEvent event) {
var player = event.getPlayer();
var playerRef = Universe.get().getPlayer(player.getUuid());
var packetHandler = playerRef.getPacketHandler();
// Create messages
var primaryMessage = Message.raw("THIS WORKS!!!").color("#00FF00");
var secondaryMessage = Message.raw("This is the secondary message").color("#228B22");
// Create icon from item
var icon = new ItemStack("Weapon_Sword_Mithril", 1).toPacket();
// Send notification
NotificationUtil.sendNotification(
packetHandler,
primaryMessage,
secondaryMessage,
(ItemWithAllMetadata) icon
);
}
}
public void sendAchievementNotification(PlayerRef playerRef, String achievement) {
var packetHandler = playerRef.getPacketHandler();
var primary = Message.raw("Achievement Unlocked!").color("#FFD700");
var secondary = Message.raw(achievement).color("#FFFFFF");
var icon = new ItemStack("Item_Trophy_Gold", 1).toPacket();
NotificationUtil.sendNotification(
packetHandler,
primary,
secondary,
(ItemWithAllMetadata) icon
);
}
public void sendItemReceivedNotification(PlayerRef playerRef, String itemId, int quantity) {
var packetHandler = playerRef.getPacketHandler();
var primary = Message.raw("Item Received").color("#00FF00");
var secondary = Message.raw("+" + quantity + " " + itemId).color("#AAAAAA");
var icon = new ItemStack(itemId, quantity).toPacket();
NotificationUtil.sendNotification(
packetHandler,
primary,
secondary,
(ItemWithAllMetadata) icon
);
}
public void sendWarningNotification(PlayerRef playerRef, String warning) {
var packetHandler = playerRef.getPacketHandler();
var primary = Message.raw("Warning!").color("#FF0000");
var secondary = Message.raw(warning).color("#FFAAAA");
var icon = new ItemStack("Item_Warning_Sign", 1).toPacket();
NotificationUtil.sendNotification(
packetHandler,
primary,
secondary,
(ItemWithAllMetadata) icon
);
}
public void sendLevelUpNotification(PlayerRef playerRef, int newLevel) {
var packetHandler = playerRef.getPacketHandler();
var primary = Message.raw("LEVEL UP!").color("#FFD700");
var secondary = Message.raw("You are now level " + newLevel).color("#FFFFFF");
var icon = new ItemStack("Item_Star", 1).toPacket();
NotificationUtil.sendNotification(
packetHandler,
primary,
secondary,
(ItemWithAllMetadata) icon
);
}
Notifications use the standard Message API for styling:
| Method | Description |
|---|---|
Message.raw(String) | Create message from raw text |
.color(String) | Apply hex color (e.g., "#00FF00") |
.color(Color) | Apply named color constant |
Message.join(Message...) | Join multiple messages |
// Green success
Message.raw("Success!").color("#00FF00");
// Gold achievement
Message.raw("Achievement").color("#FFD700");
// Red warning
Message.raw("Warning").color("#FF0000");
// Blue info
Message.raw("Info").color("#0088FF");
Icons are created from ItemStack objects converted to packet format:
// Create from item ID and quantity
var icon = new ItemStack("Weapon_Sword_Mithril", 1).toPacket();
// Cast to ItemWithAllMetadata for sendNotification
NotificationUtil.sendNotification(
packetHandler,
primary,
secondary,
(ItemWithAllMetadata) icon
);
| Item ID | Use Case |
|---|---|
Weapon_Sword_* | Combat notifications |
Item_Trophy_* | Achievement notifications |
Item_Coin_* | Currency notifications |
Food_* | Food/buff notifications |
Tool_* | Tool-related notifications |
Consider creating a utility wrapper for consistent notification styling:
public class Notifications {
public static void success(PlayerRef player, String title, String message, String iconId) {
send(player, title, "#00FF00", message, "#AAFFAA", iconId);
}
public static void warning(PlayerRef player, String title, String message, String iconId) {
send(player, title, "#FFAA00", message, "#FFDDAA", iconId);
}
public static void error(PlayerRef player, String title, String message, String iconId) {
send(player, title, "#FF0000", message, "#FFAAAA", iconId);
}
public static void info(PlayerRef player, String title, String message, String iconId) {
send(player, title, "#0088FF", message, "#AADDFF", iconId);
}
private static void send(PlayerRef player, String title, String titleColor,
String message, String messageColor, String iconId) {
var packetHandler = player.getPacketHandler();
var primary = Message.raw(title).color(titleColor);
var secondary = Message.raw(message).color(messageColor);
var icon = new ItemStack(iconId, 1).toPacket();
NotificationUtil.sendNotification(
packetHandler,
primary,
secondary,
(ItemWithAllMetadata) icon
);
}
}