Added option to show target groups in /enchantinfo

This commit is contained in:
Auxilor 2020-10-18 20:17:28 +01:00
parent ec61350b94
commit b8ad3d2193
3 changed files with 36 additions and 15 deletions

View File

@ -84,13 +84,23 @@ public final class CommandEnchantinfo extends AbstractCommand {
Set<String> applicableItemsSet = new HashSet<>();
targets.forEach(material -> {
String matName = material.toString();
matName = matName.toLowerCase();
matName = matName.replaceAll("_", " ");
matName = WordUtils.capitalize(matName);
applicableItemsSet.add(matName);
});
if(ConfigManager.getConfig().getBool("commands.enchantinfo.show-target-group")) {
enchantment.getRawTarget().forEach(target -> {
String targetName = target.getName();
targetName = targetName.toLowerCase();
targetName = targetName.replaceAll("_", " ");
targetName = WordUtils.capitalize(targetName);
applicableItemsSet.add(targetName);
});
} else {
targets.forEach(material -> {
String matName = material.toString();
matName = matName.toLowerCase();
matName = matName.replaceAll("_", " ");
matName = WordUtils.capitalize(matName);
applicableItemsSet.add(matName);
});
}
StringBuilder targetNamesBuilder = new StringBuilder();
applicableItemsSet.forEach((name1) -> {

View File

@ -17,12 +17,7 @@ import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.regex.Pattern;
@SuppressWarnings("unchecked")
@ -41,7 +36,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
private int maxLvl;
private Set<Enchantment> conflicts;
private EnchantmentRarity rarity;
private final Set<Material> target = new HashSet<>();
private Set<com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget> target = new HashSet<>();
private boolean enabled;
@ -89,7 +84,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
name = ChatColor.translateAlternateColorCodes('&', config.getString("name"));
description = ChatColor.translateAlternateColorCodes('&', config.getString("description"));
target.clear();
config.getTargets().forEach(enchantmentTarget -> target.addAll(enchantmentTarget.getMaterials()));
target.addAll(config.getTargets());
enabled = config.getBool("enabled", true);
this.register();
@ -235,6 +230,18 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
* @return Set of enchantable items
*/
public Set<Material> getTarget() {
Set<Material> materials = new HashSet<>();
target.forEach(target -> {
materials.addAll(target.getMaterials());
});
return materials;
}
/**
* Get raw target of enchantment
* @return {@link com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget}
*/
public Set<com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget> getRawTarget() {
return target;
}

View File

@ -3,6 +3,10 @@
# by Auxilor
#
commands:
enchantinfo:
show-target-group: true # Show name of target group rather than individual items
anvil:
allow-unsafe-levels: false # Allow unsafe enchantments like Sharpness 6 by combining 2 Sharp 5.
allow-combining-unsafe: true # Allow further combining unsafe levels, eg Sharp 6 + Sharp 6 = Sharp 7.