This script is a simple module that reads a specific flag
attached to the player provided by triggered events
or commands
. These data are then rendered by the script based on the provided template and are added into a provided item as icon
as lores formatted.
Just drop into your Denizen scripts folder and it should load without problem.
use /notification ingame to open the notification window. By default, right clicking an icon will remove it from the player's notification GUI but it will still be in their data for future review.
This module is composed of 2 important elements.
- Source of Notification Message
- Message Template
The way this script works is that an event
will compose a map
of data based on the template data_notification_data_template.template
which can be found in config/Data Template.dsc
. By default these are the fields that the template contains:
data_notification_data_template:
type: data
debug: false
template:
# Recipient of the notification (player object)
to: null
# Type of notification
type: Notification
# meta data for any forms of storage
meta: meta
# message template
template: null
In addition to this, when the data is finally saved, additional fields will be added such as:
- Date (format yyyy/MM/dd)
- Time (format hh:mm:ss a)
- ID (random 12 characters from '123456789abcdefghijklmnopqrstuvwxyz')
- Read
- Deleted
Using denizen you can add your own events that will then push the data into the player's flag and later on rendered in the Notification GUI. Lets start by adding a simple block break event!
my_event:
type: world
debug: false
data:
type: MY_NOTIFICATION
event:
break_block: BLOCK_BREAK
events:
on player breaks block:
- define notification <script[data_notification_data_template].data_key[template]>
- define notification.to <player>
- define notification.type <script.data_key[data.type]>
- define notification.template <script.data_key[event.break_block]>
- definemap notification.meta:
block: <context.material.translated_name>
location: <context.location.simple>
- customevent id:push_notification_module context:<[notification]>
This event contains 3 importants details.
- Who to send the notification (target)
- What kind of notification (notification type)
- What is the template of the notification (notification type template ID)
After filling out the details, we then call the custom event push_notification_module
with the notification data.
Now that we have an event that pushes the details of our notification, lets create a template to render notification data into!
data_notification_template_MY_NOTIFICATION:
type: data
debug: false
MY_NOTIFICATION:
BLOCK_BREAK:
title: You broke a ${block}!
message:
- <reset><gray>You broke a ${block} in ${location}!
Now there's a 3 things we need to take note when creating a template.
- the script container's name should always be
data_notification_template_
+your_notification_type
in our sample will bedata_notification_template_MY_NOTIFICATION
. - Notification Type as root node (
MY_NOTIFICATION
) - Template ID (
BLOCK_BREAK
)
A notification template should always have a title
and message
. The title
will be the name of the item rendered in the GUI and the message
will become the item's lore.
Now that we have our event
pushing the notification data into the player's flag and a template
to put as a message, we can now test it out! Try breaking a block and check our notification by doing /notification
You can do more with denizen and extend this script even further by having custom handlers, actions, etc... through denizen.
- add support for left click to execute script
- add support for pagination if notifications overflows