Search in sources :

Example 1 with TaskScriptContainer

use of net.aufdemrand.denizencore.scripts.containers.core.TaskScriptContainer in project Denizen-For-Bukkit by DenizenScript.

the class ListenerRegistry method finish.

/**
     * Finishes a listener, effectively removing and destroying the instance, but
     * calls the optional finish_script and bukkit/world script events associated.
     *
     * @param player    the dPlayer
     * @param npc       dNPC attached from the listen command (can be null)
     * @param id        id of the listener
     * @param on_finish dScript to run on finish
     */
public void finish(dPlayer player, dNPC npc, String id, dScript on_finish) {
    if (player == null || id == null) {
        return;
    }
    // Remove listener instance from the player
    removeListenerFor(player, id);
    // Run finish script
    if (on_finish != null) {
        try {
            // TODO: Add context to this
            ((TaskScriptContainer) on_finish.getContainer()).runTaskScript(new BukkitScriptEntryData(player, npc), null);
        } catch (Exception e) {
            // Hm, not a valid task script?
            dB.echoError("Tried to run the finish task for: " + id + "/" + player.getName() + "," + "but it seems not to be valid!");
        }
    }
    Bukkit.getPluginManager().callEvent(new ListenerFinishEvent(player, id));
}
Also used : ListenerFinishEvent(net.aufdemrand.denizen.events.bukkit.ListenerFinishEvent) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) TaskScriptContainer(net.aufdemrand.denizencore.scripts.containers.core.TaskScriptContainer)

Aggregations

BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 ListenerFinishEvent (net.aufdemrand.denizen.events.bukkit.ListenerFinishEvent)1 TaskScriptContainer (net.aufdemrand.denizencore.scripts.containers.core.TaskScriptContainer)1