From 1d3bafc4e6015e381c03db8ea28f43f7764085db Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 31 Aug 2020 11:50:22 +0200 Subject: [PATCH] use compat material in whitelist to simplify things --- .../com/songoda/epicenchants/menus/InfoMenu.java | 2 +- .../com/songoda/epicenchants/objects/BookItem.java | 3 +-- .../com/songoda/epicenchants/objects/Enchant.java | 11 ++++++----- .../epicenchants/utils/single/ItemGroup.java | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java b/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java index 9f45168..0a25f4a 100644 --- a/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java +++ b/src/main/java/com/songoda/epicenchants/menus/InfoMenu.java @@ -49,7 +49,7 @@ public class InfoMenu extends FastInv { slots.stream().filter(slot -> enchantIterator.hasNext()).forEach(slot -> { Enchant enchant = enchantIterator.next(); - String whitelist = instance.getItemGroup().getGroups(enchant.getItemWhitelist().stream().map(CompatibleMaterial::getMaterial).collect(Collectors.toSet())) + String whitelist = instance.getItemGroup().getGroups(enchant.getItemWhitelist()) .stream() .map(s -> StringUtils.capitalize(s.toLowerCase())) .collect(Collectors.joining(", ")); diff --git a/src/main/java/com/songoda/epicenchants/objects/BookItem.java b/src/main/java/com/songoda/epicenchants/objects/BookItem.java index 2e32ba6..a273ee9 100644 --- a/src/main/java/com/songoda/epicenchants/objects/BookItem.java +++ b/src/main/java/com/songoda/epicenchants/objects/BookItem.java @@ -65,8 +65,7 @@ public class BookItem { } string = string - .replace("{item_group}", "" + instance.getItemGroup().getGroup(enchant.getItemWhitelist() - .stream().map(CompatibleMaterial::getMaterial).collect(Collectors.toSet())).map(ItemGroup.Group::getName).orElse("N/A")) + .replace("{item_group}", "" + instance.getItemGroup().getGroup(enchant.getItemWhitelist()).map(ItemGroup.Group::getName).orElse("N/A")) .replace("{success_rate}", "" + finalSuccessRate) .replace("{destroy_rate}", "" + finalDestroyRate); diff --git a/src/main/java/com/songoda/epicenchants/objects/Enchant.java b/src/main/java/com/songoda/epicenchants/objects/Enchant.java index 4d27647..220f1c9 100644 --- a/src/main/java/com/songoda/epicenchants/objects/Enchant.java +++ b/src/main/java/com/songoda/epicenchants/objects/Enchant.java @@ -1,5 +1,6 @@ package com.songoda.epicenchants.objects; +import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.epicenchants.effect.EffectExecutor; import com.songoda.epicenchants.enums.EventType; import com.songoda.epicenchants.enums.TriggerType; @@ -23,14 +24,14 @@ public class Enchant { private Group group; private int maxLevel; private Set conflict; - private Set itemWhitelist; + private Set itemWhitelist; private Set effectExecutors; private List description; private String format; @Nullable private BookItem bookItem; - Enchant(String author, String identifier, Group group, int maxLevel, Set conflict, Set itemWhitelist, Set effectExecutors, List description, String format, BookItem bookItem) { + Enchant(String author, String identifier, Group group, int maxLevel, Set conflict, Set itemWhitelist, Set effectExecutors, List description, String format, BookItem bookItem) { this.author = author; this.identifier = identifier; this.group = group; @@ -96,7 +97,7 @@ public class Enchant { return this.conflict; } - public Set getItemWhitelist() { + public Set getItemWhitelist() { return new HashSet<>(this.itemWhitelist); } @@ -123,7 +124,7 @@ public class Enchant { private Group group; private int maxLevel; private Set conflict; - private Set itemWhitelist; + private Set itemWhitelist; private Set effectExecutors; private List description; private String format; @@ -157,7 +158,7 @@ public class Enchant { return this; } - public Enchant.EnchantBuilder itemWhitelist(Set itemWhitelist) { + public Enchant.EnchantBuilder itemWhitelist(Set itemWhitelist) { this.itemWhitelist = itemWhitelist; return this; } diff --git a/src/main/java/com/songoda/epicenchants/utils/single/ItemGroup.java b/src/main/java/com/songoda/epicenchants/utils/single/ItemGroup.java index 613427d..ee18c99 100644 --- a/src/main/java/com/songoda/epicenchants/utils/single/ItemGroup.java +++ b/src/main/java/com/songoda/epicenchants/utils/single/ItemGroup.java @@ -42,14 +42,14 @@ public class ItemGroup { groupMap.put(TRIDENTS, TRIDENT); } - public Set get(String key) { + public Set get(String key) { Optional optionalGroup = Group.from(key); - Set output = new HashSet<>(); + Set output = new HashSet<>(); optionalGroup.ifPresent(group -> output.addAll(getMaterials(group))); if (CompatibleMaterial.getMaterial(key) != null) { - output.add(CompatibleMaterial.getMaterial(key).getMaterial()); + output.add(CompatibleMaterial.getMaterial(key)); } return output; @@ -61,7 +61,7 @@ public class ItemGroup { for (int i = 0; i < 5; i++) { getGroup(materials).ifPresent(group -> { groups.add(group.getName()); - materials.removeAll(getMaterials(group).stream().map(e -> CompatibleMaterial.getMaterial(e)).collect(Collectors.toList())); + materials.removeAll(getMaterials(group).stream().collect(Collectors.toList())); }); } @@ -81,12 +81,12 @@ public class ItemGroup { return groupMap.asMap().entrySet().stream().filter(s -> materials.containsAll(s.getValue())).map(Map.Entry::getKey).findFirst(); } - public Set getMaterials(Group group) { - Set out = new HashSet<>(); + public Set getMaterials(Group group) { + Set out = new HashSet<>(); for (int i = 0; i < 5; i++) { if (group.getChildren().isEmpty()) - out.addAll(groupMap.get(group).stream().map(CompatibleMaterial::getMaterial).collect(Collectors.toList())); + out.addAll(groupMap.get(group)); else out.addAll(group.getChildren().stream().map(this::getMaterials).flatMap(Collection::stream).collect(Collectors.toSet())); }