6
6
import java .util .logging .Logger ;
7
7
8
8
import org .bstats .bukkit .Metrics ;
9
+ import org .bstats .charts .DrilldownPie ;
10
+ import org .bstats .charts .SimplePie ;
9
11
import org .bukkit .Bukkit ;
10
12
import org .bukkit .plugin .Plugin ;
11
13
import org .bukkit .plugin .java .JavaPlugin ;
12
14
15
+ import de .tr7zw .changeme .nbtapi .utils .nmsmappings .ClassWrapper ;
16
+ import de .tr7zw .changeme .nbtapi .utils .nmsmappings .ReflectionMethod ;
17
+
13
18
/**
14
19
* This class acts as the "Brain" of the NBTApi. It contains the main logger for
15
20
* other classes,registers bStats and checks rather Maven shading was done
@@ -30,6 +35,8 @@ public enum MinecraftVersion {
30
35
private static MinecraftVersion version ;
31
36
private static Boolean hasGsonSupport ;
32
37
private static Boolean isForgePresent ;
38
+ private static Boolean isNeoForgePresent ;
39
+ private static Boolean isFabricPresent ;
33
40
private static Boolean isFoliaPresent ;
34
41
private static boolean bStatsDisabled = false ;
35
42
private static boolean disablePackageWarning = false ;
@@ -163,13 +170,67 @@ public static String getNBTAPIVersion() {
163
170
}
164
171
165
172
private static void init () {
173
+ // Maven's Relocate is clever and changes strings, too. So we have to use this
174
+ // little "trick" ... :D (from bStats)
175
+ final String defaultPackage = new String (new byte [] { 'd' , 'e' , '.' , 't' , 'r' , '7' , 'z' , 'w' , '.' , 'c' , 'h' ,
176
+ 'a' , 'n' , 'g' , 'e' , 'm' , 'e' , '.' , 'n' , 'b' , 't' , 'a' , 'p' , 'i' , '.' , 'u' , 't' , 'i' , 'l' , 's' });
177
+ final String reservedPackage = new String (new byte [] { 'd' , 'e' , '.' , 't' , 'r' , '7' , 'z' , 'w' , '.' , 'n' , 'b' ,
178
+ 't' , 'a' , 'p' , 'i' , '.' , 'u' , 't' , 'i' , 'l' , 's' });
166
179
try {
167
180
if (hasGsonSupport () && !bStatsDisabled ) {
168
181
Plugin plugin = Bukkit .getPluginManager ().getPlugin (VersionChecker .getPlugin ());
169
182
if (plugin != null && plugin instanceof JavaPlugin ) {
170
183
getLogger ()
171
184
.info ("[NBTAPI] Using the plugin '" + plugin .getName () + "' to create a bStats instance!" );
172
- new Metrics ((JavaPlugin ) plugin , 1058 );
185
+ Metrics metrics = new Metrics ((JavaPlugin ) plugin , 1058 );
186
+ metrics .addCustomChart (new SimplePie ("nbtapi_version" , () -> {
187
+ return VERSION ;
188
+ }));
189
+ metrics .addCustomChart (new DrilldownPie ("nms_version" , () -> {
190
+ Map <String , Map <String , Integer >> map = new HashMap <>();
191
+ Map <String , Integer > entry = new HashMap <>();
192
+ entry .put (Bukkit .getName (), 1 );
193
+ map .put (getVersion ().name (), entry );
194
+ return map ;
195
+ }));
196
+ metrics .addCustomChart (new SimplePie ("shaded" , () -> {
197
+ return Boolean .toString (!"NBTAPI" .equals (VersionChecker .getPlugin ()));
198
+ }));
199
+ metrics .addCustomChart (new SimplePie ("server_software" , () -> {
200
+ return Bukkit .getName ();
201
+ }));
202
+ metrics .addCustomChart (new SimplePie ("parent_plugin" , () -> {
203
+ return VersionChecker .getPluginforBStats ();
204
+ }));
205
+ metrics .addCustomChart (new SimplePie ("special_environment" , () -> {
206
+ if (isFoliaPresent ()) {
207
+ return "Folia" ;
208
+ } else if (isForgePresent ()) {
209
+ return "Forge" ;
210
+ } else if (isFabricPresent ()) {
211
+ return "Fabric" ;
212
+ } else if (isNeoForgePresent ()) {
213
+ return "NeoForge" ;
214
+ } else {
215
+ return "None" ;
216
+ }
217
+ }));
218
+ metrics .addCustomChart (new SimplePie ("bindings_check" , () -> {
219
+
220
+ boolean failedBinding = false ;
221
+ for (ClassWrapper c : ClassWrapper .values ()) {
222
+ if (c .isEnabled () && c .getClazz () == null ) {
223
+ failedBinding = true ;
224
+ }
225
+ }
226
+ for (ReflectionMethod method : ReflectionMethod .values ()) {
227
+ if (method .isCompatible () && !method .isLoaded ()) {
228
+ failedBinding = true ;
229
+ }
230
+ }
231
+
232
+ return failedBinding ? "Failed" : "Pass" ;
233
+ }));
173
234
} else if (plugin == null ) {
174
235
getLogger ().info ("[NBTAPI] Unable to create a bStats instance!!" );
175
236
}
@@ -186,12 +247,6 @@ private static void init() {
186
247
logger .log (Level .WARNING , "[NBTAPI] Error while checking for updates! Error: " + ex .getMessage ());
187
248
}
188
249
}).start ();
189
- // Maven's Relocate is clever and changes strings, too. So we have to use this
190
- // little "trick" ... :D (from bStats)
191
- final String defaultPackage = new String (new byte [] { 'd' , 'e' , '.' , 't' , 'r' , '7' , 'z' , 'w' , '.' , 'c' , 'h' ,
192
- 'a' , 'n' , 'g' , 'e' , 'm' , 'e' , '.' , 'n' , 'b' , 't' , 'a' , 'p' , 'i' , '.' , 'u' , 't' , 'i' , 'l' , 's' });
193
- final String reservedPackage = new String (new byte [] { 'd' , 'e' , '.' , 't' , 'r' , '7' , 'z' , 'w' , '.' , 'n' , 'b' ,
194
- 't' , 'a' , 'p' , 'i' , '.' , 'u' , 't' , 'i' , 'l' , 's' });
195
250
if (!disablePackageWarning && MinecraftVersion .class .getPackage ().getName ().equals (defaultPackage )) {
196
251
logger .warning (
197
252
"#########################################- NBTAPI -#########################################" );
@@ -251,6 +306,22 @@ public static boolean hasGsonSupport() {
251
306
return hasGsonSupport ;
252
307
}
253
308
309
+ /**
310
+ * @return True, if Fabric is present
311
+ */
312
+ public static boolean isFabricPresent () {
313
+ if (isFabricPresent != null ) {
314
+ return isFabricPresent ;
315
+ }
316
+ try {
317
+ logger .info ("[NBTAPI] Found Fabric: " + Class .forName ("net.fabricmc.api.ModInitializer" ));
318
+ isFabricPresent = true ;
319
+ } catch (Exception ex ) {
320
+ isFabricPresent = false ;
321
+ }
322
+ return isFabricPresent ;
323
+ }
324
+
254
325
/**
255
326
* @return True, if Forge is present
256
327
*/
@@ -268,6 +339,22 @@ public static boolean isForgePresent() {
268
339
}
269
340
return isForgePresent ;
270
341
}
342
+
343
+ /**
344
+ * @return True, if NeoForge is present
345
+ */
346
+ public static boolean isNeoForgePresent () {
347
+ if (isNeoForgePresent != null ) {
348
+ return isNeoForgePresent ;
349
+ }
350
+ try {
351
+ logger .info ("[NBTAPI] Found NeoForge: " + Class .forName ("net.neoforged.neoforge.common.NeoForge" ));
352
+ isNeoForgePresent = true ;
353
+ } catch (Exception ex ) {
354
+ isNeoForgePresent = false ;
355
+ }
356
+ return isNeoForgePresent ;
357
+ }
271
358
272
359
/**
273
360
* @return True, if Folia is present
0 commit comments