Skip to content

Commit

Permalink
Remove null enchantments
Browse files Browse the repository at this point in the history
Hopefully fixes SquidDev-CC#269.
  • Loading branch information
SquidDev committed Jun 13, 2020
1 parent a7b5882 commit 07ccc4d
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import org.squiddev.plethora.utils.WorldDummy;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

@Injects
public final class VanillaMeta {
Expand Down Expand Up @@ -134,16 +131,18 @@ public BlockPos getSpawnerPosition() {
Map<Enchantment, Integer> enchants = EnchantmentHelper.getEnchantments(target);
if (enchants.isEmpty()) return Collections.emptyMap();

return Collections.singletonMap("enchantments", Helpers.map(enchants.entrySet(), entry -> {
Enchantment enchantment = entry.getKey();
int level = entry.getValue();
HashMap<String, Object> enchant = new HashMap<>(3);
enchant.put("name", enchantment.getName());
enchant.put("level", level);
enchant.put("fullName", enchantment.getTranslatedName(level));

return enchant;
}));
return Collections.singletonMap("enchantments", enchants.entrySet().stream()
.filter(Objects::nonNull)
.map(entry -> {
Enchantment enchantment = entry.getKey();
int level = entry.getValue();
HashMap<String, Object> enchant = new HashMap<>(3);
enchant.put("name", enchantment.getName());
enchant.put("level", level);
enchant.put("fullName", enchantment.getTranslatedName(level));

return enchant;
}).collect(Helpers.tinyCollect()));
}

@Nonnull
Expand Down

0 comments on commit 07ccc4d

Please sign in to comment.