Update Metrics
This commit is contained in:
parent
778be07e51
commit
baf61099b8
5 changed files with 65 additions and 9 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -176,6 +176,8 @@ Desktop.ini
|
||||||
.windsurfrules
|
.windsurfrules
|
||||||
context.json
|
context.json
|
||||||
run.sh
|
run.sh
|
||||||
|
run_*.sh
|
||||||
|
no-log4j2.xml
|
||||||
|
|
||||||
# Compiled class file
|
# Compiled class file
|
||||||
*.class
|
*.class
|
||||||
|
|
|
||||||
10
pom.xml
10
pom.xml
|
|
@ -157,8 +157,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
<artifactId>bstats-bukkit-lite</artifactId>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<version>1.8</version>
|
<version>3.1.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
@ -223,5 +223,11 @@
|
||||||
<version>5.10.0</version>
|
<version>5.10.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.seeseemelk</groupId>
|
||||||
|
<artifactId>MockBukkit-v1.21</artifactId>
|
||||||
|
<version>3.133.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -11,10 +11,9 @@ import org.bukkit.block.Block;
|
||||||
import net.coreprotect.config.ConfigHandler;
|
import net.coreprotect.config.ConfigHandler;
|
||||||
import net.coreprotect.database.Database;
|
import net.coreprotect.database.Database;
|
||||||
import net.coreprotect.database.statement.UserStatement;
|
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.BlockUtils;
|
||||||
import net.coreprotect.utility.StringUtils;
|
import net.coreprotect.utility.StringUtils;
|
||||||
|
import net.coreprotect.utility.WorldUtils;
|
||||||
|
|
||||||
public class BlockAPI {
|
public class BlockAPI {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package net.coreprotect.services;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.bstats.bukkit.MetricsLite;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
@ -163,7 +163,7 @@ public class PluginInitializationService {
|
||||||
*/
|
*/
|
||||||
private static void enableMetrics(JavaPlugin plugin) {
|
private static void enableMetrics(JavaPlugin plugin) {
|
||||||
try {
|
try {
|
||||||
new MetricsLite(plugin, 2876);
|
new Metrics(plugin, 2876);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// Failed to connect to bStats server or something else went wrong
|
// Failed to connect to bStats server or something else went wrong
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,32 @@ import oshi.hardware.CentralProcessor;
|
||||||
|
|
||||||
public class SystemUtils {
|
public class SystemUtils {
|
||||||
|
|
||||||
|
private static boolean testMode = Boolean.getBoolean("net.coreprotect.test");
|
||||||
|
private static String processorInfo = null;
|
||||||
|
|
||||||
private SystemUtils() {
|
private SystemUtils() {
|
||||||
throw new IllegalStateException("Utility class");
|
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() {
|
public static CentralProcessor getProcessorInfo() {
|
||||||
|
// In test mode, don't actually try to initialize hardware components
|
||||||
|
if (testMode || isLog4jDisabled()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
CentralProcessor result = null;
|
CentralProcessor result = null;
|
||||||
try {
|
try {
|
||||||
Class.forName("com.sun.jna.Platform");
|
Class.forName("com.sun.jna.Platform");
|
||||||
|
|
@ -32,4 +53,32 @@ public class SystemUtils {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue