Speeds up smith presets by using caching and sets
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

This commit is contained in:
2024-05-06 12:56:22 +02:00
parent 3dd8467a58
commit 3ed3c99c15
4 changed files with 87 additions and 52 deletions

View File

@ -101,10 +101,12 @@ public final class ItemHelper {
/**
* Gets a complete list of all reforge-able materials
*
* <p>Note: As this loops through all materials, the result should be cached</p>
*
* @return <p>A complete list of reforge-able materials</p>
*/
public static @NotNull List<Material> getAllReforgeAbleMaterials() {
List<Material> reforgeAbleMaterials = new ArrayList<>();
public static @NotNull Set<Material> getAllReforgeAbleMaterials() {
Set<Material> reforgeAbleMaterials = new HashSet<>();
for (Material material : Material.values()) {
ItemStack item = new ItemStack(material);
if (isRepairable(item)) {
@ -207,12 +209,12 @@ public final class ItemHelper {
* @param extended <p>Whether to use an extended match, allowing any material</p>
* @return <p>The matched material(s)</p>
*/
public static @NotNull List<Material> getWildcardMatch(@NotNull String materialName, boolean extended) {
public static @NotNull Set<Material> getWildcardMatch(@NotNull String materialName, boolean extended) {
String search = InputParsingHelper.regExIfy(materialName);
List<Material> materials = new ArrayList<>();
List<Material> all;
Set<Material> materials = new HashSet<>();
Set<Material> all;
if (extended) {
all = List.of(Material.values());
all = Set.of(Material.values());
} else {
all = ItemHelper.getAllReforgeAbleMaterials();
}