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

      public static @Nullable ClassInfo<?> getClassInfoNoError(@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

      public static <T> @Nullable ClassInfo<T> getExactClassInfo(@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 of 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
    • 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

      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

      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

      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

      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

      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

      public static <T> @Nullable 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

      public static <T> @Nullable 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

      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

      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 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:
      toString(Object, StringMode), toString(Object[], boolean), toString(Object[], boolean, StringMode), Parser
    • getDebugMessage

      public static String getDebugMessage(@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 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 Object o)
      Must be called on the appropriate thread for the given value (i.e. the main thread currently)
    • deserialize

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

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

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

      @Deprecated 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