Refactored CoreProtectAPI

This commit is contained in:
Intelli 2025-03-10 13:41:26 -06:00
parent d6c4755fba
commit 5c965b8a68
11 changed files with 812 additions and 303 deletions

View file

@ -10,6 +10,7 @@ public class SystemUtils {
private static boolean testMode = Boolean.getBoolean("net.coreprotect.test");
private static String processorInfo = null;
private static boolean log4jInitialized = false;
private SystemUtils() {
throw new IllegalStateException("Utility class");
@ -43,7 +44,17 @@ public class SystemUtils {
else if (System.getProperty("os.name").toLowerCase().contains("android") || System.getProperty("java.runtime.name").toLowerCase().contains("android")) {
return null;
}
Configurator.setLevel("oshi.hardware.common.AbstractCentralProcessor", Level.OFF);
try {
if (!log4jInitialized) {
Configurator.setLevel("oshi.hardware.common.AbstractCentralProcessor", Level.OFF);
log4jInitialized = true;
}
}
catch (Exception e) {
// log4j configuration failure, continue without it
}
SystemInfo systemInfo = new SystemInfo();
result = systemInfo.getHardware().getProcessor();
}
@ -79,6 +90,6 @@ public class SystemUtils {
* @return true if Log4j is disabled
*/
private static boolean isLog4jDisabled() {
return Boolean.getBoolean("log4j2.disable") || System.getProperty("log4j.configurationFile", "").contains("no-log4j2.xml");
return Boolean.getBoolean("log4j2.disable") || Boolean.getBoolean("net.coreprotect.disable.log4j") || System.getProperty("log4j.configurationFile", "").contains("no-log4j2.xml");
}
}

View file

@ -46,7 +46,18 @@ public class VersionUtils {
}
public static String getPluginName() {
String name = CoreProtect.getInstance().getDescription().getName();
CoreProtect instance = CoreProtect.getInstance();
// Return default name if instance is null
if (instance == null) {
return "CoreProtect";
}
// Return default name if description is null
if (instance.getDescription() == null) {
return "CoreProtect";
}
String name = instance.getDescription().getName();
String branch = ConfigHandler.EDITION_BRANCH;
if (branch.startsWith("-edge")) {
@ -107,7 +118,12 @@ public class VersionUtils {
public static String getBranch() {
String branch = "";
try {
InputStreamReader reader = new InputStreamReader(CoreProtect.getInstance().getClass().getResourceAsStream("/plugin.yml"));
CoreProtect instance = CoreProtect.getInstance();
if (instance == null) {
return "";
}
InputStreamReader reader = new InputStreamReader(instance.getClass().getResourceAsStream("/plugin.yml"));
branch = YamlConfiguration.loadConfiguration(reader).getString("branch");
reader.close();
@ -257,4 +273,4 @@ public class VersionUtils {
return result;
}
}
}