mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 01:49:30 +00:00
修复condition component错误
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package net.momirealms.craftengine.core.pack.model.condition;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.momirealms.craftengine.core.util.GsonHelper;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
@@ -10,9 +12,9 @@ public class ComponentConditionProperty implements ConditionProperty {
|
||||
public static final Factory FACTORY = new Factory();
|
||||
public static final Reader READER = new Reader();
|
||||
private final String predicate;
|
||||
private final String value;
|
||||
private final JsonElement value;
|
||||
|
||||
public ComponentConditionProperty(String predicate, String value) {
|
||||
public ComponentConditionProperty(String predicate, JsonElement value) {
|
||||
this.predicate = predicate;
|
||||
this.value = value;
|
||||
}
|
||||
@@ -26,15 +28,15 @@ public class ComponentConditionProperty implements ConditionProperty {
|
||||
public void accept(JsonObject jsonObject) {
|
||||
jsonObject.addProperty("property", type().toString());
|
||||
jsonObject.addProperty("predicate", this.predicate);
|
||||
jsonObject.addProperty("value", this.value);
|
||||
jsonObject.add("value", this.value);
|
||||
}
|
||||
|
||||
public static class Factory implements ConditionPropertyFactory {
|
||||
@Override
|
||||
public ConditionProperty create(Map<String, Object> arguments) {
|
||||
String predicate = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("predicate"), "warning.config.item.model.condition.component.missing_predicate");
|
||||
String value = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value"), "warning.config.item.model.condition.component.missing_value");
|
||||
return new ComponentConditionProperty(predicate, value);
|
||||
JsonElement jsonElement = GsonHelper.get().toJsonTree(ResourceConfigUtils.requireNonNullOrThrow(arguments.get("value"), "warning.config.item.model.condition.component.missing_value"));
|
||||
return new ComponentConditionProperty(predicate, jsonElement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +44,7 @@ public class ComponentConditionProperty implements ConditionProperty {
|
||||
@Override
|
||||
public ConditionProperty read(JsonObject json) {
|
||||
String predicate = json.get("predicate").getAsString();
|
||||
String value = json.get("value").getAsString();
|
||||
JsonElement value = json.get("value");
|
||||
return new ComponentConditionProperty(predicate, value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user