Search in sources :

Example 1 with ExhaustedNPCEvent

use of com.denizenscript.denizen.events.bukkit.ExhaustedNPCEvent in project Denizen-For-Bukkit by DenizenScript.

the class HungerTrait method onMove.

// <--[action]
// @Actions
// exhausted
// 
// @Triggers when the NPC is exhausted (Requires the Hunger trait)
// 
// @Context
// None
// 
// -->
/**
 * Listens for the NPC to move so hunger-loss can be calculated.
 * Cuts down on processing since loss is only calculated when moving.
 * Also checks for exhaustion, if enabled. If a NPC is exhausted, that is,
 * if currenthunger >= maxhunger, the NPC cannot move and a
 * NPCExhaustedEvent and 'On Exhausted:' action will fire.
 */
@EventHandler
public void onMove(NavigationBeginEvent event) {
    // TODO: Check if NPC == this NPC?
    if (allowexhaustion) {
        if (isStarving()) {
            // Create NPCExhaustedEvent, give chance for outside plugins to cancel.
            ExhaustedNPCEvent e = new ExhaustedNPCEvent(npc);
            Bukkit.getServer().getPluginManager().callEvent(e);
            // If still exhausted, cancel navigation and fire 'On Exhausted:' action
            if (!e.isCancelled()) {
                npc.getNavigator().cancelNavigation();
                new NPCTag(npc).action("exhausted", null);
                // No need to progress any further.
                return;
            }
        }
    }
    location = npc.getStoredLocation().clone();
    listening = true;
}
Also used : ExhaustedNPCEvent(com.denizenscript.denizen.events.bukkit.ExhaustedNPCEvent) NPCTag(com.denizenscript.denizen.objects.NPCTag) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ExhaustedNPCEvent (com.denizenscript.denizen.events.bukkit.ExhaustedNPCEvent)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 EventHandler (org.bukkit.event.EventHandler)1