Skip to content

Commit

Permalink
Add dismount action/event fix for 349
Browse files Browse the repository at this point in the history
In theory? Doesn't seem to work yet.
  • Loading branch information
mcmonkey4eva committed Aug 14, 2013
1 parent 95b7e5a commit e2ef4ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -122,7 +122,7 @@ public static dEntity valueOf(String string) {

// When selecting a random entity type, ignore invalid or inappropriate ones
while (randomType == null ||
randomType.name().matches("^(COMPLEX_PART|DROPPED_ITEM|ENDER_CRYSTAL|ENDER_DRAGON|FISHING_HOOK|ITEM_FRAME|LIGHTNING|PAINTING|PLAYER|UNKNOWN|WEATHER|WITHER|WITHER_SKULL)$") == true) {
randomType.name().matches("^(COMPLEX_PART|DROPPED_ITEM|ENDER_CRYSTAL|ENDER_DRAGON|FISHING_HOOK|ITEM_FRAME|LIGHTNING|PAINTING|PLAYER|UNKNOWN|WEATHER|WITHER|WITHER_SKULL)$")) {

randomType = EntityType.values()[Utilities.getRandom().nextInt(EntityType.values().length)];
}
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/net/aufdemrand/denizen/tags/core/NPCTags.java
Expand Up @@ -8,10 +8,13 @@
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.citizensnpcs.api.ai.TargetType;
import net.citizensnpcs.api.ai.event.NavigationBeginEvent;
import net.citizensnpcs.api.ai.event.NavigationCancelEvent;
import net.citizensnpcs.api.ai.event.NavigationCompleteEvent;

import net.citizensnpcs.api.event.NPCVehicleExitEvent;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -72,7 +75,7 @@ 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();
dNPC.mirrorCitizensNPC(event.getNPC()), null, null);

// Do the assignment script action
if (!event.getNPC().hasTrait(AssignmentTrait.class)) return;
Expand All @@ -92,14 +95,13 @@ public void navBegin(NavigationBeginEvent event) {
dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
npc.action("begin navigation", null);

if (event.getNPC().getNavigator().getTargetType().toString() == "ENTITY")
{
if (event.getNPC().getNavigator().getTargetType() == TargetType.ENTITY) {
LivingEntity entity = event.getNPC().getNavigator().getEntityTarget().getTarget();

// If the NPC has an entity target, is aggressive towards it
// and that entity is not dead, trigger "on attack" command
if (event.getNPC().getNavigator().getEntityTarget().isAggressive()
&& entity.isDead() == false)
&& !entity.isDead())
{
dPlayer player = null;

Expand All @@ -120,12 +122,25 @@ public void navBegin(NavigationBeginEvent event) {
public void navCancel(NavigationCancelEvent event) {
WorldScriptHelper.doEvents(Arrays.asList
("npc cancels navigation"),
dNPC.mirrorCitizensNPC(event.getNPC()), null, null).toUpperCase();
dNPC.mirrorCitizensNPC(event.getNPC()), null, null);

if (!event.getNPC().hasTrait(AssignmentTrait.class)) return;
dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
npc.action("cancel navigation", null);
npc.action("cancel navigation due to " + event.getCancelReason().toString(), null);
}

@EventHandler
public void onNpcDismount(NPCVehicleExitEvent event) {
if (event.getExited() instanceof Player) {
dNPC npc = dNPC.mirrorCitizensNPC(event.getNPC());
npc.action("dismount", dPlayer.mirrorBukkitPlayer((Player)event.getExited()));
WorldScriptHelper.doEvents(Arrays.asList("player dismounts npc"),
npc, (Player)event.getExited(), null);
}
else {
dB.echoDebug("NPCVehicleExitEvent without a player?");
}
}

}

0 comments on commit e2ef4ef

Please sign in to comment.