-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
PoweredRequirement.java
52 lines (42 loc) · 1.74 KB
/
PoweredRequirement.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
package net.aufdemrand.denizen.scripts.requirements.core;
import net.aufdemrand.denizen.exceptions.RequirementCheckException;
import net.aufdemrand.denizen.objects.dLocation;
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 org.bukkit.block.Block;
import java.util.List;
public class PoweredRequirement extends AbstractRequirement {
@Override
public boolean check(RequirementsContext context, List<String> args) throws RequirementCheckException {
boolean outcome = false;
Block blockToCheck = null;
for (String thisArg : args) {
if (aH.matchesLocation(thisArg)) {
blockToCheck = dLocation.valueOf(thisArg).getBlock();
if (blockToCheck != null) {
dB.echoDebug(context.getScriptContainer(), "...block to check is type '" + blockToCheck.getType().toString() + "'");
}
}
else {
dB.echoError("Could not match argument '" + thisArg + "'");
}
}
if (blockToCheck != null) {
if (blockToCheck.isBlockPowered()) {
outcome = true;
}
else if (blockToCheck.isBlockIndirectlyPowered()) {
outcome = true;
}
}
if (outcome) {
dB.echoDebug(context.getScriptContainer(), "...block is powered!");
}
else {
dB.echoDebug(context.getScriptContainer(), "...block is not powered!");
}
return outcome;
}
}