Class Util

java.lang.Object
de.Keyle.MyPet.api.Util

public class Util extends Object
Small helpers shared across the API: the sanitized MiniMessage instance for player-controlled text, a shared random source, and a few collection and HTTP conveniences.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final MiniMessage
    A restricted MiniMessage instance that only resolves safe visual tags.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Not intended for instantiation -- every member of this class is static.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    clamp(double val, double min, double max)
    Deprecated, for removal: This API element is subject to removal in a future version.
    use Math.clamp(long, int, int), which this now delegates to
    static float
    clamp(float val, float min, float max)
    Deprecated, for removal: This API element is subject to removal in a future version.
    use Math.clamp(long, int, int), which this now delegates to
    static int
    clamp(int val, int min, int max)
    Deprecated, for removal: This API element is subject to removal in a future version.
    use Math.clamp(long, int, int), which this now delegates to
    static String
    decimal2roman(int src)
    Converts a positive integer to its Roman numeral representation.
    static Set<Class<?>>
    Deprecated, for removal: This API element is subject to removal in a future version.
    internal helper with a single caller; do not use from addons
    static List<Class<?>>
    Deprecated, for removal: This API element is subject to removal in a future version.
    internal helper with a single caller; do not use from addons
    static <T extends Annotation>
    T
    getClassAnnotation(Class<?> clazz, Class<T> annotation)
    Deprecated.
    use AnnotationLookup.find(Class, Class), which this now delegates to
    static <T> void
    getClassParents(Class<?> clazz, Class<T> type, Set<Class<? extends T>> result)
    Deprecated.
    internal helper with a single caller; do not use from addons
    static Random
    Returns a random number generator for the calling thread.
    static boolean
    isInt(String number)
    Checks whether the given string can be parsed as an int.
    static String
    Deprecated, for removal: This API element is subject to removal in a future version.
    no replacement in the API; this was only used by MyPet itself, which now keeps its own copy.
    static String
    readUrlContent(String address, int timeout)
    Deprecated, for removal: This API element is subject to removal in a future version.
    no replacement in the API; this was only used by MyPet itself, which now keeps its own copy.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SANITIZED_MINIMESSAGE

      public static final MiniMessage SANITIZED_MINIMESSAGE
      A restricted MiniMessage instance that only resolves safe visual tags. Use this for user-controlled content (pet names, etc.) to prevent injection of click/hover/insertion events via MiniMessage tags.
  • Constructor Details

    • Util

      public Util()
      Not intended for instantiation -- every member of this class is static.
  • Method Details

    • getRandom

      public static Random getRandom()
      Returns a random number generator for the calling thread.

      This is ThreadLocalRandom.current(), so it is contention-free but must not be shared between threads or reseeded (setSeed is unsupported).

      Returns:
      the calling thread's random number generator
    • isInt

      public static boolean isInt(String number)
      Checks whether the given string can be parsed as an int.
      Parameters:
      number - the string to test
      Returns:
      true if the string is a valid integer, false otherwise
    • readUrlContent

      @Deprecated(since="4.1.0", forRemoval=true) public static String readUrlContent(String address) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      no replacement in the API; this was only used by MyPet itself, which now keeps its own copy. Use HttpClient directly.
      Fetches the content of a URL as a string using a default timeout of 10000ms.
      Parameters:
      address - the URL to fetch
      Returns:
      the response body as a string
      Throws:
      IOException - if the request fails or is interrupted
      See Also:
    • readUrlContent

      @Deprecated(since="4.1.0", forRemoval=true) public static String readUrlContent(String address, int timeout) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      no replacement in the API; this was only used by MyPet itself, which now keeps its own copy. Use HttpClient directly.
      Fetches the content of a URL as a string with a configurable timeout. The timeout applies to both the connection and the request as a whole.
      Parameters:
      address - the URL to fetch
      timeout - the timeout in milliseconds for both connect and read
      Returns:
      the response body as a string
      Throws:
      IOException - if the request fails or is interrupted
    • decimal2roman

      public static String decimal2roman(int src)
      Converts a positive integer to its Roman numeral representation. Used for displaying skill levels (e.g. level 4 as "IV").
      Parameters:
      src - the positive integer to convert
      Returns:
      the Roman numeral string, or an empty string if src is 0
    • clamp

      @Deprecated(since="4.1.0", forRemoval=true) public static double clamp(double val, double min, double max)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use Math.clamp(long, int, int), which this now delegates to
      Clamps a double value to the specified range.
      Parameters:
      val - the value to clamp
      min - the minimum allowed value
      max - the maximum allowed value
      Returns:
      min if val < min, max if val > max, otherwise val
      Throws:
      IllegalArgumentException - if min > max
    • clamp

      @Deprecated(since="4.1.0", forRemoval=true) public static float clamp(float val, float min, float max)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use Math.clamp(long, int, int), which this now delegates to
      Clamps a float value to the specified range.
      Parameters:
      val - the value to clamp
      min - the minimum allowed value
      max - the maximum allowed value
      Returns:
      min if val < min, max if val > max, otherwise val
      Throws:
      IllegalArgumentException - if min > max
    • clamp

      @Deprecated(since="4.1.0", forRemoval=true) public static int clamp(int val, int min, int max)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use Math.clamp(long, int, int), which this now delegates to
      Clamps an int value to the specified range.
      Parameters:
      val - the value to clamp
      min - the minimum allowed value
      max - the maximum allowed value
      Returns:
      min if val < min, max if val > max, otherwise val
      Throws:
      IllegalArgumentException - if min > max
    • getClassParents

      @Deprecated(since="4.1.0") public static <T> void getClassParents(Class<?> clazz, Class<T> type, Set<Class<? extends T>> result)
      Deprecated.
      internal helper with a single caller; do not use from addons
      Recursively collects all superclasses and interfaces of clazz that are assignable to type, excluding type itself and Object.
      Type Parameters:
      T - the base type to filter against
      Parameters:
      clazz - the class whose hierarchy to walk
      type - the target type — only classes assignable to this are collected
      result - the set to populate with matching parent classes
    • getClassAnnotation

      @Deprecated(since="4.1.0") public static <T extends Annotation> T getClassAnnotation(Class<?> clazz, Class<T> annotation)
      Deprecated.
      use AnnotationLookup.find(Class, Class), which this now delegates to
      Searches for an annotation on the given class, walking up the superclass chain and all implemented interfaces recursively. Returns the first match found, or null.
      Type Parameters:
      T - the annotation type
      Parameters:
      clazz - the class to start searching from
      annotation - the annotation class to look for
      Returns:
      the annotation instance if found, or null
    • getAllInterfaces

      @Deprecated(since="4.1.0", forRemoval=true) public static Set<Class<?>> getAllInterfaces(Class<?> type)
      Deprecated, for removal: This API element is subject to removal in a future version.
      internal helper with a single caller; do not use from addons
      Collects all interfaces implemented by the given class and its entire superclass chain, including transitively inherited interfaces. The result preserves insertion order.
      Parameters:
      type - the class to inspect
      Returns:
      a set of all interfaces in the class hierarchy, in discovery order
    • getAllSuperclasses

      @Deprecated(since="4.1.0", forRemoval=true) public static List<Class<?>> getAllSuperclasses(Class<?> cls)
      Deprecated, for removal: This API element is subject to removal in a future version.
      internal helper with a single caller; do not use from addons
      Returns all superclasses of the given class, from the immediate parent up to (and including) Object. Does not include the class itself.
      Parameters:
      cls - the class whose superclass chain to collect
      Returns:
      a list of superclasses ordered from most specific to most general