Search in sources :

Example 51 with NPCTag

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

the class SittingTrait method sitInternal.

public void sitInternal(Location location) {
    safetyCleanup(location.clone());
    new NPCTag(npc).action("sit", null);
    npc.getEntity().teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
    forceEntitySit(npc.getEntity(), location.clone(), false);
    sitting = true;
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag)

Example 52 with NPCTag

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

the class SittingTrait method stand.

// <--[action]
// @Actions
// stand
// 
// @Triggers when the NPC stands up.
// 
// @Context
// None
// 
// -->
/**
 * Makes the NPC stand
 */
public void stand() {
    new NPCTag(npc).action("stand", null);
    standInternal();
    standInternal();
    chairLocation = null;
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag)

Example 53 with NPCTag

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

the class ChatTrigger method process.

// Technically defined in TriggerTrait, but placing here instead.
// <--[action]
// @Actions
// chat
// 
// @Triggers when a player chats to the NPC.
// 
// @Context
// <context.message> returns the triggering message
// <context.keyword> returns the keyword matched by a RegEx trigger
// 
// @Determine
// "CANCELLED" to stop the player from chatting.
// ElementTag to change the message.
// 
// -->
public ChatContext process(Player player, String message) {
    NPCTag npc = Utilities.getClosestNPC_ChatTrigger(player.getLocation(), 25);
    if (Debug.verbose) {
        Debug.log("Processing chat trigger: valid npc? " + (npc != null));
    }
    if (npc == null) {
        return new ChatContext(false);
    }
    if (Debug.verbose) {
        Debug.log("Has trait?  " + npc.getCitizen().hasTrait(TriggerTrait.class));
    }
    if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
        return new ChatContext(false);
    }
    if (Debug.verbose) {
        Debug.log("enabled? " + npc.getCitizen().getOrAddTrait(TriggerTrait.class).isEnabled(name));
    }
    if (!npc.getCitizen().getOrAddTrait(TriggerTrait.class).isEnabled(name)) {
        return new ChatContext(false);
    }
    if (npc.getTriggerTrait().getRadius(name) < npc.getLocation().distance(player.getLocation())) {
        if (Debug.verbose) {
            Debug.log("Not in range");
        }
        return new ChatContext(false);
    }
    if (Settings.chatMustSeeNPC()) {
        if (!player.hasLineOfSight(npc.getEntity())) {
            if (Debug.verbose) {
                Debug.log("no LOS");
            }
            return new ChatContext(false);
        }
    }
    if (Settings.chatMustLookAtNPC()) {
        if (!NMSHandler.getEntityHelper().isFacingEntity(player, npc.getEntity(), 45)) {
            if (Debug.verbose) {
                Debug.log("Not facing");
            }
            return new ChatContext(false);
        }
    }
    boolean ret = false;
    Map<String, ObjectTag> context = new HashMap<>();
    context.put("message", new ElementTag(message));
    TriggerTrait.TriggerContext trigger = npc.getTriggerTrait().trigger(ChatTrigger.this, new PlayerTag(player), context);
    if (trigger.hasDetermination()) {
        if (trigger.getDeterminations().containsCaseInsensitive("cancelled")) {
            if (Debug.verbose) {
                Debug.log("Cancelled");
            }
            return new ChatContext(true);
        }
    }
    if (!trigger.wasTriggered()) {
        if (Settings.chatGloballyIfUninteractable()) {
            if (Debug.verbose) {
                Debug.log(ChatColor.YELLOW + "Resuming. " + ChatColor.WHITE + "The NPC is currently cooling down or engaged.");
            }
            return new ChatContext(false);
        } else {
            ret = true;
        }
    }
    if (trigger.hasDetermination()) {
        message = trigger.getDeterminations().get(0);
    }
    List<InteractScriptContainer> scripts = npc.getInteractScripts(new PlayerTag(player), ChatTrigger.class);
    if (scripts == null) {
        if (Debug.verbose) {
            Debug.log("null scripts");
        }
        return new ChatContext(message, false);
    }
    ChatContext returnable = new ChatContext(ret);
    for (InteractScriptContainer script : scripts) {
        processSingle(message, player, npc, context, script, returnable);
    }
    return returnable;
}
Also used : TriggerTrait(com.denizenscript.denizen.npc.traits.TriggerTrait) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) InteractScriptContainer(com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 54 with NPCTag

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

the class ProximityTrigger method onEnable.

@Override
public void onEnable() {
    Bukkit.getServer().getPluginManager().registerEvents(this, Denizen.getInstance());
    final ProximityTrigger trigger = this;
    taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Denizen.getInstance(), () -> {
        Collection<? extends Player> allPlayers = Bukkit.getOnlinePlayers();
        for (NPC citizensNPC : CitizensAPI.getNPCRegistry()) {
            if (citizensNPC == null || !citizensNPC.isSpawned()) {
                continue;
            }
            if (!citizensNPC.hasTrait(TriggerTrait.class) || !citizensNPC.getOrAddTrait(TriggerTrait.class).isEnabled(name)) {
                continue;
            }
            NPCTag npc = new NPCTag(citizensNPC);
            TriggerTrait triggerTrait = npc.getTriggerTrait();
            for (Player bukkitPlayer : allPlayers) {
                if (!npc.getWorld().equals(bukkitPlayer.getWorld()) && hasExitedProximityOf(bukkitPlayer, npc)) {
                    continue;
                }
                if (!isCloseEnough(bukkitPlayer, npc) && hasExitedProximityOf(bukkitPlayer, npc)) {
                    continue;
                }
                PlayerTag player = PlayerTag.mirrorBukkitPlayer(bukkitPlayer);
                double entryRadius = triggerTrait.getRadius(name);
                double exitRadius = triggerTrait.getRadius(name);
                double moveRadius = triggerTrait.getRadius(name);
                Location npcLocation = npc.getLocation();
                boolean playerChangedWorlds = false;
                if (npcLocation.getWorld() != player.getWorld()) {
                    playerChangedWorlds = true;
                }
                boolean exitedProximity = hasExitedProximityOf(bukkitPlayer, npc);
                double distance = 0;
                if (!playerChangedWorlds) {
                    distance = npcLocation.distance(player.getLocation());
                }
                if (!exitedProximity && (playerChangedWorlds || distance >= exitRadius)) {
                    if (!triggerTrait.triggerCooldownOnly(trigger, player)) {
                        continue;
                    }
                    exitProximityOf(bukkitPlayer, npc);
                    npc.action("exit proximity", player);
                    parseAll(npc, player, "EXIT");
                } else if (exitedProximity && distance <= entryRadius) {
                    if (!triggerTrait.triggerCooldownOnly(trigger, player)) {
                        continue;
                    }
                    enterProximityOf(bukkitPlayer, npc);
                    npc.action("enter proximity", player);
                    parseAll(npc, player, "ENTRY");
                } else if (!exitedProximity && distance <= moveRadius) {
                    npc.action("move proximity", player);
                    parseAll(npc, player, "MOVE");
                }
            }
        }
    }, 5, 5);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) Player(org.bukkit.entity.Player) TriggerTrait(com.denizenscript.denizen.npc.traits.TriggerTrait) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) Location(org.bukkit.Location)

Example 55 with NPCTag

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

the class NPCOpensScriptEvent method NPCOpenDoor.

@EventHandler
public void NPCOpenDoor(NPCOpenDoorEvent event) {
    npc = new NPCTag(event.getNPC());
    location = new LocationTag(event.getDoor().getLocation());
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) 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