Skip to content

Commit

Permalink
Fixed #29
Browse files Browse the repository at this point in the history
  • Loading branch information
replaceitem committed May 3, 2022
1 parent cc07a12 commit 67cef1a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/Discarpet/script/values/common/DiscordValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +27,20 @@ public T getInternal() {
@SuppressWarnings("unchecked")
public static <V> Value of(V object) {
if(object == null) return Value.NULL;
OutputConverter<V> outputConverter = (OutputConverter<V>) OutputConverter.get(object.getClass());
OutputConverter<V> outputConverter = null;
try {
outputConverter = (OutputConverter<V>) OutputConverter.get(object.getClass());
} catch (NullPointerException ignored) {}
if(outputConverter == null) {
Class<?>[] interfaces = object.getClass().getInterfaces();
for (Class<?> interfaceClass : interfaces) {
try {
outputConverter = (OutputConverter<V>) 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);
}

Expand Down

0 comments on commit 67cef1a

Please sign in to comment.