Skip to content

Commit baaee1f

Browse files
author
Jakub Sapalski
committed
Add bStats metrics
1 parent cd1f9d0 commit baaee1f

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/.project
55

66
*.html
7+
/dependency-reduced-pom.xml

pom.xml

+36
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,33 @@
4141
<artifactId>maven-jar-plugin</artifactId>
4242
<version>2.4</version>
4343
</plugin>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-shade-plugin</artifactId>
47+
<version>2.4.3</version>
48+
<executions>
49+
<execution>
50+
<phase>package</phase>
51+
<goals>
52+
<goal>shade</goal>
53+
</goals>
54+
<configuration>
55+
<artifactSet>
56+
<includes>
57+
<include>org.bstats:*</include>
58+
</includes>
59+
</artifactSet>
60+
<relocations>
61+
<relocation>
62+
<pattern>org.bstats</pattern>
63+
<shadedPattern>pl.betoncraft.flier.bstats</shadedPattern>
64+
</relocation>
65+
</relocations>
66+
<minimizeJar>${minimize}</minimizeJar>
67+
</configuration>
68+
</execution>
69+
</executions>
70+
</plugin>
4471
</plugins>
4572
</build>
4673
<repositories>
@@ -52,6 +79,10 @@
5279
<id>betonquest-repo</id>
5380
<url>http://betonquest.betoncraft.pl/mvn</url>
5481
</repository>
82+
<repository>
83+
<id>bstats-repo</id>
84+
<url>http://repo.bstats.org/content/repositories/releases/</url>
85+
</repository>
5586
</repositories>
5687
<dependencies>
5788
<dependency>
@@ -75,5 +106,10 @@
75106
<artifactId>BetonQuest</artifactId>
76107
<version>1.9</version>
77108
</dependency>
109+
<dependency>
110+
<groupId>org.bstats</groupId>
111+
<artifactId>bstats-bukkit</artifactId>
112+
<version>1.1</version>
113+
</dependency>
78114
</dependencies>
79115
</project>

src/main/java/pl/betoncraft/flier/FlierPlugin.java

+34
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import java.util.Collections;
1010
import java.util.HashMap;
1111
import java.util.Map;
12+
import java.util.Set;
1213
import java.util.UUID;
1314

15+
import org.bstats.Metrics;
1416
import org.bukkit.Bukkit;
1517
import org.bukkit.configuration.ConfigurationSection;
1618
import org.bukkit.entity.Entity;
@@ -167,6 +169,38 @@ public void onChunkUnload(ChunkUnloadEvent event) {
167169
// schedule loading after all plugins are enabled
168170
Bukkit.getScheduler().runTask(this, () -> reload());
169171

172+
// start metrics
173+
Metrics metrics = new Metrics(this);
174+
metrics.addCustomChart(new Metrics.SingleLineChart("ingame_players") {
175+
@Override
176+
public int getValue() {
177+
return players.size();
178+
}
179+
});
180+
metrics.addCustomChart(new Metrics.AdvancedPie("game_types") {
181+
@Override
182+
public HashMap<String, Integer> getValues(HashMap<String, Integer> map) {
183+
for (Lobby lobby : lobbies.values()) {
184+
for (Set<Game> set : lobby.getGames().values()) {
185+
for (Game game : set) {
186+
String name;
187+
if (game instanceof DeathMatchGame) {
188+
name = "DeathMatch";
189+
} else if (game instanceof TeamDeathMatch) {
190+
name = "Team DeathMatch";
191+
} else {
192+
name = "Custom";
193+
}
194+
int amount = map.computeIfAbsent(name, key -> 0);
195+
amount++;
196+
map.put(name, amount);
197+
}
198+
}
199+
}
200+
return map;
201+
}
202+
});
203+
170204
getLogger().info("Flier enabled!");
171205
}
172206

0 commit comments

Comments
 (0)