Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Walk and Follow commands to accept non-NPC entities
TA-DA! It's MAGIC! Wanna do something fun? /ex follow followers:<pl.location.find.entities[zombie].within[1000]>
- Loading branch information
Showing
6 changed files
with
272 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/net/aufdemrand/denizen/scripts/commands/entity/FollowCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package net.aufdemrand.denizen.scripts.commands.entity; | ||
|
||
import net.aufdemrand.denizen.BukkitScriptEntryData; | ||
import net.aufdemrand.denizen.objects.*; | ||
import net.aufdemrand.denizen.utilities.entity.EntityMovement; | ||
import net.aufdemrand.denizencore.exceptions.CommandExecutionException; | ||
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException; | ||
import net.aufdemrand.denizen.scripts.ScriptEntry; | ||
import net.aufdemrand.denizen.scripts.commands.AbstractCommand; | ||
import net.aufdemrand.denizen.utilities.debugging.dB; | ||
|
||
/** | ||
* Instructs the NPC to follow a player. | ||
* | ||
* @author aufdemrand | ||
* | ||
*/ | ||
public class FollowCommand extends AbstractCommand { | ||
|
||
@Override | ||
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { | ||
|
||
// Parse Arguments | ||
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { | ||
if (!scriptEntry.hasObject("stop") && | ||
arg.matches("STOP")) | ||
scriptEntry.addObject("stop", new Element(true)); | ||
|
||
else if (!scriptEntry.hasObject("lead") && | ||
arg.matchesPrimitive(aH.PrimitiveType.Double)) | ||
scriptEntry.addObject("lead", arg.asElement()); | ||
|
||
else if (!scriptEntry.hasObject("speed") && | ||
arg.matchesPrimitive(aH.PrimitiveType.Percentage)) | ||
scriptEntry.addObject("speed", arg.asElement()); | ||
|
||
else if (!scriptEntry.hasObject("target") && | ||
arg.matchesArgumentType(dEntity.class)) | ||
scriptEntry.addObject("target", arg.asType(dEntity.class)); | ||
|
||
else if (!scriptEntry.hasObject("entities") && | ||
arg.matchesPrefix("followers", "follower") && | ||
arg.matchesArgumentList(dEntity.class)) | ||
scriptEntry.addObject("entities", arg.asType(dList.class)); | ||
|
||
else | ||
arg.reportUnhandled(); | ||
} | ||
if (!scriptEntry.hasObject("target")) { | ||
if (((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer()) | ||
scriptEntry.addObject("target", ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getDenizenEntity()); | ||
else | ||
throw new InvalidArgumentsException("This command requires a linked player!"); | ||
} | ||
if (!scriptEntry.hasObject("entities")) { | ||
if (!((BukkitScriptEntryData)scriptEntry.entryData).hasNPC()) | ||
throw new InvalidArgumentsException("This command requires a linked NPC!"); | ||
else | ||
scriptEntry.addObject("entities", | ||
new dList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().identify())); | ||
} | ||
|
||
scriptEntry.defaultObject("stop", new Element(false)); | ||
} | ||
|
||
@Override | ||
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { | ||
// Get objects | ||
Element stop = scriptEntry.getElement("stop"); | ||
Element lead = scriptEntry.getElement("lead"); | ||
Element speed = scriptEntry.getElement("speed"); | ||
dList entities = scriptEntry.getdObject("entities"); | ||
dEntity target = scriptEntry.getdObject("target"); | ||
|
||
// Report to dB | ||
dB.report(scriptEntry, getName(), | ||
(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer() != null ? ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().debug() : "") | ||
+ (!stop.asBoolean() ? aH.debugObj("Action", "FOLLOW") : aH.debugObj("Action", "STOP")) | ||
+ (lead != null ? lead.debug() : "") | ||
+ entities.debug() | ||
+ target.debug()); | ||
|
||
for (dEntity entity : entities.filter(dEntity.class)) { | ||
if (entity.isNPC()) { | ||
dNPC npc = entity.getDenizenNPC(); | ||
if (lead != null) | ||
npc.getNavigator().getLocalParameters().distanceMargin(lead.asDouble()); | ||
|
||
if (speed != null) | ||
npc.getNavigator().getLocalParameters().speedModifier(speed.asFloat()); | ||
|
||
if (stop.asBoolean()) | ||
npc.getNavigator().cancelNavigation(); | ||
else | ||
npc.getNavigator().setTarget(target.getBukkitEntity(), false); | ||
} | ||
else { | ||
if (stop.asBoolean()) | ||
EntityMovement.stopFollowing(entity.getBukkitEntity()); | ||
else | ||
EntityMovement.follow(target.getBukkitEntity(), entity.getBukkitEntity(), | ||
speed != null ? speed.asDouble() : 0.3, lead != null ? lead.asDouble(): 3); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
src/main/java/net/aufdemrand/denizen/scripts/commands/npc/FollowCommand.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.