Fixed errors pertaining the CPU lib on startup on some systems (fixes #591)

This commit is contained in:
Intelli 2024-08-15 19:04:31 -06:00
parent 64eedb0aa3
commit d2bffb2103
4 changed files with 17 additions and 16 deletions

View File

@ -155,9 +155,9 @@
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>org.jhardware</groupId>
<artifactId>jHardware</artifactId>
<version>0.8.6</version>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>

View File

@ -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 {

View File

@ -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();

View File

@ -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