/
DefineCommand.java
67 lines (53 loc) · 2.53 KB
/
DefineCommand.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
package net.aufdemrand.denizen.scripts.commands.core;
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.aH.ArgumentType;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Listener;
/**
* Creates a queue/script-level variable.
*
* @author Jeremy Schroeder
*
*/
public class DefineCommand extends AbstractCommand implements Listener {
public String getHelp() {
return "Defines a script/queue-level variable. Once the queue is" +
"completed, this definition is destroyed. Definitions are meant" +
"to be used as temporary variables, if any kind of persistence " +
"is required, use a flag instead. Definitions can be recalled" +
"by any script entry in the same queue by using '%' characters" +
"enclosing the variable name.\n" +
" \n" +
"- define doomed_player p@mastaba \n" +
"- strike %doomed_player% \n";
}
public String getUsage() {
return "- define [id] [value]";
}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("definition")
&& !arg.matchesPrefix("value, v"))
scriptEntry.addObject("definition", arg.getValue().toLowerCase());
else if (!scriptEntry.hasObject("value")
&& !arg.matchesPrefix("definition, def, d"))
scriptEntry.addObject("value", arg.getValue());
}
if (!scriptEntry.hasObject("definition") || !scriptEntry.hasObject("value"))
throw new InvalidArgumentsException("Must specify a definition and value!");
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
scriptEntry.getResidingQueue().context
.put((String) scriptEntry.getObject("definition"),
(String) scriptEntry.getObject("value"));
}
}