From d2bffb2103eafea281745a6b462e3755e6a61874 Mon Sep 17 00:00:00 2001 From: Intelli Date: Thu, 15 Aug 2024 19:04:31 -0600 Subject: [PATCH] Fixed errors pertaining the CPU lib on startup on some systems (fixes #591) --- pom.xml | 6 +++--- .../java/net/coreprotect/command/StatusCommand.java | 10 +++++----- .../java/net/coreprotect/config/ConfigHandler.java | 4 ++-- src/main/java/net/coreprotect/utility/Util.java | 13 +++++++------ 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 7dfab63..66ffd9e 100755 --- a/pom.xml +++ b/pom.xml @@ -155,9 +155,9 @@ 5.0.1 - org.jhardware - jHardware - 0.8.6 + com.github.oshi + oshi-core + 6.6.2 org.apache.logging.log4j diff --git a/src/main/java/net/coreprotect/command/StatusCommand.java b/src/main/java/net/coreprotect/command/StatusCommand.java index b6d1e49..c60031a 100755 --- a/src/main/java/net/coreprotect/command/StatusCommand.java +++ b/src/main/java/net/coreprotect/command/StatusCommand.java @@ -104,18 +104,18 @@ public class StatusCommand { try { String cpuInfo = ""; if (ConfigHandler.processorInfo != null) { - String modelName = ConfigHandler.processorInfo.getModelName(); + String modelName = ConfigHandler.processorInfo.getProcessorIdentifier().getName(); if (modelName.contains(" CPU")) { - String[] split = ConfigHandler.processorInfo.getModelName().split(" CPU")[0].split(" "); + String[] split = modelName.split(" CPU")[0].split(" "); modelName = split[split.length - 1]; } else if (modelName.contains(" Processor")) { - String[] split = ConfigHandler.processorInfo.getModelName().split(" Processor")[0].split(" "); + String[] split = modelName.split(" Processor")[0].split(" "); modelName = split[split.length - 1]; } - String cpuSpeed = ConfigHandler.processorInfo.getMhz(); - cpuSpeed = String.format("%.2f", Double.valueOf(cpuSpeed) / 1000.0); + String cpuSpeed = String.valueOf(ConfigHandler.processorInfo.getMaxFreq()); + cpuSpeed = String.format("%.2f", Long.valueOf(cpuSpeed) / 1000000000.0); cpuInfo = modelName + " " + Runtime.getRuntime().availableProcessors() + " x " + cpuSpeed + "GHz."; } else { diff --git a/src/main/java/net/coreprotect/config/ConfigHandler.java b/src/main/java/net/coreprotect/config/ConfigHandler.java index 06be249..09dcf71 100644 --- a/src/main/java/net/coreprotect/config/ConfigHandler.java +++ b/src/main/java/net/coreprotect/config/ConfigHandler.java @@ -19,7 +19,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; -import org.jutils.jhardware.model.ProcessorInfo; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; @@ -37,6 +36,7 @@ import net.coreprotect.spigot.SpigotAdapter; import net.coreprotect.utility.Chat; import net.coreprotect.utility.Color; import net.coreprotect.utility.Util; +import oshi.hardware.CentralProcessor; public class ConfigHandler extends Queue { public static int SERVER_VERSION = 0; @@ -56,7 +56,7 @@ public class ConfigHandler extends Queue { public static int maximumPoolSize = 10; public static HikariDataSource hikariDataSource = null; - public static final ProcessorInfo processorInfo = Util.getProcessorInfo(); + public static final CentralProcessor processorInfo = Util.getProcessorInfo(); public static final boolean isSpigot = Util.isSpigot(); public static final boolean isPaper = Util.isPaper(); public static final boolean isFolia = Util.isFolia(); diff --git a/src/main/java/net/coreprotect/utility/Util.java b/src/main/java/net/coreprotect/utility/Util.java index d14877e..114a8f8 100755 --- a/src/main/java/net/coreprotect/utility/Util.java +++ b/src/main/java/net/coreprotect/utility/Util.java @@ -53,8 +53,6 @@ import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.Plugin; import org.bukkit.util.io.BukkitObjectOutputStream; -import org.jutils.jhardware.HardwareInfo; -import org.jutils.jhardware.model.ProcessorInfo; import net.coreprotect.CoreProtect; import net.coreprotect.bukkit.BukkitAdapter; @@ -68,6 +66,8 @@ import net.coreprotect.thread.CacheHandler; import net.coreprotect.thread.Scheduler; import net.coreprotect.utility.serialize.ItemMetaHandler; import net.coreprotect.worldedit.CoreProtectEditSessionEvent; +import oshi.SystemInfo; +import oshi.hardware.CentralProcessor; public class Util extends Queue { @@ -116,11 +116,12 @@ public class Util extends Queue { return name; } - public static ProcessorInfo getProcessorInfo() { - ProcessorInfo result = null; + public static CentralProcessor getProcessorInfo() { + CentralProcessor result = null; try { - Configurator.setLevel("com.profesorfalken.jsensors.manager.unix.UnixSensorsManager", Level.OFF); - result = HardwareInfo.getProcessorInfo(); + Configurator.setLevel("oshi.hardware.common.AbstractCentralProcessor", Level.OFF); + SystemInfo systemInfo = new SystemInfo(); + result = systemInfo.getHardware().getProcessor(); } catch (Exception e) { // unable to read processor information