/
ExplodeCommand.java
72 lines (56 loc) · 2.89 KB
/
ExplodeCommand.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
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.utilities.arguments.aH;
import net.aufdemrand.denizen.utilities.arguments.aH.ArgumentType;
import net.aufdemrand.denizen.utilities.arguments.dLocation;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
/**
* Create an explosion at a location.
* If no location is specified, create the explosion where the NPC is.
*
* @author Alain Blanquet
*/
public class ExplodeCommand extends AbstractCommand {
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
dLocation location = null;
Float power = 1F;
boolean breakblocks = false;
boolean setFire = false;
for (String arg : scriptEntry.getArguments()) {
if (aH.matchesLocation(arg)) {
location = aH.getLocationFrom(arg);
dB.echoDebug("...location set to '%s'.", arg);
} else if (aH.matchesValueArg("power", arg, ArgumentType.Float)) {
power = aH.getFloatFrom(arg);
dB.echoDebug("...will have a power of " + power);
} else if (aH.matchesArg("breakblocks", arg)) {
breakblocks = true;
dB.echoDebug("...will break blocks.");
} else if (aH.matchesArg("setFire", arg)) {
setFire = true;
dB.echoDebug("...will set Fire on blocks.");
} else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
// Stash objects
scriptEntry.addObject("location", location);
scriptEntry.addObject("power", power);
scriptEntry.addObject("breakblocks", breakblocks);
scriptEntry.addObject("setFire", setFire);
}
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
final dLocation location = scriptEntry.hasObject("location") ?
(dLocation) scriptEntry.getObject("location") :
(dLocation) scriptEntry.getNPC().getLocation();
Float power = (Float) scriptEntry.getObject("power");
boolean breakblocks = (Boolean) scriptEntry.getObject("breakblocks");
boolean setFire = (Boolean) scriptEntry.getObject("setFire");
location.getWorld().createExplosion(location.getX(),location.getY(),location.getZ(), (Float) power,breakblocks,setFire);
}
}