added null value check for material
This commit is contained in:
@@ -8,15 +8,14 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Statistics extends Appliance {
|
||||
record StatisticsResponse(List<PlayerStatistics> playerStatistics) {
|
||||
record PlayerStatistics(String player, Map<MaterialStatistic, Integer> values) {
|
||||
record PlayerStatistics(String player, List<MaterialStatistic> statistics) {
|
||||
}
|
||||
}
|
||||
|
||||
record MaterialStatistic(String name, String material) {
|
||||
record MaterialStatistic(String name, String material, int value) {
|
||||
}
|
||||
|
||||
record StatisticsRequest(List<MaterialStatistic> categories) {
|
||||
@@ -34,14 +33,14 @@ public class Statistics extends Appliance {
|
||||
.map(player -> new StatisticsResponse.PlayerStatistics(
|
||||
player.getUniqueId().toString(),
|
||||
statistics.categories().stream()
|
||||
.map(s -> new AbstractMap.SimpleEntry<>(s, s.material().isBlank()
|
||||
? player.getStatistic(Statistic.valueOf(s.name))
|
||||
: player.getStatistic(Statistic.valueOf(s.name), Material.valueOf(s.material()))
|
||||
))
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
Map.Entry::getValue
|
||||
))
|
||||
.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