/
StrikeCommand.java
59 lines (43 loc) · 2.06 KB
/
StrikeCommand.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
package net.aufdemrand.denizen.scripts.commands.world;
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.Element;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
public class StrikeCommand extends AbstractCommand {
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(dLocation.class))
scriptEntry.addObject("location", arg.asType(dLocation.class));
else if (arg.matches("no_damage") || arg.matches("nodamage"))
scriptEntry.addObject("damage", Element.FALSE);
else
arg.reportUnhandled();
}
// Check required args
if (!scriptEntry.hasObject("location"))
throw new InvalidArgumentsException("Missing location argument!");
scriptEntry.defaultObject("damage", Element.TRUE);
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Extract objects from ScriptEntry
dLocation location = (dLocation) scriptEntry.getObject("location");
Boolean damage = scriptEntry.getElement("damage").asBoolean();
// Debugger
dB.report(scriptEntry, getName(),
location.debug()
+ aH.debugObj("Damageable", String.valueOf(damage)));
// Play the sound
if (damage)
location.getWorld().strikeLightning(location);
else
location.getWorld().strikeLightningEffect(location);
}
}