Skip to content

Commit

Permalink
Fixed errors pertaining the CPU lib on startup on some systems (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Aug 16, 2024
1 parent 64eedb0 commit d2bffb2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/coreprotect/command/StatusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ else if (instance.getServer().getPluginManager().getPlugin("WorldEdit") != null)
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 {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/coreprotect/config/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand All @@ -37,6 +36,7 @@
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;
Expand All @@ -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();
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/net/coreprotect/utility/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
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;
Expand All @@ -68,6 +66,8 @@
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 {

Expand Down Expand Up @@ -116,11 +116,12 @@ public static String getPluginName() {
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
Expand Down

0 comments on commit d2bffb2

Please sign in to comment.