package net.knarcraft.blacksmith.config; import net.knarcraft.blacksmith.BlacksmithPlugin; import org.bukkit.Material; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; /** * A representation of the presets for different kinds of smiths */ public enum SmithPreset { /** * A blacksmith capable of re-forging all weapons (including shields) */ WEAPON_SMITH(new SmithPresetFilter[]{SmithPresetFilter.BOW, SmithPresetFilter.SWORD, SmithPresetFilter.RANGED}), /** * A blacksmith capable of re-forging all armor */ ARMOR_SMITH(new SmithPresetFilter[]{SmithPresetFilter.LEATHER, SmithPresetFilter.IRON, SmithPresetFilter.CHAINMAIL, SmithPresetFilter.GOLD, SmithPresetFilter.DIAMOND, SmithPresetFilter.NETHERITE}), /** * A blacksmith capable of re-forging all tools (hoe, axe, shovel, pickaxe, flint and steel, shears, fishing rod) */ TOOL_SMITH(new SmithPresetFilter[]{SmithPresetFilter.WOOD, SmithPresetFilter.STONE, SmithPresetFilter.IRON, SmithPresetFilter.GOLD, SmithPresetFilter.DIAMOND, SmithPresetFilter.NETHERITE, SmithPresetFilter.PICKAXE, SmithPresetFilter.AXE, SmithPresetFilter.HOE, SmithPresetFilter.SHOVEL, SmithPresetFilter.MISC}); private final SmithPresetFilter[] filters; /** * Instantiates a new smith preset * * @param filters
The filters applicable to this preset
*/ SmithPreset(SmithPresetFilter[] filters) { this.filters = filters; } /** * Gets whether this preset supports the given filter * * @param filterThe filter to check
* @returnTrue if the filter is supported
*/ public boolean supportsFilter(SmithPresetFilter filter) { return List.of(filters).contains(filter); } /** * Gets all filters supported by this preset * * @returnThe filters supported by this preset
*/ public ListAll available smith presets
*/ public static ListThe string that might be a preset
* @returnThe string, possibly with the preset replaced
*/ public static String replacePreset(String possiblePreset) { String upperCasedPreset = possiblePreset.replace('-', '_').toUpperCase(); if (!upperCasedPreset.startsWith("PRESET:")) { return possiblePreset; } //Parse the input SmithPresetFilter filter = null; SmithPreset preset; try { String[] parts = upperCasedPreset.split(":"); if (parts.length > 2) { filter = SmithPresetFilter.valueOf(parts[2]); } preset = SmithPreset.valueOf(parts[1]); } catch (IllegalArgumentException exception) { /* This case means that either the preset or the filter given is invalid, and thus the preset string should be ignored to prevent any problems. */ BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, String.format("The smith preset %s is " + "invalid, and will be ignored. Please fix it!", possiblePreset)); return ""; } //Return the list of materials included in the preset if (filter != null) { return String.join(",", preset.getMaterialNames(filter)); } else { return String.join(",", preset.getMaterialNames()); } } /** * Gets the materials included in this preset, filtered using the given filter * * @param filterThe filter to use for filtering
* @returnThe materials included in this preset, filtered using the given filter
*/ public ListAll materials in this preset
*/ public ListAll ranged weapon materials
*/ private ListAll tool materials
*/ private ListAll weapon materials
*/ private ListAll sword materials
*/ private ListThe string to look for
* @returnThe resulting materials
*/ private ListAll material names for this smith
*/ private ListThe filter used for filtering materials
* @returnAll material names for this smith
*/ private ListThe materials to get the names of
* @returnThe names of the materials
*/ private List