Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75c9ecc
commit 71c87c2
Showing
3 changed files
with
28 additions
and
10 deletions.
There are no files selected for viewing
25 changes: 23 additions & 2 deletions
25
src/main/java/com/denizenscript/denizencore/objects/properties/ObjectProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
package com.denizenscript.denizencore.objects.properties; | ||
|
||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
|
||
public abstract class ObjectProperty<T extends ObjectTag> implements Property { | ||
public abstract class ObjectProperty<TObj extends ObjectTag, TData extends ObjectTag> implements Property { | ||
|
||
public T object; | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters