How to send notifications with your script

In this tutorial you'll end up with a great system to send notifications to the computer from the user of your script.
It's quite easy, so be ready!

Maven POM

First of all, make sure your Maven POM file contains the latest version of the Client, to be at least bigger than 2.6.4.
To your dependencies add: 

    <dependency>
        <groupId>org.parabot</groupId>
        <artifactId>client</artifactId>
        <version>2.6.4</version>
    </dependency>

The actual code

In this example we'll put everything in our own Script class, so first of all create a class that has a Manifest to test it locally.

package org.parabot.jketelaar;

import org.parabot.environment.scripts.Category;
import org.parabot.environment.scripts.Script;
import org.parabot.environment.scripts.ScriptManifest;
import org.parabot.environment.scripts.framework.LoopTask;

/**
 * @author JKetelaar
 */

@ScriptManifest(
        author = "JKetelaar",
        category = Category.UTILITY,
        name = "Notification Example",
        version = 0.1,
        servers = {""},
        description = "Testing the Notification system in Parabot")
public class Core extends Script implements LoopTask {

    @Override
    public boolean onExecute() {
        return super.onExecute();
    }

    @Override
    public int loop() {
        return 0;
    }
}

Constructor

We gotta make sure we have the Notification instance as a local variable, instead of calling the NotificationManager method every time, we'll do this in our constructor (don't forget to import NotificationManager):

private NotificationManager notificationManager;

public Core() {
    this.notificationManager = NotificationManager.getContext();
}

An example

Now we're gonna use the NotificationManager to push notifications.
In this example we'll let the user know the script is still running, every 5 seconds:

    this.notificationManager.sendMessage("Notification Example", "The script is still running!");
    sleep(5000);

Result

The previous pieces of code will result into the following simply script:

package org.parabot.jketelaar;

import org.parabot.api.notifications.NotificationManager;
import org.parabot.api.notifications.types.NotificationType;
import org.parabot.environment.scripts.Category;
import org.parabot.environment.scripts.Script;
import org.parabot.environment.scripts.ScriptManifest;
import org.parabot.environment.scripts.framework.LoopTask;

/**
 * @author JKetelaar
 */

@ScriptManifest(
        author = "JKetelaar",
        category = Category.UTILITY,
        name = "Notification Example",
        version = 0.1,
        servers = {""},
        description = "Testing the Notification system in Parabot")
public class Core extends Script implements LoopTask {

    private NotificationManager notificationManager;

    public Core() {
        this.notificationManager = NotificationManager.getContext();
    }

    @Override
    public boolean onExecute() {
        return super.onExecute();
    }

    @Override
    public int loop() {
        this.notificationManager.sendNotification("Notification Example", "The script is still running!");
        sleep(5000);
        return 0;
    }
}