-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
FollowCommand.java
58 lines (46 loc) · 2.06 KB
/
FollowCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package net.aufdemrand.denizen.scripts.commands.core;
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.arguments.aH;
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 (String arg : scriptEntry.getArguments()) {
if (aH.matchesArg("STOP", arg))
scriptEntry.addObject("stop", true);
else if (aH.matchesValueArg("LEAD", arg, aH.ArgumentType.Double))
scriptEntry.addObject("lead", aH.getDoubleFrom(arg));
else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
Boolean stop = (Boolean) scriptEntry.getObject("stop");
Double lead = (Double) scriptEntry.getObject("lead");
// Report to dB
dB.report(getName(),
aH.debugObj("Player", scriptEntry.getPlayer().getName())
+ (stop == null ? aH.debugObj("Action", "FOLLOW")
: aH.debugObj("Action", "STOP"))
+ (lead != null ? aH.debugObj("Lead", lead.toString()) : "" ));
if (lead != null)
scriptEntry.getNPC().getNavigator().getLocalParameters().distanceMargin(lead);
if (stop != null)
scriptEntry.getNPC().getNavigator()
.cancelNavigation();
else
scriptEntry.getNPC().getNavigator()
.setTarget(scriptEntry.getPlayer(), false);
}
}