Package emu.grasscutter.utils
Class Utils
java.lang.Object
emu.grasscutter.utils.Utils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intabilityHash(String str) static byte[]base64Decode(String toDecode) Base64 decodes a given string.static Stringbase64Encode(byte[] toEncode) Base64 encodes a given byte array.static byte[]byteBufToArray(io.netty.buffer.ByteBuf buf) static StringbytesToHex(byte[] bytes) static StringbytesToHex(io.netty.buffer.ByteBuf buf) static booleancopyFromResources(String resource, String destination) Copies a file from the archive's resources to the file system.static booleancreateFolder(String path) Creates a folder on the file system.static booleanfileExists(String path) Checks if a file exists on the file system.static intstatic doublestatic StringgetLanguageCode(Locale locale) Gets the language code from a given locale.static intgetNextTimestampOfThisHour(int hour, String timeZone, int param) Gets the timestamp of the next hour.static intgetNextTimestampOfThisHourInNextMonth(int hour, String timeZone, int param) Gets the timestamp of the next hour in a month.static intgetNextTimestampOfThisHourInNextWeek(int hour, String timeZone, int param) Gets the timestamp of the next hour in a week.static booleanintInArray(int key, int[] array) Checks if an int is in an int[]static <T> TjsonDecode(String jsonData, Class<T> classType) Safely JSON decodes a given string.static intlerp(int x, int[][] xyArray) Performs a linear interpolation using a table of fixed points to create an effective piecewise f(x) = y function.static voidlogByteArray(byte[] array) static voidLogs an object to the console.static Stringstatic floatrandomFloatRange(float min, float max) static intrandomRange(int min, int max) static StringreadFromInputStream(InputStream stream) Retrieves a string from an input stream.static <T> TrequireNonNullElseGet(T nonNull, T fallback) Get object with null fallback.static int[]setSubtract(int[] minuend, int[] subtrahend) Return a copy of minuend without any elements found in subtrahend.static voidChecks for required files and folders before startup.switchPropertiesUpperLowerCase(Map<String, Object> objMap, Class<?> cls) Switch properties from upper case to lower case?static StringtoFilePath(String path) Creates a string with the path to a file.static StringtoString(InputStream inputStream)
-
Field Details
-
random
-
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
randomRange
public static int randomRange(int min, int max) -
randomFloatRange
public static float randomFloatRange(float min, float max) -
getDist
-
getCurrentSeconds
public static int getCurrentSeconds() -
lowerCaseFirstChar
-
toString
- Throws:
IOException
-
logByteArray
public static void logByteArray(byte[] array) -
bytesToHex
-
bytesToHex
-
byteBufToArray
public static byte[] byteBufToArray(io.netty.buffer.ByteBuf buf) -
abilityHash
-
toFilePath
Creates a string with the path to a file.- Parameters:
path- The path to the file.- Returns:
- A path using the operating system's file separator.
-
fileExists
Checks if a file exists on the file system.- Parameters:
path- The path to the file.- Returns:
- True if the file exists, false otherwise.
-
createFolder
Creates a folder on the file system.- Parameters:
path- The path to the folder.- Returns:
- True if the folder was created, false otherwise.
-
copyFromResources
Copies a file from the archive's resources to the file system.- Parameters:
resource- The path to the resource.destination- The path to copy the resource to.- Returns:
- True if the file was copied, false otherwise.
-
requireNonNullElseGet
public static <T> T requireNonNullElseGet(T nonNull, T fallback) Get object with null fallback.- Parameters:
nonNull- The object to return if not null.fallback- The object to return if null.- Returns:
- One of the two provided objects.
-
logObject
Logs an object to the console.- Parameters:
object- The object to log.
-
startupCheck
public static void startupCheck()Checks for required files and folders before startup. -
getNextTimestampOfThisHour
Gets the timestamp of the next hour.- Returns:
- The timestamp in UNIX seconds.
-
getNextTimestampOfThisHourInNextWeek
Gets the timestamp of the next hour in a week.- Returns:
- The timestamp in UNIX seconds.
-
getNextTimestampOfThisHourInNextMonth
Gets the timestamp of the next hour in a month.- Returns:
- The timestamp in UNIX seconds.
-
readFromInputStream
Retrieves a string from an input stream.- Parameters:
stream- The input stream.- Returns:
- The string.
-
switchPropertiesUpperLowerCase
public static Map<String,Object> switchPropertiesUpperLowerCase(Map<String, Object> objMap, Class<?> cls) Switch properties from upper case to lower case? -
lerp
public static int lerp(int x, int[][] xyArray) Performs a linear interpolation using a table of fixed points to create an effective piecewise f(x) = y function.- Parameters:
x-xyArray- Array of points in [[x0,y0], ... [xN, yN]] format- Returns:
- f(x) = y
-
intInArray
public static boolean intInArray(int key, int[] array) Checks if an int is in an int[]- Parameters:
key- int to look forarray- int[] to look in- Returns:
- key in array
-
setSubtract
public static int[] setSubtract(int[] minuend, int[] subtrahend) Return a copy of minuend without any elements found in subtrahend.- Parameters:
minuend- The array we want elements fromsubtrahend- The array whose elements we don't want- Returns:
- The array with only the elements we want, in the order that minuend had them
-
getLanguageCode
Gets the language code from a given locale.- Parameters:
locale- A locale.- Returns:
- A string in the format of 'XX-XX'.
-
base64Encode
Base64 encodes a given byte array.- Parameters:
toEncode- An array of bytes.- Returns:
- A base64 encoded string.
-
base64Decode
Base64 decodes a given string.- Parameters:
toDecode- A base64 encoded string.- Returns:
- An array of bytes.
-
jsonDecode
Safely JSON decodes a given string.- Parameters:
jsonData- The JSON-encoded data.- Returns:
- JSON decoded data, or null if an exception occurred.
-