Skip to content

Commit

Permalink
Make MobProx warn on bad trait command
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 11, 2013
1 parent 8a76b3d commit e23f10c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/net/aufdemrand/denizen/npc/traits/MobproxTrait.java
Expand Up @@ -3,6 +3,7 @@
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.citizensnpcs.api.event.NPCTraitCommandAttachEvent;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -33,10 +34,10 @@ public MobproxTrait() {
public void run() {
checkTimer++;
if (checkTimer == 40) {
int range = frange.getLast().asInteger();
boolean acceptnpc = facceptnpc.getLast().asBoolean();
checkTimer = 0;
if (getNPC().isSpawned()) {
int range = frange.getLast().asInteger();
boolean acceptnpc = facceptnpc.getLast().asBoolean();
List<Entity> nearby = liveEnt.getNearbyEntities(range, range, range);
List<Entity> removeme = new ArrayList<Entity>();
removeme.addAll(inrange);
Expand Down Expand Up @@ -67,6 +68,20 @@ private void callAction(String act, Entity ent) {
dnpc.action("mob " + act + " proximity", null, context);
dnpc.action(ent.getType().name() + " " + act + " proximity", null, context);
}
@EventHandler
public void onTraitAttachEvent(NPCTraitCommandAttachEvent event) {
if (!event.getTraitClass().equals(MobproxTrait.class)) {
return;
}
if (event.getNPC() != getNPC()) {
return;
}
onSpawn();
AssignmentTrait at = dnpc.getAssignmentTrait();
if (at == null || !at.hasAssignment()) {
event.getCommandSender().sendMessage(ChatColor.RED + "Warning: This NPC doesn't have a script assigned! Mobprox only works with scripted Denizen NPCs!");
}
}
@Override
public void onSpawn() {
liveEnt = getNPC().getBukkitEntity();
Expand All @@ -80,6 +95,7 @@ public void onSpawn() {
facceptnpc.set("false");
}
}
/*
@Override
public void onAttach() {
onSpawn();
Expand All @@ -94,5 +110,6 @@ public void onAttach() {
}
}
}
*/

}

0 comments on commit e23f10c

Please sign in to comment.