Class EventFactory

java.lang.Object
net.fabricmc.fabric.api.event.EventFactory

public final class EventFactory
extends Object
Helper for creating Event classes.
  • Method Details

    • isProfilingEnabled

      public static boolean isProfilingEnabled()
      Returns:
      True if events are supposed to be profiled.
    • invalidate

      public static void invalidate()
      Invalidate and re-create all existing "invoker" instances across events created by this EventFactory. Use this if, for instance, the profilingEnabled field changes.
    • createArrayBacked

      public static <T> Event<T> createArrayBacked​(Class<? super T> type, Function<T[],​T> invokerFactory)
      Create an "array-backed" Event instance.
      Type Parameters:
      T - The listener type.
      Parameters:
      type - The listener class type.
      invokerFactory - The invoker factory, combining multiple listeners into one instance.
      Returns:
      The Event instance.
    • createArrayBacked

      public static <T> Event<T> createArrayBacked​(Class<T> type, T emptyInvoker, Function<T[],​T> invokerFactory)
      Create an "array-backed" Event instance with a custom empty invoker.

      Having a custom empty invoker (of type (...) -> {}) increases performance relative to iterating over an empty array; however, it only really matters if the event is executed thousands of times a second.

      Type Parameters:
      T - The listener type.
      Parameters:
      type - The listener class type.
      emptyInvoker - The custom empty invoker.
      invokerFactory - The invoker factory, combining multiple listeners into one instance.
      Returns:
      The Event instance.
    • getHandlerName

      public static String getHandlerName​(Object handler)
      Get the listener object name. This can be used in debugging/profiling scenarios.
      Parameters:
      handler - The listener object.
      Returns:
      The listener name.