-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
StrikeCommand.java
57 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
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.dLocation;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
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))
// Location arg
scriptEntry.addObject("location", arg.asType(dLocation.class).setPrefix("location"));
else if (arg.matches("no_damage") || arg.matches("nodamage"))
scriptEntry.addObject("damage", false);
}
// Check required args
if (!scriptEntry.hasObject("location"))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "LOCATION");
if (!scriptEntry.hasObject("damage"))
scriptEntry.addObject("damage", true);
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Extract objects from ScriptEntry
dLocation location = (dLocation) scriptEntry.getObject("location");
Boolean damage = (Boolean) scriptEntry.getObject("damage");
// Debugger
dB.report(getName(),
location.debug()
+ aH.debugObj("Damageable", String.valueOf(damage)));
// Play the sound
if (damage)
location.getWorld().strikeLightning(location);
else
location.getWorld().strikeLightningEffect(location);
}
}