Package de.Keyle.MyPet.api
Class Util
java.lang.Object
de.Keyle.MyPet.api.Util
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
FieldsModifier and TypeFieldDescriptionstatic final MiniMessageA restricted MiniMessage instance that only resolves safe visual tags. -
Constructor Summary
ConstructorsConstructorDescriptionUtil()Not intended for instantiation -- every member of this class is static. -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleclamp(double val, double min, double max) Deprecated, for removal: This API element is subject to removal in a future version.static floatclamp(float val, float min, float max) Deprecated, for removal: This API element is subject to removal in a future version.useMath.clamp(long, int, int), which this now delegates tostatic intclamp(int val, int min, int max) Deprecated, for removal: This API element is subject to removal in a future version.useMath.clamp(long, int, int), which this now delegates tostatic Stringdecimal2roman(int src) Converts a positive integer to its Roman numeral representation.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 addonsgetAllSuperclasses(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 addonsstatic <T extends Annotation>
TgetClassAnnotation(Class<?> clazz, Class<T> annotation) Deprecated.useAnnotationLookup.find(Class, Class), which this now delegates tostatic <T> voidgetClassParents(Class<?> clazz, Class<T> type, Set<Class<? extends T>> result) Deprecated.internal helper with a single caller; do not use from addonsstatic RandomReturns a random number generator for the calling thread.static booleanChecks whether the given string can be parsed as anint.static StringreadUrlContent(String address) 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 StringreadUrlContent(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.
-
Field Details
-
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
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 (setSeedis unsupported).- Returns:
- the calling thread's random number generator
-
isInt
Checks whether the given string can be parsed as anint.- Parameters:
number- the string to test- Returns:
trueif the string is a valid integer,falseotherwise
-
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. UseHttpClientdirectly.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. UseHttpClientdirectly.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 fetchtimeout- 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
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
srcis 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.useMath.clamp(long, int, int), which this now delegates toClamps adoublevalue to the specified range.- Parameters:
val- the value to clampmin- the minimum allowed valuemax- the maximum allowed value- Returns:
minifval < min,maxifval > max, otherwiseval- Throws:
IllegalArgumentException- ifmin > 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.useMath.clamp(long, int, int), which this now delegates toClamps afloatvalue to the specified range.- Parameters:
val- the value to clampmin- the minimum allowed valuemax- the maximum allowed value- Returns:
minifval < min,maxifval > max, otherwiseval- Throws:
IllegalArgumentException- ifmin > max
-
clamp
Deprecated, for removal: This API element is subject to removal in a future version.useMath.clamp(long, int, int), which this now delegates toClamps anintvalue to the specified range.- Parameters:
val- the value to clampmin- the minimum allowed valuemax- the maximum allowed value- Returns:
minifval < min,maxifval > max, otherwiseval- Throws:
IllegalArgumentException- ifmin > 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 addonsRecursively collects all superclasses and interfaces ofclazzthat are assignable totype, excludingtypeitself andObject.- Type Parameters:
T- the base type to filter against- Parameters:
clazz- the class whose hierarchy to walktype- the target type — only classes assignable to this are collectedresult- 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.useAnnotationLookup.find(Class, Class), which this now delegates toSearches for an annotation on the given class, walking up the superclass chain and all implemented interfaces recursively. Returns the first match found, ornull.- Type Parameters:
T- the annotation type- Parameters:
clazz- the class to start searching fromannotation- 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 addonsCollects 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 addonsReturns 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
-
Math.clamp(long, int, int), which this now delegates to