📚 fix enchantment searching on books

Took 11 minutes
This commit is contained in:
Kiran Hart 2023-08-11 09:50:23 -04:00
parent 38f17da446
commit ebd443075e
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3

View File

@ -39,10 +39,12 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.Plugin;
@ -295,11 +297,20 @@ public class AuctionAPI {
public List<String> getItemEnchantments(ItemStack stack) {
final List<String> enchantments = new ArrayList<>();
Objects.requireNonNull(stack, "Item Stack cannot be null when getting enchantments");
if (!stack.getEnchantments().isEmpty()) {
stack.getEnchantments().forEach((k, i) -> {
enchantments.add(k.getName() + i);
});
// actual enchantment books
if (stack.getType() == XMaterial.ENCHANTED_BOOK.parseMaterial() && stack.getItemMeta() instanceof EnchantmentStorageMeta) {
final EnchantmentStorageMeta meta = (EnchantmentStorageMeta) stack.getItemMeta();
meta.getStoredEnchants().forEach((enchant, level) -> enchantments.add(enchantmentName(enchant.getName())));
return enchantments;
}
// normal enchantments on item
final ItemMeta meta = stack.getItemMeta();
if (meta != null && meta.hasEnchants()) {
meta.getEnchants().forEach((enchant, level) -> enchantments.add(enchantmentName(enchant.getName())));
}
return enchantments;
}
@ -796,4 +807,71 @@ public class AuctionAPI {
return meets;
}
private String enchantmentName(String arg) {
switch (Enchantment.getByName(arg).getName()) {
case "ARROW_DAMAGE":
return "Power";
case "ARROW_FIRE":
return "Flame";
case "ARROW_INFINITE":
return "Infinity";
case "ARROW_KNOCKBACK":
return "Punch";
case "BINDING_CURSE":
return "Curse of Binding";
case "DAMAGE_ALL":
return "Sharpness";
case "DAMAGE_ARTHROPODS":
return "Bane of Arthropods";
case "DAMAGE_UNDEAD":
return "Smite";
case "DEPTH_STRIDER":
return "Depth Strider";
case "DIG_SPEED":
return "Efficiency";
case "DURABILITY":
return "Unbreaking";
case "FIRE_ASPECT":
return "Fire Aspect";
case "FROST_WALKER":
return "Frost Walker";
case "KNOCKBACK":
return "Knockback";
case "LOOT_BONUS_BLOCKS":
return "Fortune";
case "LOOT_BONUS_MOBS":
return "Looting";
case "LUCK":
return "Luck of the Sea";
case "LURE":
return "Lure";
case "MENDING":
return "Mending";
case "OXYGEN":
return "Respiration";
case "PROTECTION_ENVIRONMENTAL":
return "Protection";
case "PROTECTION_EXPLOSIONS":
return "Blast Protection";
case "PROTECTION_FALL":
return "Feather Falling";
case "PROTECTION_FIRE":
return "Fire Protection";
case "PROTECTION_PROJECTILE":
return "Projectile Protection";
case "SILK_TOUCH":
return "Silk Touch";
case "SWEEPING_EDGE":
return "Sweeping Edge";
case "THORNS":
return "Thorns";
case "VANISHING_CURSE":
return "Cure of Vanishing";
case "WATER_WORKER":
return "Aqua Affinity";
default:
return "Unknown";
}
}
}