21
21
import com .comphenix .protocol .ProtocolLibrary ;
22
22
import com .comphenix .protocol .events .PacketAdapter ;
23
23
import com .comphenix .protocol .events .PacketListener ;
24
+ import com .comphenix .protocol .utility .Util ;
25
+
26
+ import org .bukkit .Bukkit ;
24
27
import org .bukkit .craftbukkit .libs .org .apache .commons .lang3 .tuple .Pair ;
25
28
26
29
import java .io .IOException ;
@@ -36,22 +39,45 @@ public Statistics(ProtocolLib plugin) throws IOException {
36
39
metrics = new Metrics (plugin );
37
40
metrics .logFailedRequests (plugin .getProtocolConfig ().isDebug ());
38
41
39
- // Determine who is using this library
40
- addPluginUserGraph (metrics );
42
+ addCustomGraphs (metrics );
43
+ }
44
+
45
+ private void addCustomGraphs (Metrics metrics ) {
46
+ metrics .addCustomChart (new Metrics .AdvancedPie ("pluginUsers" , this ::getPluginUsers ));
47
+ metrics .addCustomChart (new Metrics .SimplePie ("buildVersion" , this ::getBuildNumber ));
48
+ metrics .addCustomChart (new Metrics .SimplePie ("serverBrand" , this ::getServerBrand ));
49
+ }
50
+
51
+ private String getServerBrand () {
52
+ // spigot doesn't overwrite the serverName, but paper does
53
+ if (!Bukkit .getServer ().getName ().equals ("CraftBukkit" )) {
54
+ return Bukkit .getServer ().getName ();
55
+ } else if (Util .isUsingSpigot ()) {
56
+ return "Spigot" ;
57
+ } else {
58
+ return "CraftBukkit" ;
59
+ }
41
60
}
42
61
43
- private void addPluginUserGraph (Metrics metrics ) {
44
- metrics .addCustomChart (new Metrics .AdvancedPie ("Plugin Users" , this ::getPluginUsers ));
45
- metrics .addCustomChart (new Metrics .SimplePie ("buildVersion" , () -> splitVersion ().getRight ()));
62
+ private String getBuildNumber () {
63
+ String version = ProtocolLibrary .getPlugin ().getDescription ().getVersion ();
64
+ if (version .contains ("-b" )) {
65
+ String [] split = version .split ("-b" );
66
+ return split [1 ];
67
+ } else if (!version .contains ("SNAPSHOT" )) {
68
+ return "Release" ;
69
+ } else {
70
+ return "Unknown" ;
71
+ }
46
72
}
47
73
48
- public static Pair < String , String > splitVersion () {
74
+ public static String getVersion () {
49
75
String version = ProtocolLibrary .getPlugin ().getDescription ().getVersion ();
50
76
if (version .contains ("-b" )) {
51
77
String [] split = version .split ("-b" );
52
- return Pair . of ( split [0 ], split [ 1 ]) ;
78
+ return split [0 ];
53
79
} else {
54
- return Pair . of ( version , "Unknown" ) ;
80
+ return version ;
55
81
}
56
82
}
57
83
0 commit comments