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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations