Compare commits
2 Commits
91a28b4500
...
develop-st
| Author | SHA1 | Date | |
|---|---|---|---|
| 62c0250049 | |||
| b4ccc3c4c8 |
@@ -0,0 +1,50 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.statistics;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Statistics extends Appliance {
|
||||
record StatisticsResponse(List<PlayerStatistics> playerStatistics) {
|
||||
record PlayerStatistics(String player, List<MaterialStatistic> statistics) {
|
||||
}
|
||||
}
|
||||
|
||||
record MaterialStatistic(String name, String material, int value) {
|
||||
}
|
||||
|
||||
record StatisticsRequest(List<MaterialStatistic> categories) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||
apiBuilder.post(
|
||||
"getStatistics",
|
||||
StatisticsRequest.class,
|
||||
(statistics, request) -> {
|
||||
Main.instance().getLogger().info("API requested statistics");
|
||||
List<StatisticsResponse.PlayerStatistics> statisticsList = Arrays.stream(Bukkit.getOfflinePlayers())
|
||||
.parallel()
|
||||
.map(player -> new StatisticsResponse.PlayerStatistics(
|
||||
player.getUniqueId().toString(),
|
||||
statistics.categories().stream()
|
||||
.map(category -> {
|
||||
String material = (category.material() == null || category.material().isBlank()) ? null : category.material();
|
||||
return new MaterialStatistic(category.name(), material, material == null
|
||||
? player.getStatistic(Statistic.valueOf(category.name()))
|
||||
: player.getStatistic(Statistic.valueOf(category.name()), Material.valueOf(material))
|
||||
);
|
||||
})
|
||||
.toList()
|
||||
))
|
||||
.toList();
|
||||
return new StatisticsResponse(statisticsList);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user