Search in sources :

Example 41 with EntityTag

use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.

the class PlayerFishesScriptEvent method onPlayerFishes.

@EventHandler
public void onPlayerFishes(PlayerFishEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    Entity hookEntity = NMSHandler.getEntityHelper().getFishHook(event);
    EntityTag.rememberEntity(hookEntity);
    hook = new EntityTag(hookEntity);
    state = new ElementTag(event.getState().toString());
    item = null;
    entity = null;
    Entity caughtEntity = event.getCaught();
    if (caughtEntity != null) {
        EntityTag.rememberEntity(caughtEntity);
        entity = new EntityTag(caughtEntity);
        if (caughtEntity instanceof Item) {
            item = new ItemTag(((Item) caughtEntity).getItemStack());
        }
    }
    this.event = event;
    fire(event);
    EntityTag.forgetEntity(hookEntity);
    EntityTag.forgetEntity(caughtEntity);
}
Also used : Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) EventHandler(org.bukkit.event.EventHandler)

Example 42 with EntityTag

use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.

the class VehicleCollidesEntityScriptEvent method onVehicleCollidesEntity.

@EventHandler
public void onVehicleCollidesEntity(VehicleEntityCollisionEvent event) {
    entity = new EntityTag(event.getEntity());
    vehicle = new EntityTag(event.getVehicle());
    this.event = event;
    fire(event);
}
Also used : EntityTag(com.denizenscript.denizen.objects.EntityTag) EventHandler(org.bukkit.event.EventHandler)

Example 43 with EntityTag

use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.

the class VehicleMoveScriptEvent method onVehicleMove.

@EventHandler
public void onVehicleMove(VehicleMoveEvent event) {
    to = new LocationTag(event.getTo());
    from = new LocationTag(event.getFrom());
    vehicle = new EntityTag(event.getVehicle());
    this.event = event;
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) EventHandler(org.bukkit.event.EventHandler)

Example 44 with EntityTag

use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNPCHelper method despawn.

// <--[action]
// @Actions
// despawn
// @Triggers when the NPC is despawned.
// This can be because a command was issued, or a chunk has been unloaded.
// 
// @Context
// None
// -->
/**
 * Fires a world script event and then NPC action when the NPC despawns.
 *
 * @param event NPCDespawnEvent
 */
@EventHandler
public void despawn(NPCDespawnEvent event) {
    NPCTag npc = new NPCTag(event.getNPC());
    if (npc.isValid()) {
        EntityDespawnScriptEvent.instance.entity = new EntityTag(event.getNPC().getEntity());
        EntityDespawnScriptEvent.instance.cause = new ElementTag("CITIZENS");
        EntityDespawnScriptEvent.instance.fire(event);
        npc.action("despawn", null);
    }
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

Example 45 with EntityTag

use of com.denizenscript.denizen.objects.EntityTag in project Denizen-For-Bukkit by DenizenScript.

the class DenizenChat method talk.

@Override
public void talk(SpeechContext speechContext) {
    if (!(speechContext instanceof DenizenSpeechContext)) {
        return;
    }
    DenizenSpeechContext context = (DenizenSpeechContext) speechContext;
    Talkable talker = context.getTalker();
    if (talker == null) {
        return;
    }
    ScriptEntry entry = context.getScriptEntry();
    ScriptQueue queue = entry.getResidingQueue();
    String defTalker = null;
    if (queue.hasDefinition("talker")) {
        defTalker = queue.getDefinition("talker");
    }
    queue.addDefinition("talker", new EntityTag(talker.getEntity()).identify());
    String defMessage = null;
    if (queue.hasDefinition("message")) {
        defMessage = queue.getDefinition("message");
    }
    queue.addDefinition("message", context.getMessage());
    // Chat to the world using Denizen chat settings
    if (!context.hasRecipients()) {
        String text = TagManager.tag(Settings.chatNoTargetFormat(), new BukkitTagContext(entry));
        talkToBystanders(talker, text, context);
    } else // Single recipient
    if (context.size() <= 1) {
        // Send chat to target
        String text = TagManager.tag(Settings.chatToTargetFormat(), new BukkitTagContext(entry));
        for (Talkable entity : context) {
            entity.talkTo(context, text, this);
        }
        // Check if bystanders hear targeted chat
        if (context.isBystandersEnabled()) {
            String defTarget = null;
            if (queue.hasDefinition("target")) {
                defTarget = queue.getDefinition("target");
            }
            queue.addDefinition("target", new EntityTag(context.iterator().next().getEntity()).identify());
            String bystanderText = TagManager.tag(Settings.chatWithTargetToBystandersFormat(), new BukkitTagContext(entry));
            talkToBystanders(talker, bystanderText, context);
            if (defTarget != null) {
                queue.addDefinition("target", defTarget);
            }
        }
    } else // Multiple recipients
    {
        // Send chat to targets
        String text = TagManager.tag(Settings.chatToTargetFormat(), new BukkitTagContext(entry));
        for (Talkable entity : context) {
            entity.talkTo(context, text, this);
        }
        if (context.isBystandersEnabled()) {
            String[] format = Settings.chatMultipleTargetsFormat().split("%target%");
            if (format.length <= 1) {
                Debug.echoError("Invalid 'Commands.Chat.Options.Multiple targets format' in config.yml! Must have at least 1 %target%");
            }
            StringBuilder parsed = new StringBuilder();
            Iterator<Talkable> iter = context.iterator();
            int i = 0;
            while (iter.hasNext()) {
                if (i == format.length - 1) {
                    parsed.append(format[i]);
                    break;
                }
                parsed.append(format[i]).append(new EntityTag(iter.next().getEntity()).getName());
                i++;
            }
            String targets = TagManager.tag(parsed.toString(), new BukkitTagContext(entry));
            String defTargets = null;
            if (queue.hasDefinition("targets")) {
                defTargets = queue.getDefinition("targets");
            }
            queue.addDefinition("targets", targets);
            String bystanderText = TagManager.tag(Settings.chatWithTargetsToBystandersFormat(), new BukkitTagContext(entry));
            talkToBystanders(talker, bystanderText, context);
            if (defTargets != null) {
                queue.addDefinition("targets", defTargets);
            }
        }
    }
    if (defMessage != null) {
        queue.addDefinition("message", defMessage);
    }
    if (defTalker != null) {
        queue.addDefinition("talker", defTalker);
    }
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) Iterator(java.util.Iterator) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) EntityTag(com.denizenscript.denizen.objects.EntityTag) Talkable(net.citizensnpcs.api.ai.speech.Talkable) ScriptQueue(com.denizenscript.denizencore.scripts.queues.ScriptQueue)

Aggregations

EntityTag (com.denizenscript.denizen.objects.EntityTag)142 EventHandler (org.bukkit.event.EventHandler)81 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)56 LocationTag (com.denizenscript.denizen.objects.LocationTag)45 List (java.util.List)27 Entity (org.bukkit.entity.Entity)25 ItemTag (com.denizenscript.denizen.objects.ItemTag)17 ListTag (com.denizenscript.denizencore.objects.core.ListTag)17 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)15 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)12 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)11 NPCTag (com.denizenscript.denizen.objects.NPCTag)10 ArrayList (java.util.ArrayList)10 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)10 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)9 Player (org.bukkit.entity.Player)9 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)8 Argument (com.denizenscript.denizencore.objects.Argument)8 LivingEntity (org.bukkit.entity.LivingEntity)8 Item (org.bukkit.entity.Item)7