-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
ResetCommand.java
78 lines (55 loc) · 2.79 KB
/
ResetCommand.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
package net.aufdemrand.denizen.scripts.commands.core;
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.Duration;
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
public class ResetCommand extends AbstractCommand {
private enum Type { FINISH, FAIL, PLAYER_COOLDOWN, GLOBAL_COOLDOWN }
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
dScript script = scriptEntry.getScript();
Type type = null;
for (String arg : scriptEntry.getArguments()) {
if (aH.matchesArg("finishes, finished, finish", arg))
type = Type.FINISH;
else if (aH.matchesArg("fail, fails, failed", arg))
type = Type.FAIL;
else if (aH.matchesArg("cooldown", arg))
type = Type.PLAYER_COOLDOWN;
else if (aH.matchesArg("global_cooldown", arg))
type = Type.GLOBAL_COOLDOWN;
else if (aH.matchesScript(arg))
script = aH.getScriptFrom(arg);
else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}
if (type == null)
throw new InvalidArgumentsException("Must specify a type! Valid: FAILS, FINISHES, COOLDOWN, GLOBAL_COOLDOWN");
if (scriptEntry.getPlayer() == null && type != Type.GLOBAL_COOLDOWN)
throw new InvalidArgumentsException(dB.Messages.ERROR_NO_PLAYER);
scriptEntry.addObject("script", script)
.addObject("type", type);
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Type type = (Type) scriptEntry.getObject("type");
dScript script = (dScript) scriptEntry.getObject("script");
switch (type) {
case FAIL:
FailCommand.resetFails(scriptEntry.getPlayer().getName(), script.getName());
return;
case FINISH:
FinishCommand.resetFinishes(scriptEntry.getPlayer().getName(), script.getName());
return;
case PLAYER_COOLDOWN:
CooldownCommand.setCooldown(scriptEntry.getPlayer().getName(), Duration.ZERO, script.getName(), false);
return;
case GLOBAL_COOLDOWN:
CooldownCommand.setCooldown(scriptEntry.getPlayer().getName(), Duration.ZERO, script.getName(), true);
return;
}
}
}