Skip to content

Commit 1580543

Browse files
committed
bStatsを追加
1 parent 65fb4cd commit 1580543

File tree

6 files changed

+133
-0
lines changed

6 files changed

+133
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,11 @@ file:
7171
7272
- `schemuploader.upload`: Permission to use the schem file upload feature
7373
- `schemuploader.download`: Permission to use the schem file download feature
74+
75+
## About Statistics Data
76+
77+
BungeePteroPower collects anonymous statistical data using [bStats](https://bstats.org/).
78+
You can find the statistics data [here](https://bstats.org/plugin/bukkit/SchemUploader/21061).
79+
80+
bStats is used to understand the usage of the plugin and help improve it.
81+
To disable the collection of statistical data, please set `enabled` to `false` in `plugins/bStats/config.yml`

README_ja.md

+8
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,11 @@ download:
6969
7070
- `schemuploader.upload`: schemファイルのアップロード機能を使用する権限
7171
- `schemuploader.download`: schemファイルのダウンロード機能を使用する権限
72+
73+
## 統計データについて
74+
75+
BungeePteroPowerは、[bStats](https://bstats.org/)を使用して匿名の統計データを収集しています。
76+
統計データは[こちら](https://bstats.org/plugin/bukkit/SchemUploader/21061)。
77+
78+
bStatsは、プラグインの使用状況を把握するために使用され、プラグインの改善に役立てられます。
79+
統計データの収集を無効にするには、`plugins/bStats/config.yml`の `enabled` を `false` に設定してください。

pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,10 @@
7676
<version>2.8.9</version>
7777
<scope>provided</scope>
7878
</dependency>
79+
<dependency>
80+
<groupId>org.bstats</groupId>
81+
<artifactId>bstats-bukkit</artifactId>
82+
<version>3.0.2</version>
83+
</dependency>
7984
</dependencies>
8085
</project>

src/main/java/com/kamesuta/schemuploader/CommandListener.java

+14
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
9191
// Send an error message if the upload fails
9292
if (!result.success) {
9393
sender.sendMessage(plugin.messages.error("upload_failed", result.error));
94+
95+
// Add record to statistics
96+
plugin.statistics.actionCounter.increment(Statistics.ActionCounter.ActionType.UPLOAD_FAILURE);
97+
9498
return;
9599
}
96100

@@ -101,6 +105,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
101105
.event(new ClickEvent(ClickEvent.Action.OPEN_URL, result.url))
102106
.create()
103107
);
108+
109+
// Add record to statistics
110+
plugin.statistics.actionCounter.increment(Statistics.ActionCounter.ActionType.UPLOAD_SUCCESS);
104111
});
105112

106113
return true;
@@ -174,6 +181,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
174181
} else {
175182
sender.sendMessage(plugin.messages.error("download_failed", result.error));
176183
}
184+
185+
// Add record to statistics
186+
plugin.statistics.actionCounter.increment(Statistics.ActionCounter.ActionType.DOWNLOAD_FAILURE);
187+
177188
return;
178189
}
179190

@@ -184,6 +195,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
184195
.event(new ClickEvent(ClickEvent.Action.OPEN_URL, url))
185196
.create()
186197
);
198+
199+
// Add record to statistics
200+
plugin.statistics.actionCounter.increment(Statistics.ActionCounter.ActionType.DOWNLOAD_SUCCESS);
187201
});
188202

189203
return true;

src/main/java/com/kamesuta/schemuploader/SchemUploader.java

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public final class SchemUploader extends JavaPlugin {
1818
*/
1919
public static SchemUploader plugin;
2020

21+
/**
22+
* Statistics
23+
*/
24+
public Statistics statistics;
25+
2126
/**
2227
* Fallback Translations
2328
*/
@@ -68,6 +73,9 @@ public void onEnable() {
6873

6974
// Register commands
7075
CommandListener.register();
76+
77+
// Statistics
78+
statistics = new Statistics();
7179
}
7280

7381
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.kamesuta.schemuploader;
2+
3+
import org.bstats.bukkit.Metrics;
4+
import org.bstats.charts.SimplePie;
5+
import org.bstats.charts.SingleLineChart;
6+
7+
import java.util.EnumMap;
8+
import java.util.Map;
9+
import java.util.concurrent.atomic.AtomicInteger;
10+
11+
import static com.kamesuta.schemuploader.SchemUploader.plugin;
12+
13+
/**
14+
* Statistics of the plugin
15+
*/
16+
public class Statistics {
17+
public final ActionCounter actionCounter = new ActionCounter();
18+
19+
/**
20+
* Register bStats
21+
*/
22+
public void register() {
23+
// Enable bStats
24+
Metrics metrics = new Metrics(plugin, 21061);
25+
26+
// Config charts
27+
metrics.addCustomChart(new SimplePie("uploadEnabled", () -> PluginConfig.uploadEnabled ? "enabled" : "disabled"));
28+
metrics.addCustomChart(new SimplePie("downloadEnabled", () -> PluginConfig.downloadEnabled ? "enabled" : "disabled"));
29+
metrics.addCustomChart(new SimplePie("downloadUrlRestrictionEnabled", () -> PluginConfig.downloadUrlRestrictionEnabled ? "enabled" : "disabled"));
30+
metrics.addCustomChart(new SimplePie("language", () -> PluginConfig.language));
31+
32+
// The number of power actions performed
33+
for (ActionCounter.ActionType actionType : ActionCounter.ActionType.values()) {
34+
metrics.addCustomChart(new SingleLineChart(actionType.name, () -> actionCounter.collect(actionType)));
35+
}
36+
}
37+
38+
/**
39+
* The counter for each action
40+
*/
41+
public static class ActionCounter {
42+
private final Map<ActionType, AtomicInteger> countMap = new EnumMap<>(ActionType.class);
43+
44+
/**
45+
* Increment the counter
46+
*
47+
* @param actionType type of action to get statistics for
48+
*/
49+
public void increment(ActionType actionType) {
50+
getOrCreate(actionType).incrementAndGet();
51+
}
52+
53+
/**
54+
* Get the collected value and reset the counter
55+
*
56+
* @param actionType type of action to get statistics for
57+
* @return The collected value
58+
*/
59+
public int collect(ActionType actionType) {
60+
return getOrCreate(actionType).getAndSet(0);
61+
}
62+
63+
/**
64+
* Get or create the counter
65+
*
66+
* @param actionType type of action to get statistics for
67+
* @return The counter
68+
*/
69+
private AtomicInteger getOrCreate(ActionType actionType) {
70+
return countMap.computeIfAbsent(actionType, (k) -> new AtomicInteger());
71+
}
72+
73+
/**
74+
* The service to collect statistics
75+
*/
76+
public enum ActionType {
77+
UPLOAD_SUCCESS("upload_success"),
78+
DOWNLOAD_SUCCESS("download_success"),
79+
UPLOAD_FAILURE("upload_failure"),
80+
DOWNLOAD_FAILURE("download_failure"),
81+
;
82+
83+
public final String name;
84+
85+
ActionType(String name) {
86+
this.name = name;
87+
}
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)