use compat material in whitelist to simplify things

This commit is contained in:
Aurora 2020-08-31 11:50:22 +02:00
parent 2679f63c60
commit 1d3bafc4e6
4 changed files with 15 additions and 15 deletions

View File

@ -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(", "));

View File

@ -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);

View File

@ -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<String> conflict;
private Set<Material> itemWhitelist;
private Set<CompatibleMaterial> itemWhitelist;
private Set<EffectExecutor> effectExecutors;
private List<String> description;
private String format;
@Nullable
private BookItem bookItem;
Enchant(String author, String identifier, Group group, int maxLevel, Set<String> conflict, Set<Material> itemWhitelist, Set<EffectExecutor> effectExecutors, List<String> description, String format, BookItem bookItem) {
Enchant(String author, String identifier, Group group, int maxLevel, Set<String> conflict, Set<CompatibleMaterial> itemWhitelist, Set<EffectExecutor> effectExecutors, List<String> 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<Material> getItemWhitelist() {
public Set<CompatibleMaterial> getItemWhitelist() {
return new HashSet<>(this.itemWhitelist);
}
@ -123,7 +124,7 @@ public class Enchant {
private Group group;
private int maxLevel;
private Set<String> conflict;
private Set<Material> itemWhitelist;
private Set<CompatibleMaterial> itemWhitelist;
private Set<EffectExecutor> effectExecutors;
private List<String> description;
private String format;
@ -157,7 +158,7 @@ public class Enchant {
return this;
}
public Enchant.EnchantBuilder itemWhitelist(Set<Material> itemWhitelist) {
public Enchant.EnchantBuilder itemWhitelist(Set<CompatibleMaterial> itemWhitelist) {
this.itemWhitelist = itemWhitelist;
return this;
}

View File

@ -42,14 +42,14 @@ public class ItemGroup {
groupMap.put(TRIDENTS, TRIDENT);
}
public Set<Material> get(String key) {
public Set<CompatibleMaterial> get(String key) {
Optional<Group> optionalGroup = Group.from(key);
Set<Material> output = new HashSet<>();
Set<CompatibleMaterial> 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<Material> getMaterials(Group group) {
Set<Material> out = new HashSet<>();
public Set<CompatibleMaterial> getMaterials(Group group) {
Set<CompatibleMaterial> 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()));
}