diff --git a/src/main/java/io/github/thegatesdev/maple/data/DataElement.java b/src/main/java/io/github/thegatesdev/maple/data/DataElement.java index da4ad2bf..b1ad1e93 100644 --- a/src/main/java/io/github/thegatesdev/maple/data/DataElement.java +++ b/src/main/java/io/github/thegatesdev/maple/data/DataElement.java @@ -178,17 +178,28 @@ public final void ifList(Consumer listConsumer) { } /** - * Unsafe cast to E + * Unsafe cast this element to E * - * @param elementClass The class to cast to. - * @param The type to cast to. + * @param The type to cast this element to. * @return The cast element. */ @SuppressWarnings("unchecked") - public E asUnsafe(Class elementClass) { + public E unsafeCast() { return (E) this; } + /** + * Cast this element to E + * + * @param The type to cast this element to. + * @param elementClass The class to cast this element with. + * @return The same DataElement as E, or null if this element does not conform to elementClass. + */ + @SuppressWarnings("unchecked") + public E castOrNull(Class elementClass) { + return elementClass.isInstance(this) ? (E) this : null; + } + /** * @return {@code true} if this element's name is not {@code null} */