/
LookcloseCommand.java
92 lines (69 loc) · 2.65 KB
/
LookcloseCommand.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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.objects.aH.ArgumentType;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.trait.LookClose;
/**
* Configures the LookClose Trait for a NPC.
*
* @author Jeremy Schroeder
*/
public class LookcloseCommand extends AbstractCommand {
/* LOOKCLOSE [TOGGLE:TRUE|FALSE] (RANGE:#.#) (REALISTIC) */
/*
* Arguments: [] - Required, () - Optional
*
*/
boolean toggle;
boolean realistic;
Double range;
NPC npc;
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Set some defaults based on the scriptEntry
npc = null;
range = null;
realistic = false;
toggle = true;
if (scriptEntry.getNPC() != null) npc = scriptEntry.getNPC().getCitizen();
// Parse Arguments
for (String arg : scriptEntry.getArguments()) {
if (aH.matchesArg("REALISTIC", arg)) {
realistic = true;
dB.echoDebug(Messages.DEBUG_SET_TYPE, arg);
} else if (aH.matchesValueArg("RANGE", arg, ArgumentType.Double)) {
range = aH.getDoubleFrom(arg);
dB.echoDebug(Messages.DEBUG_SET_RANGE, String.valueOf(range));
} else if (aH.matchesState(arg)) {
toggle = aH.getBooleanFrom(arg);
dB.echoDebug(Messages.DEBUG_TOGGLE, String.valueOf(toggle));
} else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
if (scriptEntry.getNPC() == null)
throw new InvalidArgumentsException(Messages.ERROR_NO_NPCID);
scriptEntry.addObject("realistic", realistic)
.addObject("range", range)
.addObject("toggle", toggle);
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get the instance of the trait that belongs to the target NPC
LookClose trait = npc.getTrait(LookClose.class);
trait.lookClose(toggle);
if (realistic) {
trait.setRealisticLooking(true);
}
if (range != null) {
trait.setRange(range.intValue());
}
}
@Override
public void onEnable() {
}
}