diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java index 1e558ff..6b8bdb5 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java @@ -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 getItemEnchantments(ItemStack stack) { final List 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"; + } + } }