Skip to content

Commit

Permalink
Add on NPC Completes Navigation, on NPC Cancels Navigation, on NPC be…
Browse files Browse the repository at this point in the history
…gins navigation, on NPC spawns, and on NPC despawns world script events.
  • Loading branch information
aufdemrand committed Jul 15, 2013
1 parent 396f953 commit 4a95390
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Expand Up @@ -327,6 +327,11 @@ && getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != nu
return new Element(String.valueOf(getNavigator().getLocalParameters().speed()))
.getAttribute(attribute.fulfill(2));

if (attribute.startsWith("navigator.range"))
return new Element(String.valueOf(getNavigator().getLocalParameters().range()))
.getAttribute(attribute.fulfill(2));


if (attribute.startsWith("navigator.attack_strategy"))
return new Element(String.valueOf(getNavigator().getLocalParameters().attackStrategy().toString()))
.getAttribute(attribute.fulfill(2));
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/net/aufdemrand/denizen/tags/core/NPCTags.java
Expand Up @@ -2,12 +2,11 @@

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.events.ReplaceableTagEvent;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.npc.traits.AssignmentTrait;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.containers.core.WorldScriptHelper;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.citizensnpcs.api.ai.event.NavigationBeginEvent;
import net.citizensnpcs.api.ai.event.NavigationCancelEvent;
Expand All @@ -18,6 +17,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -67,13 +67,26 @@ public void npcTags(ReplaceableTagEvent event) {

@EventHandler
public void navComplete(NavigationCompleteEvent event) {

// Do world script event 'On NPC Completes Navigation'
WorldScriptHelper.doEvents(Arrays.asList
("npc completes navigation"),
dNPC.mirrorCitizensNPC(event.getNPC()), null, null).toUpperCase();

// Do the assignment script action
if (!event.getNPC().hasTrait(AssignmentTrait.class)) return;
dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
npc.action("complete navigation", null);

}

@EventHandler
public void navBegin(NavigationBeginEvent event) {
// Do world script event 'On NPC Completes Navigation'
WorldScriptHelper.doEvents(Arrays.asList
("npc begins navigation"),
dNPC.mirrorCitizensNPC(event.getNPC()), null, null);

if (!event.getNPC().hasTrait(AssignmentTrait.class)) return;
dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
npc.action("begin navigation", null);
Expand Down Expand Up @@ -104,6 +117,10 @@ public void navBegin(NavigationBeginEvent event) {

@EventHandler
public void navCancel(NavigationCancelEvent event) {
WorldScriptHelper.doEvents(Arrays.asList
("npc cancels navigation"),
dNPC.mirrorCitizensNPC(event.getNPC()), null, null).toUpperCase();

if (!event.getNPC().hasTrait(AssignmentTrait.class)) return;
dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
npc.action("cancel navigation", null);
Expand Down

0 comments on commit 4a95390

Please sign in to comment.