Improves messages when trying to salvage an item
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

Implements unimplemented too damaged for salvage message
Adds two new messages explaining whether an item will produce full or partial salvage
This commit is contained in:
2024-05-05 15:37:38 +02:00
parent e956c7dda7
commit 2612f4f7d8
6 changed files with 113 additions and 23 deletions

View File

@ -1,5 +1,6 @@
package net.knarcraft.blacksmith.util;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.enchantments.Enchantment;
@ -24,6 +25,23 @@ public final class SalvageHelper {
private static final Random random = new Random();
/**
* Gets whether the given item has a valid crafting recipe
*
* @param item <p>The item to check</p>
* @return <p>True if the item has a valid crafting recipe</p>
*/
public static boolean hasRecipe(@NotNull ItemStack item) {
List<Recipe> recipes = Bukkit.getRecipesFor(new ItemStack(item.getType(), item.getAmount()));
for (Recipe recipe : recipes) {
if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) {
return true;
}
}
return false;
}
/**
* Gets the sum of all enchantment levels for the given item
*