Skip to content

Commit

Permalink
Add lookat to walk command
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 8, 2016
1 parent a1d1b14 commit ddc0203
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Expand Up @@ -3876,7 +3876,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name Walk
// @Syntax walk (<entity>|...) [<location>/stop] (speed:<#.#>) (auto_range) (radius:<#.#>)
// @Syntax walk (<entity>|...) [<location>/stop] (speed:<#.#>) (auto_range) (radius:<#.#>) (lookat:<location>)
// @Required 1
// @Stable stable
// @Short Causes an entity or list of entities to walk to another location.
Expand All @@ -3896,7 +3896,7 @@ public void registerCoreMembers() {
// TODO: Document Command Details
// -->
registerCoreMember(WalkCommand.class,
"WALK, WALKTO", "walk (<entity>|...) [<location>/stop] (speed:<#>) (auto_range) (radius:<#.#>)", 1);
"WALK, WALKTO", "walk (<entity>|...) [<location>/stop] (speed:<#>) (auto_range) (radius:<#.#>) (lookat:<location>)", 1);

// <--[command]
// @Name Weather
Expand Down
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.scripts.commands.entity;

import com.google.common.base.Function;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dLocation;
Expand All @@ -16,6 +17,8 @@
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import net.aufdemrand.denizencore.scripts.commands.Holdable;
import net.citizensnpcs.api.ai.Navigator;
import org.bukkit.Location;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -34,9 +37,10 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("location")
if (!scriptEntry.hasObject("lookat")
&& arg.matchesPrefix("lookat")
&& arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("location", arg.asType(dLocation.class));
scriptEntry.addObject("lookat", arg.asType(dLocation.class));
}

else if (!scriptEntry.hasObject("speed")
Expand All @@ -61,6 +65,11 @@ else if (!scriptEntry.hasObject("stop")
scriptEntry.addObject("stop", new Element(true));
}

else if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(dLocation.class)) {
scriptEntry.addObject("location", arg.asType(dLocation.class));
}

else if (!scriptEntry.hasObject("entities")
&& arg.matchesArgumentList(dEntity.class)) {
scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
Expand Down Expand Up @@ -105,6 +114,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element radius = scriptEntry.getElement("radius");
Element stop = scriptEntry.getElement("stop");
List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
final dLocation lookat = scriptEntry.getdObject("lookat");


// Debug the execution
Expand All @@ -113,6 +123,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
+ (speed != null ? speed.debug() : "")
+ (auto_range != null ? auto_range.debug() : "")
+ (radius != null ? radius.debug() : "")
+ (lookat != null ? lookat.debug() : "")
+ stop.debug()
+ (aH.debugObj("entities", entities)));

Expand Down Expand Up @@ -146,6 +157,15 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

npc.getNavigator().setTarget(loc);

if (lookat != null) {
npc.getNavigator().getLocalParameters().lookAtFunction(new Function<Navigator, Location>() {
@Override
public Location apply(Navigator nav) {
return lookat;
}
});
}

if (speed != null) {
npc.getNavigator().getLocalParameters().speedModifier(speed.asFloat());
}
Expand Down

0 comments on commit ddc0203

Please sign in to comment.