-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
AttackCommand.java
64 lines (49 loc) · 1.89 KB
/
AttackCommand.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
59
60
61
62
63
64
package net.aufdemrand.denizen.scripts.commands.npc;
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.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
/**
*
* TODO: Document usage
*
* Instructs the NPC to follow a player.
*
* @author aufdemrand
*
*/
public class AttackCommand extends AbstractCommand {
private enum Action { START, STOP }
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
Action action = Action.START;
// Parse Arguments
for (String arg : scriptEntry.getArguments()) {
if (aH.matchesArg("STOP", arg))
action = Action.STOP;
// TODO: Add TARGET: argument.
else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
// Stash objects into ScriptEntry
scriptEntry.addObject("action", action);
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
Action action = (Action) scriptEntry.getObject("action");
// Report to dB
dB.report(getName(),
aH.debugObj("Player", scriptEntry.getPlayer().getName())
+ aH.debugObj("Action", action.toString()));
// Stop fighting
if (action == Action.STOP)
scriptEntry.getNPC().getNavigator()
.cancelNavigation();
// Start attacking
else
scriptEntry.getNPC().getNavigator()
.setTarget(scriptEntry.getPlayer().getPlayerEntity(), true);
}
}