use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class FollowCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag stop = scriptEntry.getElement("stop");
ElementTag lead = scriptEntry.getElement("lead");
ElementTag maxRange = scriptEntry.getElement("max");
ElementTag allowWander = scriptEntry.getElement("allow_wander");
ElementTag speed = scriptEntry.getElement("speed");
ElementTag noTeleport = scriptEntry.getElement("no_teleport");
ListTag entities = scriptEntry.getObjectTag("entities");
EntityTag target = scriptEntry.getObjectTag("target");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), Utilities.getEntryPlayer(scriptEntry), (!stop.asBoolean() ? db("Action", "FOLLOW") : db("Action", "STOP")), lead, noTeleport, maxRange, allowWander, entities, target);
}
for (EntityTag entity : entities.filter(EntityTag.class, scriptEntry)) {
if (entity.isCitizensNPC()) {
NPCTag npc = entity.getDenizenNPC();
if (lead != null) {
npc.getNavigator().getLocalParameters().distanceMargin(lead.asDouble());
}
if (speed != null) {
npc.getNavigator().getLocalParameters().speedModifier(speed.asFloat());
}
if (noTeleport != null && noTeleport.asBoolean()) {
npc.getNavigator().getLocalParameters().stuckAction(null);
}
if (stop.asBoolean()) {
npc.getNavigator().cancelNavigation();
} else {
npc.getNavigator().setTarget(target.getBukkitEntity(), false);
}
} else {
if (stop.asBoolean()) {
NMSHandler.getEntityHelper().stopFollowing(entity.getBukkitEntity());
} else {
NMSHandler.getEntityHelper().follow(target.getBukkitEntity(), entity.getBukkitEntity(), speed != null ? speed.asDouble() : 0.3, lead != null ? lead.asDouble() : 5, maxRange != null ? maxRange.asDouble() : 8, allowWander.asBoolean(), noTeleport == null || !noTeleport.asBoolean());
}
}
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class AssignmentTrait method addAssignmentScript.
// <--[action]
// @Actions
// assignment
//
// @Triggers when the assignment script is added to an NPC.
//
// @Context
// None
//
// -->
public boolean addAssignmentScript(AssignmentScriptContainer script, PlayerTag player) {
String name = CoreUtilities.toLowerCase(script.getName());
if (assignments.contains(name)) {
return false;
}
assignments.add(name);
containerCache.add(script);
ensureDefaultTraits();
Denizen.getInstance().npcHelper.getActionHandler().doAction("assignment", new NPCTag(npc), player, script, null);
return true;
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class HealthTrait method onDamage.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(EntityDamageEvent event) {
// Check if the event pertains to this NPC
if (event.getEntity() != npc.getEntity() || dying) {
return;
}
// Make sure this is a killing blow
if (this.getHealth() - event.getFinalDamage() > 0) {
return;
}
dying = true;
// Save entityId for EntityDeath event
entityId = npc.getEntity().getUniqueId();
if (npc.getEntity() == null) {
return;
}
TagContext context = new BukkitTagContext(null, new NPCTag(npc), null, true, null);
// TODO: debug option?
loc = getRespawnLocation();
if (loc == null) {
loc = npc.getStoredLocation();
}
if (animatedeath) {
// Cancel navigation to keep the NPC from damaging players
// while the death animation is being carried out.
npc.getNavigator().cancelNavigation();
// Reset health now to avoid the death from happening instantly
// setHealth();
// Play animation (TODO)
// playDeathAnimation(npc.getEntity());
}
if (respawn && (getRespawnDelay().getTicks() > 0)) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
if (CitizensAPI.getNPCRegistry().getById(npc.getId()) == null || npc.isSpawned()) {
return;
} else {
npc.spawn(loc);
}
}, (getRespawnDelay().getTicks()));
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class PushableTrait method NPCCompleteDestination.
// <--[action]
// @Actions
// push return
//
// @Triggers when the NPC returns to its center after being pushed by a player.
//
// @Context
// None
//
// -->
/**
* Fires a 'On Push Return:' action upon return after being pushed.
*/
@EventHandler
public void NPCCompleteDestination(NavigationCompleteEvent event) {
if (event.getNPC() == npc && pushed) {
Entity npcEntity = npc.getEntity();
Location location = npcEntity.getLocation();
location.setYaw(returnLocation.getYaw());
location.setPitch(returnLocation.getPitch());
NMS.setHeadYaw(npcEntity, returnLocation.getYaw());
pushed = false;
// Push Return action
new NPCTag(npc).action("push return", null);
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNPCHelper method onRemove.
// <--[action]
// @Actions
// remove
// @Triggers when the NPC is removed.
//
// @Context
// None
// -->
/**
* Removes an NPC from the Registry when removed from Citizens.
*
* @param event NPCRemoveEvent
*/
@EventHandler
public void onRemove(NPCRemoveEvent event) {
NPC npc = event.getNPC();
new NPCTag(npc).action("remove", null);
}
Aggregations