Skip to content

Commit

Permalink
improved ObjectProperty toolset
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 3, 2023
1 parent 75c9ecc commit 71c87c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
@@ -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);
}
}
Expand Up @@ -13,10 +13,7 @@ default ObjectTag getPropertyValue() {
}

@Deprecated
default String getPropertyString() {
ObjectTag res = getPropertyValue();
return res == null ? null : getPropertyValue().identify();
}
String getPropertyString();

String getPropertyId();

Expand Down
Expand Up @@ -141,14 +141,14 @@ public <R extends ObjectTag> void registerTagInternal(Class<R> returnType, Strin
public final ObjectTag getObjectAttribute(T object, Attribute attribute) {
if (attribute == null) {
if (CoreConfiguration.debugVerbose) {
Debug.log("TagProcessor - Attribute null!");
Debug.verboseLog("TagProcessor - Attribute null!");
}
return null;
}
attribute.lastValid = object;
if (attribute.isComplete()) {
if (CoreConfiguration.debugVerbose) {
Debug.log("TagProcessor - Attribute complete! Self return!");
Debug.verboseLog("TagProcessor - Attribute complete! Self return!");
}
return object;
}
Expand All @@ -160,12 +160,12 @@ public final ObjectTag getObjectAttribute(T object, Attribute attribute) {
}
if (data != null) {
if (CoreConfiguration.debugVerbose) {
Debug.log("TagProcessor - Sub-tag found for " + nextComponent.key);
Debug.verboseLog("TagProcessor - Sub-tag found for " + nextComponent.key);
}
returned = data.runner.run(attribute, object);
if (returned == null) {
if (CoreConfiguration.debugVerbose) {
Debug.log("TagProcessor - result was null");
Debug.verboseLog("TagProcessor - result was null");
}
attribute.trackLastTagFailure();
return null;
Expand Down

0 comments on commit 71c87c2

Please sign in to comment.