-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
StrikeCommand.java
89 lines (75 loc) · 3.19 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.denizenscript.denizen.scripts.commands.world;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.objects.dLocation;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.denizencore.objects.ElementTag;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
public class StrikeCommand extends AbstractCommand {
// <--[command]
// @Name Strike
// @Syntax strike (no_damage) [<location>]
// @Required 1
// @Short Strikes lightning down upon the location.
// @Group world
//
// @Description
// Causes lightning to strike at the specified location, which can optionally have damage disabled.
// The lightning will still cause fires to start, even without the 'no_damage' argument.
// Lightning caused by this command will cause creepers to activate. Using the no_damage argument makes the
// lightning do no damage to the player or any other entities, and means creepers struck will not activate.
//
// @Tags
// None
//
// @Usage
// Use to cause lightning to strike the player.
// - strike <player.location>
//
// @Usage
// Use to strike the player with lightning causing no damage.
// - strike no_damage <player.location>
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// Iterate through arguments
for (Argument arg : ArgumentHelper.interpretArguments(scriptEntry.aHArgs)) {
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", new ElementTag(false));
}
else {
arg.reportUnhandled();
}
}
// Check required args
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location argument!");
}
scriptEntry.defaultObject("damage", new ElementTag(true));
}
@Override
public void execute(ScriptEntry scriptEntry) {
// Extract objects from ScriptEntry
dLocation location = (dLocation) scriptEntry.getObject("location");
Boolean damage = scriptEntry.getElement("damage").asBoolean();
// Debugger
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
location.debug()
+ ArgumentHelper.debugObj("Damageable", String.valueOf(damage)));
}
// Play the sound
if (damage) {
location.getWorld().strikeLightning(location);
}
else {
location.getWorld().strikeLightningEffect(location);
}
}
}