use of net.aufdemrand.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();
DenizenAPI.getDenizenNPC(npc).action("exhausted", null);
// No need to progress any further.
return;
}
}
}
location = npc.getEntity().getLocation();
listening = true;
}
Aggregations