diff --git a/src/main/java/org/cyclops/integratedscripting/api/evaluate/translation/IEvaluationExceptionFactory.java b/src/main/java/org/cyclops/integratedscripting/api/evaluate/translation/IEvaluationExceptionFactory.java index ce2ff6d7..812e846b 100644 --- a/src/main/java/org/cyclops/integratedscripting/api/evaluate/translation/IEvaluationExceptionFactory.java +++ b/src/main/java/org/cyclops/integratedscripting/api/evaluate/translation/IEvaluationExceptionFactory.java @@ -1,5 +1,7 @@ package org.cyclops.integratedscripting.api.evaluate.translation; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import org.cyclops.integrateddynamics.api.evaluate.EvaluationException; /** @@ -8,6 +10,10 @@ */ public interface IEvaluationExceptionFactory { - public EvaluationException createError(String message); + public default EvaluationException createError(String message) { + return this.createError(Component.literal(message)); + } + + public EvaluationException createError(MutableComponent message); } diff --git a/src/main/java/org/cyclops/integratedscripting/evaluate/ScriptHelpers.java b/src/main/java/org/cyclops/integratedscripting/evaluate/ScriptHelpers.java index 0f22c17d..2c98ddaf 100644 --- a/src/main/java/org/cyclops/integratedscripting/evaluate/ScriptHelpers.java +++ b/src/main/java/org/cyclops/integratedscripting/evaluate/ScriptHelpers.java @@ -83,10 +83,10 @@ public static String getPathExtension(Path path) { } public static IEvaluationExceptionFactory getDummyEvaluationExceptionFactory() { - return message -> new EvaluationException(Component.literal(message)); + return EvaluationException::new; } - public static IEvaluationExceptionFactory getEvaluationExceptionFactory(int disk, Path path,String member) { + public static IEvaluationExceptionFactory getEvaluationExceptionFactory(int disk, Path path, String member) { return message -> new EvaluationException(Component.translatable("script.integratedscripting.error.script_exec", member, path.toString(), disk, message)); } diff --git a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/ValueTranslatorRegistry.java b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/ValueTranslatorRegistry.java index 1a70c5b2..25c4a099 100644 --- a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/ValueTranslatorRegistry.java +++ b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/ValueTranslatorRegistry.java @@ -51,7 +51,7 @@ public IValueTranslator getValueTypeTranslator(IValueType public Value translateToGraal(Context context, V value, IEvaluationExceptionFactory exceptionFactory) throws EvaluationException { IValueTranslator translator = getValueTypeTranslator(value.getType()); if (translator == null) { - throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.unknown_to_graal", value.getType())); + throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.unknown_to_graal", value.getType())); } return translator.translateToGraal(context, value, exceptionFactory); } @@ -70,7 +70,7 @@ public IValueTranslator getScriptValueTranslator(Value scriptValue) { public V translateFromGraal(Context context, Value value, IEvaluationExceptionFactory exceptionFactory) throws EvaluationException { IValueTranslator translator = getScriptValueTranslator(value); if (translator == null) { - throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.unknown_from_graal", value)); + throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.unknown_from_graal", value)); } return (V) translator.translateFromGraal(context, value, exceptionFactory); } @@ -79,11 +79,11 @@ public V translateFromGraal(Context context, Value value, IEv public Tag translateToNbt(Context context, V value, IEvaluationExceptionFactory exceptionFactory) throws EvaluationException { IValueTranslator translator = getValueTypeTranslator(value.getType()); if (translator == null) { - throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.unknown_to_graal_nbt", value.getType())); + throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.unknown_to_graal_nbt", value.getType())); } if (translator.canTranslateNbt()) { return translator.translateToNbt(context, value, exceptionFactory); } - throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.nbt_unmatched", value.getType())); + throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.nbt_unmatched", value.getType())); } } diff --git a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueObjectProxyObject.java b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueObjectProxyObject.java index 756d7628..5f79fb78 100644 --- a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueObjectProxyObject.java +++ b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueObjectProxyObject.java @@ -3,7 +3,6 @@ import lombok.SneakyThrows; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; -import org.cyclops.integrateddynamics.api.evaluate.EvaluationException; import org.cyclops.integrateddynamics.api.evaluate.operator.IOperator; import org.cyclops.integrateddynamics.api.evaluate.variable.IValue; import org.cyclops.integrateddynamics.core.evaluate.operator.CurriedOperator; @@ -86,6 +85,6 @@ public boolean hasMember(String key) { @SneakyThrows @Override public void putMember(String key, Value value) { - throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.proxyobject_putMember", key, valueType.getTypeName())); + throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.proxyobject_putMember", key, valueType.getTypeName())); } } diff --git a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorList.java b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorList.java index c13f9e99..4a5dd1ff 100644 --- a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorList.java +++ b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorList.java @@ -42,7 +42,7 @@ public boolean canTranslateNbt() { @Override public Value translateToGraal(Context context, ValueTypeList.ValueList value, IEvaluationExceptionFactory exceptionFactory) throws EvaluationException { if (value.getRawValue().isInfinite()) { - throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.list_infinite")); + throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.list_infinite")); } // The following should work according to the docs, but doesn't. So we fallback to a sub-optimal approach. @@ -67,7 +67,7 @@ public ValueTypeList.ValueList translateFromGraal(Context context, Value value, @Override public Tag translateToNbt(Context context, ValueTypeList.ValueList value, IEvaluationExceptionFactory exceptionFactory) throws EvaluationException { if (value.getRawValue().isInfinite()) { - throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.list_infinite")); + throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.list_infinite")); } ListTag tag = new ListTag(); diff --git a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorNbt.java b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorNbt.java index 374c270d..376a7a69 100644 --- a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorNbt.java +++ b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorNbt.java @@ -95,7 +95,7 @@ public Value translateTag(Context context, Tag tag, IEvaluationExceptionFactory case Tag.TAG_LONG_ARRAY -> { return context.asValue(((LongArrayTag) tag).getAsLongArray()); } - default -> throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.nbt_unknown", tag.getType().getPrettyName())); + default -> throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.nbt_unknown", tag.getType().getPrettyName())); } } diff --git a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorObjectAdapter.java b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorObjectAdapter.java index afc49422..52ae271a 100644 --- a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorObjectAdapter.java +++ b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorObjectAdapter.java @@ -118,6 +118,6 @@ public V translateFromGraal(Context context, Value value, IEvaluationExceptionFa @Override public Tag translateToNbt(Context context, V value, IEvaluationExceptionFactory exceptionFactory) throws EvaluationException { - throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.unsupported_translateToNbt", Component.translatable(value.getType().getTranslationKey()), value.getType().toCompactString(value))); + throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.unsupported_translateToNbt", Component.translatable(value.getType().getTranslationKey()), value.getType().toCompactString(value))); } } diff --git a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorOperator.java b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorOperator.java index 1588d774..0b63f4d2 100644 --- a/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorOperator.java +++ b/src/main/java/org/cyclops/integratedscripting/evaluate/translation/translator/ValueTranslatorOperator.java @@ -90,7 +90,7 @@ public ValueTypeOperator.ValueOperator translateFromGraal(Context context, Value @Override public Tag translateToNbt(Context context, ValueTypeOperator.ValueOperator value, IEvaluationExceptionFactory exceptionFactory) throws EvaluationException { - throw new EvaluationException(Component.translatable("valuetype.integratedscripting.error.translation.unsupported_translateToNbt", Component.translatable(value.getType().getTranslationKey()), value.getType().toCompactString(value))); + throw exceptionFactory.createError(Component.translatable("valuetype.integratedscripting.error.translation.unsupported_translateToNbt", Component.translatable(value.getType().getTranslationKey()), value.getType().toCompactString(value))); } public static class GraalOperator extends OperatorBase {