Search in sources :

Example 11 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class AssignmentCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dScript script = scriptEntry.getdObject("script");
    // Report to dB
    dB.report(scriptEntry, getName(), aH.debugObj("action", scriptEntry.getObject("action")) + script.debug());
    // Perform desired action
    if (scriptEntry.getObject("action").equals(Action.SET)) {
        ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen().getTrait(AssignmentTrait.class).setAssignment(script.getName(), ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer());
    } else if (scriptEntry.getObject("action").equals(Action.REMOVE)) {
        ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen().getTrait(AssignmentTrait.class).removeAssignment(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer());
    }
}
Also used : AssignmentTrait(net.aufdemrand.denizen.npc.traits.AssignmentTrait) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript)

Example 12 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class EngageCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Duration duration = scriptEntry.getdObject("duration");
    dNPC npc = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC();
    // Report to dB
    dB.report(scriptEntry, getName(), npc.debug() + duration.debug());
    if (duration.getSecondsAsInt() > 0) {
        setEngaged(npc.getCitizen(), duration.getSecondsAsInt());
    } else {
        setEngaged(npc.getCitizen(), true);
    }
}
Also used : net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Duration(net.aufdemrand.denizencore.objects.Duration)

Example 13 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class BukkitTagContext method getScriptEntryData.

@Override
public ScriptEntryData getScriptEntryData() {
    BukkitScriptEntryData bsed = new BukkitScriptEntryData(player, npc);
    bsed.scriptEntry = entry;
    return bsed;
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData)

Example 14 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class NPCTags method navBegin.

// <--[event]
// @Events
// npc begins navigation
//
// @Warning This event may fire very rapidly.
//
// @Triggers when an NPC begins navigating.
//
// @Context
// None
//
// -->
// <--[action]
// @Actions
// begin navigation
//
// @Triggers when the NPC has received a 'walk' command,
// or is about to follow a path.
//
// @Context
// None
//
// -->
@EventHandler
public void navBegin(NavigationBeginEvent event) {
    dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
    // Do world script event 'On NPC Completes Navigation'
    if (NPCNavigationSmartEvent.IsActive()) {
        OldEventManager.doEvents(Arrays.asList("npc begins navigation"), new BukkitScriptEntryData(null, npc), null);
    }
    if (!event.getNPC().hasTrait(AssignmentTrait.class)) {
        return;
    }
    npc.action("begin navigation", null);
    if (event.getNPC().getNavigator().getTargetType() == TargetType.ENTITY) {
        LivingEntity entity = (LivingEntity) event.getNPC().getNavigator().getEntityTarget().getTarget();
        // and that entity is not dead, trigger "on attack" command
        if (event.getNPC().getNavigator().getEntityTarget().isAggressive() && !entity.isDead()) {
            dPlayer player = null;
            // Check if the entity attacked by this NPC is a player
            if (entity instanceof Player) {
                player = dPlayer.mirrorBukkitPlayer((Player) entity);
            }
            // <--[action]
            // @Actions
            // attack
            // attack on <entity>
            //
            // @Triggers when the NPC is about to attack an enemy.
            //
            // @Context
            // None
            //
            // -->
            npc.action("attack", player);
            npc.action("attack on " + entity.getType().toString(), player);
        }
        previousLocations.put(event.getNPC().getId(), npc.getLocation());
    }
}
Also used : AssignmentTrait(net.aufdemrand.denizen.npc.traits.AssignmentTrait) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 15 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class NPCTags method navComplete.

// <--[event]
// @Events
// npc completes navigation
//
// @Warning This event may fire very rapidly.
//
// @Triggers when an NPC finishes navigating.
//
// @Context
// None
//
// -->
// <--[action]
// @Actions
// complete navigation
//
// @Triggers when the NPC has finished a 'walk' command,
// or has reached a path point.
//
// @Context
// None
//
// -->
@EventHandler
public void navComplete(NavigationCompleteEvent event) {
    dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
    // Do world script event 'On NPC Completes Navigation'
    if (NPCNavigationSmartEvent.IsActive()) {
        OldEventManager.doEvents(Arrays.asList("npc completes navigation"), new BukkitScriptEntryData(null, npc), null);
    }
    // Do the assignment script action
    if (!event.getNPC().hasTrait(AssignmentTrait.class)) {
        return;
    }
    npc.action("complete navigation", null);
}
Also used : AssignmentTrait(net.aufdemrand.denizen.npc.traits.AssignmentTrait) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)61 Element (net.aufdemrand.denizencore.objects.Element)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)19 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)18 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)18 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)13 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)13 Duration (net.aufdemrand.denizencore.objects.Duration)9 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)8 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)8 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)6 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 AssignmentTrait (net.aufdemrand.denizen.npc.traits.AssignmentTrait)5 net.aufdemrand.denizen.objects.dInventory (net.aufdemrand.denizen.objects.dInventory)5 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)5 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)5 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)5 EventHandler (org.bukkit.event.EventHandler)5