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[]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 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 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 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?
-