/
StrikeCommand.java
61 lines (46 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
60
61
package net.aufdemrand.denizen.scripts.commands.core;
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 {
// Initialize fields
dLocation location = null;
Boolean damage = true;
// Iterate through arguments
for (String arg : scriptEntry.getArguments()){
if (aH.matchesLocation(arg))
location = aH.getLocationFrom(arg);
else if (aH.matchesArg("NO_DAMAGE, NODAMAGE", arg))
damage = false;
else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
// Check required args
if (location == null)
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "LOCATION");
// Stash args in ScriptEntry for use in execute()
scriptEntry.addObject("location", location);
scriptEntry.addObject("damage", damage);
}
@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);
}
}