Fixed an error in stats map caused by modded block/item being null (#171)

feat/data-edit-commands
Galen Huang 1 year ago committed by GitHub
parent 37a671dae9
commit 0fd29bca57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -46,6 +46,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
public abstract class BukkitData implements Data { public abstract class BukkitData implements Data {
@ -588,30 +589,53 @@ public abstract class BukkitData implements Data {
@NotNull @NotNull
public static BukkitData.Statistics from(@NotNull StatisticsMap stats) { public static BukkitData.Statistics from(@NotNull StatisticsMap stats) {
return new BukkitData.Statistics( return new BukkitData.Statistics(
stats.genericStats().entrySet().stream().collect(Collectors.toMap( stats.genericStats().entrySet().stream()
entry -> matchStatistic(entry.getKey()), .flatMap(entry -> {
Map.Entry::getValue Statistic statistic = matchStatistic(entry.getKey());
)), return statistic != null ? Stream.of(new AbstractMap.SimpleEntry<>(statistic, entry.getValue())) : Stream.empty();
stats.blockStats().entrySet().stream().collect(Collectors.toMap( })
entry -> matchStatistic(entry.getKey()), .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)),
entry -> entry.getValue().entrySet().stream().collect(Collectors.toMap( stats.blockStats().entrySet().stream()
blockEntry -> Material.matchMaterial(blockEntry.getKey()), .flatMap(entry -> {
Map.Entry::getValue Statistic statistic = matchStatistic(entry.getKey());
)) return statistic != null ? Stream.of(new AbstractMap.SimpleEntry<>(statistic, entry.getValue())) : Stream.empty();
})
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().entrySet().stream()
.flatMap(blockEntry -> {
Material material = Material.matchMaterial(blockEntry.getKey());
return material != null ? Stream.of(new AbstractMap.SimpleEntry<>(material, blockEntry.getValue())) : Stream.empty();
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
)), )),
stats.itemStats().entrySet().stream().collect(Collectors.toMap( stats.itemStats().entrySet().stream()
entry -> matchStatistic(entry.getKey()), .flatMap(entry -> {
entry -> entry.getValue().entrySet().stream().collect(Collectors.toMap( Statistic statistic = matchStatistic(entry.getKey());
itemEntry -> Material.matchMaterial(itemEntry.getKey()), return statistic != null ? Stream.of(new AbstractMap.SimpleEntry<>(statistic, entry.getValue())) : Stream.empty();
Map.Entry::getValue })
)) .collect(Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().entrySet().stream()
.flatMap(itemEntry -> {
Material material = Material.matchMaterial(itemEntry.getKey());
return material != null ? Stream.of(new AbstractMap.SimpleEntry<>(material, itemEntry.getValue())) : Stream.empty();
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
)), )),
stats.entityStats().entrySet().stream().collect(Collectors.toMap( stats.entityStats().entrySet().stream()
entry -> matchStatistic(entry.getKey()), .flatMap(entry -> {
entry -> entry.getValue().entrySet().stream().collect(Collectors.toMap( Statistic statistic = matchStatistic(entry.getKey());
entityEntry -> matchEntityType(entityEntry.getKey()), return statistic != null ? Stream.of(new AbstractMap.SimpleEntry<>(statistic, entry.getValue())) : Stream.empty();
Map.Entry::getValue })
)) .collect(Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().entrySet().stream()
.flatMap(itemEntry -> {
EntityType entityType = matchEntityType(itemEntry.getKey());
return entityType != null ? Stream.of(new AbstractMap.SimpleEntry<>(entityType, itemEntry.getValue())) : Stream.empty();
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
)) ))
); );
} }

Loading…
Cancel
Save