Skip to content

Commit d88e1d6

Browse files
authored
Merge pull request #18 from Slimefun/charts/integrations
2 parents 3f71af4 + ed22bdf commit d88e1d6

File tree

10 files changed

+114
-40
lines changed

10 files changed

+114
-40
lines changed

pom.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
<scope>provided</scope>
4040
</dependency>
4141

42+
<dependency>
43+
<groupId>com.google.code.findbugs</groupId>
44+
<artifactId>jsr305</artifactId>
45+
<version>3.0.2</version>
46+
<scope>provided</scope>
47+
</dependency>
48+
4249
<dependency>
4350
<groupId>org.bstats</groupId>
4451
<artifactId>bstats-bukkit</artifactId>
@@ -51,7 +58,7 @@
5158
<defaultGoal>clean package</defaultGoal>
5259
<finalName>${project.artifactId}</finalName>
5360
<sourceDirectory>src/main/java</sourceDirectory>
54-
61+
5562
<resources>
5663
<resource>
5764
<targetPath>.</targetPath>
@@ -62,7 +69,7 @@
6269
</includes>
6370
</resource>
6471
</resources>
65-
72+
6673
<plugins>
6774
<plugin>
6875
<groupId>org.apache.maven.plugins</groupId>
@@ -73,7 +80,7 @@
7380
<target>1.8</target>
7481
</configuration>
7582
</plugin>
76-
83+
7784
<plugin>
7885
<groupId>org.apache.maven.plugins</groupId>
7986
<artifactId>maven-shade-plugin</artifactId>
@@ -86,13 +93,13 @@
8693
</relocation>
8794
</relocations>
8895
</configuration>
89-
96+
9097
<executions>
9198
<execution>
9299
<goals>
93100
<goal>shade</goal>
94101
</goals>
95-
102+
96103
<configuration>
97104
<createDependencyReducedPom>false</createDependencyReducedPom>
98105
<transformers>

src/main/java/dev/walshy/sfmetrics/MetricsModule.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.function.Supplier;
44
import java.util.logging.Level;
55

6+
import javax.annotation.ParametersAreNonnullByDefault;
7+
68
import org.bstats.bukkit.Metrics;
79
import org.bstats.bukkit.Metrics.CustomChart;
810

@@ -11,6 +13,7 @@
1113
import dev.walshy.sfmetrics.charts.CommandChart;
1214
import dev.walshy.sfmetrics.charts.CompatibilityModeChart;
1315
import dev.walshy.sfmetrics.charts.ErrorReportsChart;
16+
import dev.walshy.sfmetrics.charts.IntegrationsChart;
1417
import dev.walshy.sfmetrics.charts.MetricsAutoUpdatesChart;
1518
import dev.walshy.sfmetrics.charts.MetricsVersionChart;
1619
import dev.walshy.sfmetrics.charts.NewServersChart;
@@ -59,11 +62,13 @@ public static void start() {
5962
addChart(metrics, MetricsAutoUpdatesChart::new);
6063
addChart(metrics, TickRateChart::new);
6164
addChart(metrics, ErrorReportsChart::new);
65+
addChart(metrics, IntegrationsChart::new);
6266

6367
SlimefunPlugin.instance().getLogger().log(Level.INFO, "Now running MetricsModule build #{0}", VERSION);
6468
SlimefunPlugin.instance().getLogger().log(Level.INFO, "with a total of {0}/{1} chart(s)!", new Object[] { enabledCharts, totalCharts });
6569
}
6670

71+
@ParametersAreNonnullByDefault
6772
private static <T extends CustomChart & SlimefunMetricsChart> void addChart(Metrics metrics, Supplier<T> constructor) {
6873
T chart = null;
6974
totalCharts++;
@@ -81,12 +86,12 @@ private static <T extends CustomChart & SlimefunMetricsChart> void addChart(Metr
8186

8287
metrics.addCustomChart(chart);
8388
enabledCharts++;
84-
}
85-
catch (Exception | LinkageError x) {
89+
} catch (Exception | LinkageError x) {
8690
warn(chart == null ? "Unknown" : chart.getName(), x);
8791
}
8892
}
8993

