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