Skip to content

Commit baf6109

Browse files
committed
Update Metrics
1 parent 778be07 commit baf6109

File tree

5 files changed

+65
-9
lines changed

5 files changed

+65
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ Desktop.ini
176176
.windsurfrules
177177
context.json
178178
run.sh
179+
run_*.sh
180+
no-log4j2.xml
179181

180182
# Compiled class file
181183
*.class

pom.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@
126126
<id>codemc-repo</id>
127127
<url>https://repo.codemc.org/repository/maven-public/</url>
128128
</repository>
129-
<repository>
129+
<repository>
130130
<id>jitpack.io</id>
131131
<url>https://jitpack.io</url>
132-
</repository>
132+
</repository>
133133
</repositories>
134134
<dependencyManagement>
135135
<dependencies>
@@ -157,8 +157,8 @@
157157
</dependency>
158158
<dependency>
159159
<groupId>org.bstats</groupId>
160-
<artifactId>bstats-bukkit-lite</artifactId>
161-
<version>1.8</version>
160+
<artifactId>bstats-bukkit</artifactId>
161+
<version>3.1.0</version>
162162
<scope>compile</scope>
163163
</dependency>
164164
<dependency>
@@ -223,5 +223,11 @@
223223
<version>5.10.0</version>
224224
<scope>test</scope>
225225
</dependency>
226+
<dependency>
227+
<groupId>com.github.seeseemelk</groupId>
228+
<artifactId>MockBukkit-v1.21</artifactId>
229+
<version>3.133.2</version>
230+
<scope>test</scope>
231+
</dependency>
226232
</dependencies>
227233
</project>

src/main/java/net/coreprotect/api/BlockAPI.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
import net.coreprotect.config.ConfigHandler;
1212
import net.coreprotect.database.Database;
1313
import net.coreprotect.database.statement.UserStatement;
14-
import net.coreprotect.utility.Util;
15-
import net.coreprotect.utility.WorldUtils;
1614
import net.coreprotect.utility.BlockUtils;
1715
import net.coreprotect.utility.StringUtils;
16+
import net.coreprotect.utility.WorldUtils;
1817

1918
public class BlockAPI {
2019

src/main/java/net/coreprotect/services/PluginInitializationService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.io.File;
44

5-
import org.bstats.bukkit.MetricsLite;
5+
import org.bstats.bukkit.Metrics;
66
import org.bukkit.Bukkit;
77
import org.bukkit.plugin.PluginDescriptionFile;
88
import org.bukkit.plugin.java.JavaPlugin;
@@ -163,7 +163,7 @@ private static void startBackgroundServices(CoreProtect plugin) {
163163
*/
164164
private static void enableMetrics(JavaPlugin plugin) {
165165
try {
166-
new MetricsLite(plugin, 2876);
166+
new Metrics(plugin, 2876);
167167
}
168168
catch (Exception e) {
169169
// Failed to connect to bStats server or something else went wrong

src/main/java/net/coreprotect/utility/SystemUtils.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,32 @@
88

99
public class SystemUtils {
1010

11+
private static boolean testMode = Boolean.getBoolean("net.coreprotect.test");
12+
private static String processorInfo = null;
13+
1114
private SystemUtils() {
1215
throw new IllegalStateException("Utility class");
1316
}
1417

18+
/**
19+
* Set test mode to skip actual hardware operations
20+
*
21+
* @param enabled
22+
* Whether to enable test mode
23+
*/
24+
public static void setTestMode(boolean enabled) {
25+
testMode = enabled;
26+
if (enabled) {
27+
processorInfo = "Test Processor";
28+
}
29+
}
30+
1531
public static CentralProcessor getProcessorInfo() {
32+
// In test mode, don't actually try to initialize hardware components
33+
if (testMode || isLog4jDisabled()) {
34+
return null;
35+
}
36+
1637
CentralProcessor result = null;
1738
try {
1839
Class.forName("com.sun.jna.Platform");
@@ -32,4 +53,32 @@ else if (System.getProperty("os.name").toLowerCase().contains("android") || Syst
3253

3354
return result;
3455
}
35-
}
56+
57+
/**
58+
* Get processor information string (for testing)
59+
*
60+
* @return The processor information string
61+
*/
62+
public static String getProcessorInfoString() {
63+
if (processorInfo != null) {
64+
return processorInfo;
65+
}
66+
67+
CentralProcessor processor = getProcessorInfo();
68+
if (processor != null) {
69+
processorInfo = processor.getProcessorIdentifier().getName();
70+
return processorInfo;
71+
}
72+
73+
return "Unknown";
74+
}
75+
76+
/**
77+
* Check if Log4j is disabled via system properties
78+
*
79+
* @return true if Log4j is disabled
80+
*/
81+
private static boolean isLog4jDisabled() {
82+
return Boolean.getBoolean("log4j2.disable") || System.getProperty("log4j.configurationFile", "").contains("no-log4j2.xml");
83+
}
84+
}

0 commit comments

Comments
 (0)