Class Classes

java.lang.Object
ch.njol.skript.registrations.Classes

public abstract class Classes extends Object
  • Method Details

    • registerClass

      public static <T> void registerClass(ClassInfo<T> info)
      Parameters:
      info - info about the class to register
    • onRegistrationsStop

      public static void onRegistrationsStop()
    • getClassInfos

      public static List<ClassInfo<?>> getClassInfos()
    • getClassInfo

      public static ClassInfo<?> getClassInfo(String codeName)
      This method can be called even while Skript is loading.
      Parameters:
      codeName -
      Returns:
      The ClassInfo with the given code name
      Throws:
      SkriptAPIException - If the given class was not registered
    • getClassInfoNoError

      @Nullable public static @Nullable ClassInfo<?> getClassInfoNoError(@Nullable @Nullable String codeName)
      This method can be called even while Skript is loading.
      Parameters:
      codeName -
      Returns:
      The class info registered with the given code name or null if the code name is invalid or not yet registered
    • getExactClassInfo

      @Nullable public static <T> @Nullable ClassInfo<T> getExactClassInfo(@Nullable @Nullable Class<T> c)
      Gets the class info for the given class.

      This method can be called even while Skript is loading.

      Parameters:
      c - The exact class to get the class info for.
      Returns:
      The class info for the given class or null if no info was found.
    • getSuperClassInfo

      public static <T> ClassInfo<? super T> getSuperClassInfo(Class<T> c)
      Gets the class info of the given class or its closest registered superclass. This method will never return null unless c is null.
      Parameters:
      c -
      Returns:
      The closest superclass's info
    • getSuperClassInfo

      public static ClassInfo<?> getSuperClassInfo(Class<?>... classes)
      Gets the class info of the super type of given classes or its closest registered superclass. This method is useful for Skript to avoid passing around "unknown" super types.
      Parameters:
      classes - The classes to determine a super type from.
      Returns:
      The closest info for the super type of classes.
    • getAllSuperClassInfos

      public static <T> List<ClassInfo<? super T>> getAllSuperClassInfos(Class<T> c)
      Gets all the class info of the given class in closest order to ending on object. This list will never be empty unless c is null.
      Parameters:
      c - the class to check if assignable from
      Returns:
      The closest list of superclass infos
    • getClass

      public static Class<?> getClass(String codeName)
      Gets a class by its code name
      Parameters:
      codeName -
      Returns:
      the class with the given code name
      Throws:
      SkriptAPIException - If the given class was not registered
    • getClassInfoFromUserInput

      @Nullable public static @Nullable ClassInfo<?> getClassInfoFromUserInput(String name)
      As the name implies
      Parameters:
      name -
      Returns:
      the class info or null if the name was not recognised
    • getClassFromUserInput

      @Nullable public static @Nullable Class<?> getClassFromUserInput(String name)
      As the name implies
      Parameters:
      name -
      Returns:
      the class or null if the name was not recognized
    • getDefaultExpression

      @Nullable public static @Nullable DefaultExpression<?> getDefaultExpression(String codeName)
      Gets the default of a class
      Parameters:
      codeName -
      Returns:
      the expression holding the default value or null if this class doesn't have one
      Throws:
      SkriptAPIException - If the given class was not registered
    • getDefaultExpression

      @Nullable public static <T> @Nullable DefaultExpression<T> getDefaultExpression(Class<T> c)
      Gets the default expression of a class
      Parameters:
      c - The class
      Returns:
      The expression holding the default value or null if this class doesn't have one
    • clone

      public static Object clone(Object obj)
      Clones the given object by calling ClassInfo.clone(Object), getting the ClassInfo from the closest registered superclass (or the given object's class). Supports arrays too.
    • getExactClassName

      @Nullable public static @Nullable String getExactClassName(Class<?> c)
      Gets the name a class was registered with.
      Parameters:
      c - The exact class
      Returns:
      The name of the class or null if the given class wasn't registered.
    • parseSimple

      @Nullable public static <T> T parseSimple(String s, Class<T> c, ParseContext context)
      Parses without trying to convert anything.

      Can log an error xor other log messages.

      Parameters:
      s -
      c -
      Returns:
      The parsed object
    • parse

      @Nullable public static <T> T parse(String s, Class<T> c, ParseContext context)
      Parses a string to get an object of the desired type.

      Instead of repeatedly calling this with the same class argument, you should get a parser with getParser(Class) and use it for parsing.

      Can log an error if it returned null.

      Parameters:
      s - The string to parse
      c - The desired type. The returned value will be of this type or a subclass if it.
      Returns:
      The parsed object
    • getParser

      @Nullable public static <T> @Nullable Parser<? extends T> getParser(Class<T> to)
      Gets a parser for parsing instances of the desired type from strings. The returned parser may only be used for parsing, i.e. you must not use its toString methods.
      Parameters:
      to -
      Returns:
      A parser to parse object of the desired type
    • getExactParser

      @Nullable public static <T> @Nullable Parser<? extends T> getExactParser(Class<T> c)
      Gets a parser for an exactly known class. You should usually use getParser(Class) instead of this method.

      The main benefit of this method is that it's the only class info method of Skript that can be used while Skript is initializing and thus useful for parsing configs.

      Parameters:
      c -
      Returns:
      A parser to parse object of the desired type
    • toString

      public static String toString(@Nullable @Nullable Object o)
      Parameters:
      o - Any object, preferably not an array: use toString(Object[], boolean) instead.
      Returns:
      String representation of the object (using a parser if found or String.valueOf(Object) otherwise).
      See Also:
    • getDebugMessage

      public static String getDebugMessage(@Nullable @Nullable Object o)
    • toString

      public static <T> String toString(@Nullable T o, StringMode mode)
    • toString

      public static String toString(Object[] os, int flags, boolean and)
    • toString

      public static String toString(Object[] os, int flags, @Nullable @Nullable org.bukkit.ChatColor c)
    • toString

      public static String toString(Object[] os, boolean and)
    • toString

      public static String toString(Object[] os, boolean and, StringMode mode)
    • serialize

      public static @Nullable SerializedVariable.Value serialize(@Nullable @Nullable Object o)
      Must be called on the appropriate thread for the given value (i.e. the main thread currently)
    • deserialize

      @Nullable public static @Nullable Object deserialize(ClassInfo<?> type, byte[] value)
    • deserialize

      @Nullable public static @Nullable Object deserialize(String type, byte[] value)
    • deserialize

      @Nullable public static @Nullable Object deserialize(ClassInfo<?> type, InputStream value)
    • deserialize

      @Deprecated @Nullable public static @Nullable Object deserialize(String type, String value)
      Deprecated.
      Deserialises an object.

      This method must only be called from Bukkits main thread!

      Parameters:
      type -
      value -
      Returns:
      Deserialised value or null if the input is invalid