diff --git a/.gitignore b/.gitignore index af092a2..2d5b113 100644 --- a/.gitignore +++ b/.gitignore @@ -176,6 +176,8 @@ Desktop.ini .windsurfrules context.json run.sh +run_*.sh +no-log4j2.xml # Compiled class file *.class diff --git a/pom.xml b/pom.xml index 3da9b34..fb8a0bf 100755 --- a/pom.xml +++ b/pom.xml @@ -126,10 +126,10 @@ codemc-repo https://repo.codemc.org/repository/maven-public/ - + jitpack.io https://jitpack.io - + @@ -157,8 +157,8 @@ org.bstats - bstats-bukkit-lite - 1.8 + bstats-bukkit + 3.1.0 compile @@ -223,5 +223,11 @@ 5.10.0 test + + com.github.seeseemelk + MockBukkit-v1.21 + 3.133.2 + test + \ No newline at end of file diff --git a/src/main/java/net/coreprotect/api/BlockAPI.java b/src/main/java/net/coreprotect/api/BlockAPI.java index 5b9d547..f950000 100644 --- a/src/main/java/net/coreprotect/api/BlockAPI.java +++ b/src/main/java/net/coreprotect/api/BlockAPI.java @@ -11,10 +11,9 @@ import org.bukkit.block.Block; import net.coreprotect.config.ConfigHandler; import net.coreprotect.database.Database; import net.coreprotect.database.statement.UserStatement; -import net.coreprotect.utility.Util; -import net.coreprotect.utility.WorldUtils; import net.coreprotect.utility.BlockUtils; import net.coreprotect.utility.StringUtils; +import net.coreprotect.utility.WorldUtils; public class BlockAPI { diff --git a/src/main/java/net/coreprotect/services/PluginInitializationService.java b/src/main/java/net/coreprotect/services/PluginInitializationService.java index f79c7f7..1d39a9d 100644 --- a/src/main/java/net/coreprotect/services/PluginInitializationService.java +++ b/src/main/java/net/coreprotect/services/PluginInitializationService.java @@ -2,7 +2,7 @@ package net.coreprotect.services; import java.io.File; -import org.bstats.bukkit.MetricsLite; +import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; @@ -163,7 +163,7 @@ public class PluginInitializationService { */ private static void enableMetrics(JavaPlugin plugin) { try { - new MetricsLite(plugin, 2876); + new Metrics(plugin, 2876); } catch (Exception e) { // Failed to connect to bStats server or something else went wrong diff --git a/src/main/java/net/coreprotect/utility/SystemUtils.java b/src/main/java/net/coreprotect/utility/SystemUtils.java index 2290ab6..7cddc76 100644 --- a/src/main/java/net/coreprotect/utility/SystemUtils.java +++ b/src/main/java/net/coreprotect/utility/SystemUtils.java @@ -8,11 +8,32 @@ import oshi.hardware.CentralProcessor; public class SystemUtils { + private static boolean testMode = Boolean.getBoolean("net.coreprotect.test"); + private static String processorInfo = null; + private SystemUtils() { throw new IllegalStateException("Utility class"); } + /** + * Set test mode to skip actual hardware operations + * + * @param enabled + * Whether to enable test mode + */ + public static void setTestMode(boolean enabled) { + testMode = enabled; + if (enabled) { + processorInfo = "Test Processor"; + } + } + public static CentralProcessor getProcessorInfo() { + // In test mode, don't actually try to initialize hardware components + if (testMode || isLog4jDisabled()) { + return null; + } + CentralProcessor result = null; try { Class.forName("com.sun.jna.Platform"); @@ -32,4 +53,32 @@ public class SystemUtils { return result; } -} \ No newline at end of file + + /** + * Get processor information string (for testing) + * + * @return The processor information string + */ + public static String getProcessorInfoString() { + if (processorInfo != null) { + return processorInfo; + } + + CentralProcessor processor = getProcessorInfo(); + if (processor != null) { + processorInfo = processor.getProcessorIdentifier().getName(); + return processorInfo; + } + + return "Unknown"; + } + + /** + * Check if Log4j is disabled via system properties + * + * @return true if Log4j is disabled + */ + private static boolean isLog4jDisabled() { + return Boolean.getBoolean("log4j2.disable") || System.getProperty("log4j.configurationFile", "").contains("no-log4j2.xml"); + } +}