blob: b348367f9a92330fd0f1b1cde58df376ef3d93df (
plain)
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
|
package shcm.shsupercm.fabric.citresewn.cit.builtin.conditions;
import shcm.shsupercm.fabric.citresewn.cit.CITCondition;
import shcm.shsupercm.fabric.citresewn.cit.CITContext;
import shcm.shsupercm.fabric.citresewn.cit.CITParsingException;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
/**
* Common condition parser for booleans.
*/
public abstract class BooleanCondition extends CITCondition {
/**
* Parsed boolean.
*/
protected boolean value;
/**
* Converts the given context to a boolean to compare the parsed value to.
* @param context context to retrieve the compared value from
* @return the boolean value associated with the given context
*/
protected boolean getValue(CITContext context) {
throw new AssertionError("Not implemented by this condition");
}
@Override
public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException {
if (value.value().equalsIgnoreCase("true"))
this.value = true;
else if (value.value().equalsIgnoreCase("false"))
this.value = false;
else
throw new CITParsingException("Not a boolean", properties, value.position());
}
@Override
public boolean test(CITContext context) {
return getValue(context) == this.value;
}
}
|