Code Patterns

Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.

← Back to Patterns
ui

Send Notification

Send item pickup-style notifications to players.

Example Code

java
public static void sendItemNotification(Player player, String itemId, String message) {
    PlayerRef playerRef = Universe.get().getPlayer(player.getUuid());
    PacketHandler packetHandler = playerRef.getPacketHandler();

    Message primaryMsg = Message.raw(message).color("#00FF00");
    Message secondaryMsg = Message.raw("You received an item!").color("#228B22");
    ItemWithAllMetadata icon = (ItemWithAllMetadata) new ItemStack(itemId, 1).toPacket();

    NotificationUtil.sendNotification(packetHandler, primaryMsg, secondaryMsg, icon);
}

Common Mistakes

Not casting toPacket() to ItemWithAllMetadata.