/
ScriptRequirement.java
98 lines (83 loc) · 3.39 KB
/
ScriptRequirement.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
90
91
92
93
94
95
96
97
98
package net.aufdemrand.denizen.scripts.requirements.core;
import net.aufdemrand.denizen.exceptions.RequirementCheckException;
import net.aufdemrand.denizen.scripts.commands.core.FailCommand;
import net.aufdemrand.denizen.scripts.commands.core.FinishCommand;
import net.aufdemrand.denizen.scripts.requirements.AbstractRequirement;
import net.aufdemrand.denizen.scripts.requirements.RequirementsContext;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.aH.ArgumentType;
import java.util.List;
public class ScriptRequirement extends AbstractRequirement {
private enum Type {FINISHED, FAILED, STEP}
@Override
public boolean check(RequirementsContext context, List<String> args) throws RequirementCheckException {
boolean outcome = false;
Type type = null;
String step = null;
int quantity = 1;
boolean exactly = false;
String checkScript = null;
for (String thisArg : args) {
if (aH.matchesArg("FINISHED, FAILED", thisArg)) {
try {
type = Type.valueOf(aH.getStringFrom(thisArg).toUpperCase());
}
catch (Exception e) {
dB.echoError("Invalid check type. Valid: FINISHED, FAILED, STEP.");
}
}
else if (aH.matchesScript(thisArg)) {
checkScript = aH.getStringFrom(thisArg).toUpperCase();
}
else if (aH.matchesValueArg("STEP", thisArg, ArgumentType.String)) {
step = aH.getStringFrom(thisArg).toUpperCase();
}
else if (aH.matchesQuantity(thisArg)) {
quantity = aH.getIntegerFrom(thisArg);
}
else if (aH.matchesArg("EXACTLY", thisArg))
//im pretty confident this was missing from the original requirement
{
exactly = true;
}
else {
dB.echoError("Could not match argument '" + thisArg + "'");
}
}
if (type != null && checkScript != null) {
switch (type) {
case FINISHED:
int finishes = FinishCommand.getScriptCompletes(context.getPlayer().getName(), checkScript);
if (exactly) {
if (quantity == finishes) {
outcome = true;
}
}
else {
if (finishes >= quantity) {
outcome = true;
}
}
break;
case FAILED:
int fails = FailCommand.getScriptFails(context.getPlayer().getName(), checkScript);
if (exactly) {
if (quantity == fails) {
outcome = true;
}
}
else {
if (fails >= quantity) {
outcome = true;
}
}
break;
case STEP:
// TODO: reimplement
break;
}
}
return outcome;
}
}