-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
ObjectProperty.java
29 lines (21 loc) · 1.27 KB
/
ObjectProperty.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
package com.denizenscript.denizencore.objects.properties;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
public abstract class ObjectProperty<TObj extends ObjectTag, TData extends ObjectTag> implements Property {
public TObj object;
public abstract TData getPropertyValue();
public boolean isDefaultValue(TData data) {
return false;
}
@Deprecated @Override
public String getPropertyString() {
TData res = getPropertyValue();
return res == null || isDefaultValue(res) ? null : getPropertyValue().identify();
}
public abstract void setPropertyValue(TData data, Mechanism mechanism);
public static <TObj extends ObjectTag, TData extends ObjectTag, TProp extends ObjectProperty<TObj, TData>>
void autoRegister(String name, Class<TProp> propClass, Class<TData> dataClass, boolean isStatic, String... deprecatedVariants) {
PropertyParser.registerTagInternal(propClass, dataClass, name, (attribute, prop) -> prop.getPropertyValue(), deprecatedVariants, isStatic);
PropertyParser.registerMechanism(propClass, dataClass, name, (prop, mechanism, param) -> prop.setPropertyValue(param, mechanism), deprecatedVariants);
}
}