Skip to content

Commit b8a0590

Browse files
Merge pull request #24 from Slimefun/feature/disabled-items
Add disabled items chart
2 parents 2fae639 + 287c2ef commit b8a0590

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

.github/workflows/java.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- name: Set up JDK 1.8
2626
uses: actions/setup-java@master
2727
with:
28-
java-version: 1.8
28+
java-version: 8
29+
distribution: 'adopt'
2930
- name: Build with Maven
3031
run: mvn package --file pom.xml

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<dependency>
3131
<groupId>com.github.TheBusyBiscuit</groupId>
3232
<artifactId>Slimefun4</artifactId>
33-
<version>RC-18</version>
33+
<version>RC-22</version>
3434
<scope>provided</scope>
3535
</dependency>
3636

@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>org.bstats</groupId>
4646
<artifactId>bstats-bukkit</artifactId>
47-
<version>2.1.0</version>
47+
<version>2.2.1</version>
4848
<scope>compile</scope>
4949
</dependency>
5050
</dependencies>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import javax.annotation.ParametersAreNonnullByDefault;
77

8+
import dev.walshy.sfmetrics.charts.DisabledItemsChart;
89
import org.bstats.bukkit.Metrics;
910
import org.bstats.charts.CustomChart;
1011

@@ -65,6 +66,7 @@ public static void start() {
6566
addChart(metrics, ErrorReportsChart::new);
6667
addChart(metrics, IntegrationsChart::new);
6768
addChart(metrics, CSCoreLibChart::new);
69+
addChart(metrics, DisabledItemsChart::new);
6870

6971
SlimefunPlugin.instance().getLogger().log(Level.INFO, "Now running MetricsModule build #{0}", VERSION);
7072
SlimefunPlugin.instance().getLogger().log(Level.INFO, "with a total of {0}/{1} chart(s)!", new Object[] { enabledCharts, totalCharts });
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package dev.walshy.sfmetrics.charts;
2+
3+
import dev.walshy.sfmetrics.SlimefunMetricsChart;
4+
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
5+
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
6+
import org.bstats.charts.AdvancedPie;
7+
import org.bstats.json.JsonObjectBuilder;
8+
import org.bukkit.Server;
9+
10+
import javax.annotation.Nonnull;
11+
import java.util.Collections;
12+
import java.util.HashMap;
13+
import java.util.Map;
14+
15+
/**
16+
* This {@link AdvancedPie} shows us what {@link SlimefunItem Items} have been disabled on the
17+
* {@link Server}.
18+
* <p>
19+
* This allows us to see what Items are very unpopular and may be considered for rework/removal.
20+
*
21+
* @author Walshy
22+
*/
23+
public class DisabledItemsChart extends AdvancedPie implements SlimefunMetricsChart {
24+
25+
private static Map<String, Integer> disabledItems;
26+
27+
public DisabledItemsChart() {
28+
super("disabled_items", () -> {
29+
if (disabledItems != null) {
30+
return disabledItems;
31+
} else {
32+
fetchItems();
33+
return Collections.emptyMap();
34+
}
35+
});
36+
}
37+
38+
@Nonnull
39+
@Override
40+
public String getName() {
41+
return "Disabled Items";
42+
}
43+
44+
@Nonnull
45+
@Override
46+
public JsonObjectBuilder.JsonObject getDataSample() throws Exception {
47+
return getChartData();
48+
}
49+
50+
private static void fetchItems() {
51+
new Thread(() -> {
52+
disabledItems = new HashMap<>();
53+
for (SlimefunItem item : SlimefunPlugin.getRegistry().getAllSlimefunItems()) {
54+
if (item.getAddon().equals(SlimefunPlugin.instance()) && item.isDisabled()) {
55+
disabledItems.put(item.getId(), 1);
56+
}
57+
}
58+
}, "Slimefun - disabled items fetcher").start();
59+
}
60+
}

0 commit comments

Comments
 (0)