Class ConfigProxy<T>

java.lang.Object
tech.guilhermekaua.spigotboot.config.proxy.ConfigProxy<T>
Type Parameters:
T - the config type
All Implemented Interfaces:
MethodInterceptor

public final class ConfigProxy<T> extends Object implements MethodInterceptor
A proxy that intercepts all method calls on a config class and delegates to the current config instance from ConfigRef.get().

This ensures that injected config instances always return fresh values after reload, without requiring developers to use ConfigRef<T>.get() explicitly.

Important: Config classes must have all fields private to ensure proper proxying. Direct field access bypasses the proxy and will return stale/default values.

  • Method Details

    • createProxy

      @NotNull public static <T> T createProxy(@NotNull @NotNull Class<T> configClass, @NotNull @NotNull ConfigRef<T> configRef)
      Creates a proxy for the given config class that delegates all method calls to the current config instance from the ConfigRef.
      Type Parameters:
      T - the config type
      Parameters:
      configClass - the config class to proxy
      configRef - the config ref providing the current instance
      Returns:
      a proxy instance that appears as the config class
      Throws:
      ConfigException - if proxy creation fails
    • invoke

      public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
      Specified by:
      invoke in interface MethodInterceptor
      Throws:
      Throwable