Search in sources :

Example 41 with NPCTag

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());
            }
        }
    }
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 42 with NPCTag

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;
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag)

Example 43 with NPCTag

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()));
    }
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) TagContext(com.denizenscript.denizencore.tags.TagContext) NPCTag(com.denizenscript.denizen.objects.NPCTag) EventHandler(org.bukkit.event.EventHandler)

Example 44 with NPCTag

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);
    }
}
Also used : Entity(org.bukkit.entity.Entity) NPCTag(com.denizenscript.denizen.objects.NPCTag) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 45 with NPCTag

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);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) NPCTag(com.denizenscript.denizen.objects.NPCTag) EventHandler(org.bukkit.event.EventHandler)

Aggregations

NPCTag (com.denizenscript.denizen.objects.NPCTag)72 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)24 EventHandler (org.bukkit.event.EventHandler)22 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)21 Player (org.bukkit.entity.Player)15 LocationTag (com.denizenscript.denizen.objects.LocationTag)12 EntityTag (com.denizenscript.denizen.objects.EntityTag)10 ListTag (com.denizenscript.denizencore.objects.core.ListTag)9 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)8 HashMap (java.util.HashMap)8 NPC (net.citizensnpcs.api.npc.NPC)8 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)7 AssignmentTrait (com.denizenscript.denizen.npc.traits.AssignmentTrait)6 Location (org.bukkit.Location)6 TriggerTrait (com.denizenscript.denizen.npc.traits.TriggerTrait)5 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)5 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Entity (org.bukkit.entity.Entity)5