From b8ad3d2193e7d021f887dd767e7d4bb170842e06 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 18 Oct 2020 20:17:28 +0100 Subject: [PATCH] Added option to show target groups in /enchantinfo --- .../command/commands/CommandEnchantinfo.java | 24 +++++++++++++------ .../ecoenchants/enchantments/EcoEnchant.java | 23 +++++++++++------- Plugin/src/main/resources/config.yml | 4 ++++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java b/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java index 12b8fa5c..f62671b5 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java @@ -84,13 +84,23 @@ public final class CommandEnchantinfo extends AbstractCommand { Set 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) -> { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index 6b888657..06708b76 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -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 conflicts; private EnchantmentRarity rarity; - private final Set target = new HashSet<>(); + private Set 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 getTarget() { + Set 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 getRawTarget() { return target; } diff --git a/Plugin/src/main/resources/config.yml b/Plugin/src/main/resources/config.yml index 7469327e..d2dbb863 100644 --- a/Plugin/src/main/resources/config.yml +++ b/Plugin/src/main/resources/config.yml @@ -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.