use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class ClickTrigger method clickTrigger.
// <--[language]
// @name Click Triggers
// @group NPC Interact Scripts
// @description
// Click Triggers are triggered when a player right clicks the NPC.
//
// These are very basic with no extraneous complexity.
//
// <code>
// click trigger:
// script:
// - narrate "hi <player.name>"
// </code>
//
// They can optionally have an item matcher with multiple triggers, for the item in the player's hand. For example:
// <code>
// click trigger:
// 1:
// trigger: my_item_script
// script:
// - narrate "Nice item script"
// 2:
// trigger: stone
// script:
// - narrate "Nice vanilla item"
// 3:
// script:
// - narrate "I don't recognize your held item"
// </code>
//
// -->
// <--[action]
// @Actions
// no click trigger
//
// @Triggers when the NPC is clicked but no click trigger fires.
//
// @Context
// None
//
// -->
// Technically defined in TriggerTrait, but placing here instead.
// <--[action]
// @Actions
// click
//
// @Triggers when the NPC is clicked by a player.
//
// @Context
// None
//
// @Determine
// "cancelled" to cancel the click event completely.
//
// -->
@EventHandler
public void clickTrigger(NPCRightClickEvent event) {
if (!event.getNPC().hasTrait(TriggerTrait.class)) {
return;
}
NPCTag npc = new NPCTag(event.getNPC());
if (!npc.getTriggerTrait().isEnabled(name)) {
return;
}
PlayerTag player = PlayerTag.mirrorBukkitPlayer(event.getClicker());
TriggerTrait.TriggerContext trigger = npc.getTriggerTrait().trigger(this, player);
if (!trigger.wasTriggered()) {
return;
}
if (trigger.hasDetermination() && trigger.getDeterminations().containsCaseInsensitive("cancelled")) {
event.setCancelled(true);
return;
}
List<InteractScriptContainer> scripts = npc.getInteractScripts(player, ClickTrigger.class);
boolean any = false;
if (scripts != null) {
for (InteractScriptContainer script : scripts) {
String id = null;
Map<String, String> idMap = script.getIdMapFor(ClickTrigger.class, player);
if (!idMap.isEmpty()) {
ItemTag heldItem = new ItemTag(player.getPlayerEntity().getEquipment().getItemInMainHand());
for (Map.Entry<String, String> entry : idMap.entrySet()) {
String entry_value = TagManager.tag(entry.getValue(), new BukkitTagContext(player, npc, null, false, null));
boolean isMatch = entry_value.isEmpty() || BukkitScriptEvent.tryItem(heldItem, entry_value);
if (script.shouldDebug()) {
Debug.echoDebug(script, "Comparing click trigger '<A>" + entry_value + "<W>' with item '<A>" + heldItem.debuggable() + "<W>': " + (isMatch ? "<GR>Match!" : "<Y>Not a match"));
}
if (isMatch) {
id = entry.getKey();
break;
}
}
}
if (parse(npc, player, script, id)) {
any = true;
}
}
}
if (!any) {
npc.action("no click trigger", player);
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class NPCTagBase method navComplete.
// <--[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) {
// Do the assignment script action
if (!event.getNPC().hasTrait(AssignmentTrait.class)) {
return;
}
NPCTag npc = new NPCTag(event.getNPC());
npc.action("complete navigation", null);
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class NPCTagBase method onHit.
// <--[action]
// @Actions
// hit
// hit on <entity>
//
// @Triggers when the NPC hits an enemy.
//
// @Context
// None
//
// -->
// <--[action]
// @Actions
// kill
// kill of <entity>
//
// @Triggers when the NPC kills an enemy.
//
// @Context
// None
//
// -->
@EventHandler(priority = EventPriority.MONITOR)
public void onHit(EntityDamageByEntityEvent event) {
NPC citizen = CitizensAPI.getNPCRegistry().getNPC(event.getEntity());
if (citizen == null) {
if (event.getDamager() instanceof Projectile) {
if (((Projectile) event.getDamager()).getShooter() instanceof Entity) {
citizen = CitizensAPI.getNPCRegistry().getNPC((Entity) ((Projectile) event.getDamager()).getShooter());
}
}
}
if (citizen == null || !citizen.hasTrait(AssignmentTrait.class)) {
return;
}
NPCTag npc = new NPCTag(citizen);
PlayerTag player = null;
if (event.getEntity() instanceof Player) {
player = PlayerTag.mirrorBukkitPlayer((Player) event.getEntity());
}
// TODO: Context containing the entity hit
npc.action("hit", player);
npc.action("hit on " + event.getEntityType().name(), player);
if (event.getEntity() instanceof LivingEntity) {
if (((LivingEntity) event.getEntity()).getHealth() - event.getFinalDamage() <= 0) {
npc.action("kill", player);
npc.action("kill of " + event.getEntityType().name(), player);
}
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class NPCTagBase method navBegin.
// <--[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) {
if (!event.getNPC().hasTrait(AssignmentTrait.class)) {
return;
}
NPCTag npc = new NPCTag(event.getNPC());
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()) {
PlayerTag player = null;
// Check if the entity attacked by this NPC is a player
if (entity instanceof Player) {
player = PlayerTag.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());
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class NPCTagBase method navCancel.
// <--[action]
// @Actions
// cancel navigation
// cancel navigation due to <reason>
//
// @Triggers when a plugin or script cancels an NPC's navigation.
//
// @Context
// None
//
// -->
@EventHandler
public void navCancel(NavigationCancelEvent event) {
if (!event.getNPC().hasTrait(AssignmentTrait.class)) {
return;
}
NPCTag npc = new NPCTag(event.getNPC());
npc.action("cancel navigation", null);
npc.action("cancel navigation due to " + event.getCancelReason().toString(), null);
}
Aggregations