94+
@ParametersAreNonnullByDefault
9095
private static void warn(String chartName, Throwable x) {
9196
if (!metricsAutoUpdates) {
9297
SlimefunPlugin.instance().getLogger().log(Level.WARNING, "Turn on Auto-Updates for Slimefun-Metrics to avoid this issue!");

src/main/java/dev/walshy/sfmetrics/SlimefunMetricsChart.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.walshy.sfmetrics;
22

3+
import javax.annotation.Nonnull;
4+
35
import org.bstats.bukkit.Metrics.CustomChart;
46

57
import com.google.gson.JsonObject;
@@ -17,6 +19,7 @@ public interface SlimefunMetricsChart {
1719
*
1820
* @return The chart name
1921
*/
22+
@Nonnull
2023
String getName();
2124

2225
/**
@@ -27,6 +30,7 @@ public interface SlimefunMetricsChart {
2730
*
2831
* @return The data of this chart
2932
*/
33+
@Nonnull
3034
JsonObject getDataSample() throws Exception;
3135

3236
}

src/main/java/dev/walshy/sfmetrics/VersionDependentChart.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.walshy.sfmetrics;
22

3+
import javax.annotation.Nonnull;
4+
35
import io.github.thebusybiscuit.slimefun4.api.SlimefunBranch;
46

57
/**
@@ -22,6 +24,6 @@ public interface VersionDependentChart extends SlimefunMetricsChart {
2224
*
2325
* @return Whether this chart is compatible
2426
*/
25-
boolean isCompatible(SlimefunBranch branch, int build);
27+
boolean isCompatible(@Nonnull SlimefunBranch branch, int build);
2628

2729
}

src/main/java/dev/walshy/sfmetrics/charts/AutoUpdaterChart.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.walshy.sfmetrics.charts;
22

3+
import javax.annotation.Nonnull;
4+
35
import org.bstats.bukkit.Metrics.SimplePie;
46
import org.bukkit.Server;
57

@@ -28,7 +30,7 @@ public AutoUpdaterChart() {
2830
}
2931

3032
@Override
31-
public boolean isCompatible(SlimefunBranch branch, int build) {
33+
public boolean isCompatible(@Nonnull SlimefunBranch branch, int build) {
3234
// Auto updates are only meaningful to us for official builds
3335
return branch.isOfficial();
3436
}

src/main/java/dev/walshy/sfmetrics/charts/ErrorReportsChart.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.walshy.sfmetrics.charts;
22

3+
import javax.annotation.Nonnull;
4+
35
import org.bstats.bukkit.Metrics.SingleLineChart;
46

57
import com.google.gson.JsonObject;
@@ -29,14 +31,12 @@ public ErrorReportsChart() {
2931
}
3032

3133
@Override
32-
public boolean isCompatible(SlimefunBranch branch, int build) {
34+
public boolean isCompatible(@Nonnull SlimefunBranch branch, int build) {
3335
if (branch == SlimefunBranch.DEVELOPMENT) {
3436
return build >= 638;
35-
}
36-
else if (branch == SlimefunBranch.STABLE) {
37+
} else if (branch == SlimefunBranch.STABLE) {
3738
return build >= 16;
38-
}
39-
else {
39+
} else {
4040
return false;
4141
}
4242
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package dev.walshy.sfmetrics.charts;
2+
3+
import java.util.HashMap;
4+
import java.util.List;
5+
import java.util.Map;
6+
7+
import javax.annotation.ParametersAreNonnullByDefault;
8+
9+
import org.bstats.bukkit.Metrics.AdvancedPie;
10+
import org.bukkit.plugin.Plugin;
11+
import org.bukkit.plugin.PluginManager;
12+
13+
import com.google.gson.JsonObject;
14+
15+
import dev.walshy.sfmetrics.SlimefunMetricsChart;
16+
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
17+
18+
/**
19+
* This {@link AdvancedPie} shows us which {@link Plugin Plugins} the current
20+
* Slimefun installation has integrated with.
21+
*
22+
* @author TheBusyBiscuit
23+
*
24+
*/
25+
public class IntegrationsChart extends AdvancedPie implements SlimefunMetricsChart {
26+
27+
public IntegrationsChart() {
28+
super("integrations", () -> {
29+
SlimefunPlugin slimefun = SlimefunPlugin.instance();
30+
Map<String, Integer> plugins = new HashMap<>();
31+
32+
// Hard dependencies
33+
findDependencies(plugins, slimefun.getServer().getPluginManager(), slimefun.getDescription().getDepend());
34+
35+
// Soft dependencies
36+
findDependencies(plugins, slimefun.getServer().getPluginManager(), slimefun.getDescription().getSoftDepend());
37+
38+
return plugins;
39+
});
40+
}
41+
42+
@ParametersAreNonnullByDefault
43+
private static void findDependencies(Map<String, Integer> plugins, PluginManager pm, List<String> dependencies) {
44+
for (String plugin : dependencies) {
45+
// No need to list CS-CoreLib here
46+
if (!plugin.equals("CS-CoreLib") && pm.isPluginEnabled(plugin)) {
47+
plugins.put(plugin, 1);
48+
}
49+
}
50+
}
51+
52+
@Override
53+
public String getName() {
54+
return "Integrations";
55+
}
56+
57+
@Override
58+
public JsonObject getDataSample() throws Exception {
59+
return getChartData();
60+
}
61+
62+
}

src/main/java/dev/walshy/sfmetrics/charts/MetricsAutoUpdatesChart.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.walshy.sfmetrics.charts;
22

3+
import javax.annotation.Nonnull;
4+
35
import org.bstats.bukkit.Metrics.SimplePie;
46
import org.bukkit.Server;
57

@@ -27,14 +29,12 @@ public MetricsAutoUpdatesChart() {
2729
}
2830

2931
@Override
30-
public boolean isCompatible(SlimefunBranch branch, int build) {
32+
public boolean isCompatible(@Nonnull SlimefunBranch branch, int build) {
3133
if (branch == SlimefunBranch.DEVELOPMENT) {
3234
return build >= 600;
33-
}
34-
else if (branch == SlimefunBranch.STABLE) {
35+
} else if (branch == SlimefunBranch.STABLE) {
3536
return build >= 15;
36-
}
37-
else {
37+
} else {
3838
return false;
3939
}
4040
}

src/main/java/dev/walshy/sfmetrics/charts/NewServersChart.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.walshy.sfmetrics.charts;
22

3+
import javax.annotation.Nonnull;
4+
35
import org.bstats.bukkit.Metrics.SingleLineChart;
46
import org.bukkit.Server;
57
import org.bukkit.plugin.Plugin;
@@ -33,14 +35,12 @@ public NewServersChart() {
3335
}
3436

3537
@Override
36-
public boolean isCompatible(SlimefunBranch branch, int build) {
38+
public boolean isCompatible(@Nonnull SlimefunBranch branch, int build) {
3739
if (branch == SlimefunBranch.DEVELOPMENT) {
3840
return build >= 600;
39-
}
40-
else if (branch == SlimefunBranch.STABLE) {
41+
} else if (branch == SlimefunBranch.STABLE) {
4142
return build >= 15;
42-
}
43-
else {
43+
} else {
4444
return false;
4545
}
4646
}

src/main/java/dev/walshy/sfmetrics/charts/OnlinePlayersChart.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,21 @@ public OnlinePlayersChart() {
2222

2323
if (players <= 5) {
2424
return "0-5";
25-
}
26-
else if (players <= 15) {
25+
} else if (players <= 15) {
2726
return "6-15";
28-
}
29-
else if (players <= 25) {
27+
} else if (players <= 25) {
3028
return "16-25";
31-
}
32-
else if (players <= 50) {
29+
} else if (players <= 50) {
3330
return "26-50";
34-
}
35-
else if (players <= 75) {
31+
} else if (players <= 75) {
3632
return "51-75";
37-
}
38-
else if (players <= 100) {
33+
} else if (players <= 100) {
3934
return "76-100";
40-
}
41-
else if (players <= 150) {
35+
} else if (players <= 150) {
4236
return "101-150";
43-
}
44-
else if (players <= 200) {
37+
} else if (players <= 200) {
4538
return "151-200";
46-
}
47-
else {
39+
} else {
4840
return "200+";
4941
}
5042
});

0 commit comments

Comments
 (0)