From 67cef1ae5f2d43f8cd6963ea3b08b0445a53cd35 Mon Sep 17 00:00:00 2001 From: replaceitem <40722305+replaceitem@users.noreply.github.com> Date: Tue, 3 May 2022 16:51:06 +0200 Subject: [PATCH] Fixed #29 --- .../script/values/common/DiscordValue.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/Discarpet/script/values/common/DiscordValue.java b/src/main/java/Discarpet/script/values/common/DiscordValue.java index 58029dfa..cd9ff8c6 100644 --- a/src/main/java/Discarpet/script/values/common/DiscordValue.java +++ b/src/main/java/Discarpet/script/values/common/DiscordValue.java @@ -2,6 +2,7 @@ import Discarpet.script.util.ValueUtil; import carpet.script.annotation.OutputConverter; +import carpet.script.exception.InternalExpressionException; import carpet.script.value.Value; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtString; @@ -26,7 +27,20 @@ public T getInternal() { @SuppressWarnings("unchecked") public static Value of(V object) { if(object == null) return Value.NULL; - OutputConverter outputConverter = (OutputConverter) OutputConverter.get(object.getClass()); + OutputConverter outputConverter = null; + try { + outputConverter = (OutputConverter) OutputConverter.get(object.getClass()); + } catch (NullPointerException ignored) {} + if(outputConverter == null) { + Class[] interfaces = object.getClass().getInterfaces(); + for (Class interfaceClass : interfaces) { + try { + outputConverter = (OutputConverter) OutputConverter.get(interfaceClass); + } catch (NullPointerException ignored) {} + if(outputConverter != null) break; + } + } + if(outputConverter == null) throw new InternalExpressionException("Could not find a suitable output converter for DiscordValue.of()"); return outputConverter.convert(object).evalValue(null); }