diff --git a/src/main/java/me/fallenbreath/tweakermore/util/ReflectionUtil.java b/src/main/java/me/fallenbreath/tweakermore/util/ReflectionUtil.java index 831dd2a2..ce10ab02 100644 --- a/src/main/java/me/fallenbreath/tweakermore/util/ReflectionUtil.java +++ b/src/main/java/me/fallenbreath/tweakermore/util/ReflectionUtil.java @@ -20,25 +20,33 @@ package me.fallenbreath.tweakermore.util; +import me.fallenbreath.tweakermore.TweakerMoreMod; import org.jetbrains.annotations.Nullable; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.Map; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; public class ReflectionUtil { + private static final Map>> classCache = new ConcurrentHashMap<>(); + public static Optional> getClass(String className) { - try - { - return Optional.of(Class.forName(className)); - } - catch (ClassNotFoundException e) - { - return Optional.empty(); - } + return classCache.computeIfAbsent(className, k -> { + try + { + return Optional.of(Class.forName(className)); + } + catch (ClassNotFoundException e) + { + TweakerMoreMod.LOGGER.debug("ReflectionUtil.getClass '{}' not found", className); + return Optional.empty(); + } + }); } @SuppressWarnings("unchecked")