Part 1: - Use only one message entry for "Please register", that may have to be adapted to reflect the proper /register arguments - Remove other message entries from code and from the messages files Breaking change: reg_email_msg is also removed
63 lines
1.6 KiB
Java
63 lines
1.6 KiB
Java
package fr.xephi.authme.util;
|
|
|
|
import fr.xephi.authme.ConsoleLogger;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* Utility class for various operations used in the codebase.
|
|
*/
|
|
public final class Utils {
|
|
|
|
/** Number of milliseconds in a minute. */
|
|
public static final long MILLIS_PER_MINUTE = 60_000L;
|
|
/** Number of milliseconds in an hour. */
|
|
public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
|
|
|
|
// Utility class
|
|
private Utils() {
|
|
}
|
|
|
|
/**
|
|
* Compile Pattern sneaky without throwing Exception.
|
|
*
|
|
* @param pattern pattern string to compile
|
|
*
|
|
* @return the given regex compiled into Pattern object.
|
|
*/
|
|
public static Pattern safePatternCompile(String pattern) {
|
|
try {
|
|
return Pattern.compile(pattern);
|
|
} catch (Exception e) {
|
|
ConsoleLogger.warning("Failed to compile pattern '" + pattern + "' - defaulting to allowing everything");
|
|
return Pattern.compile(".*?");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns whether the class exists in the current class loader.
|
|
*
|
|
* @param className the class name to check
|
|
*
|
|
* @return true if the class is loaded, false otherwise
|
|
*/
|
|
public static boolean isClassLoaded(String className) {
|
|
try {
|
|
Class.forName(className);
|
|
return true;
|
|
} catch (ClassNotFoundException e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Return the available core count of the JVM.
|
|
*
|
|
* @return the core count
|
|
*/
|
|
public static int getCoreCount() {
|
|
return Runtime.getRuntime().availableProcessors();
|
|
}
|
|
|
|
}
|