Solved Custom Enchantment Lore

Discussion in 'Spigot Plugin Development' started by J4D3N, Nov 28, 2015.

  1. I have been messing around with the Bukkit EnchantmentWrapper class, I made a custom enchantment and assigned it an enchantment id (120). I noticed when I enchanted an item the enchantment didn't appear in the lore and I cannot figure out why. I looked into the net.minecraft.server.v1_8_R3.Enchantment class and noticed that there is a method which returns the name + level in a string (d method) but it uses the net.minecraft.server.v1_8_R3.LocaleI18n class.

    My attempt to add the name of the plugin to the locale was successful by using:
    Code (Text):
    try {
        Field field_1 = LocaleI18n.class.getDeclaredField("a");
        LocaleLanguage locale = (LocaleLanguage) field_1.get(null);

        Field field_2 = LocaleLanguage.class.getDeclaredField("d");
        ((Map<String, String>) field_2.get(locale)).put("enchantment." + "mending", "Mending");
    } catch(Exception e) {
    However the enchantment would still not appear in the lore, I know I can customize the lore manually but I am curious if there is a way to do it using the enchantment class.
    #1 J4D3N, Nov 28, 2015
    Last edited: Nov 29, 2015
  2. Despite you registering the enchantment on the server with a name, no such data in sent to the player. The player's client simply does not have the enchantment stored in the array.

    Additionally, if you place an item with a enchantment that is not registered for the client in an anvil, their game crashed from a NPE.
    • Agree Agree x 1
  3. You must manually add the lore. I have already tried making enchantments as well but the lore never showed up. I knew they were enchanted because I compared the items using events. Also if you return a new instance of the same enchantment you made every time it is called to the item will still not be the same so if you intend on comparing the item i'd suggest mapping the item and its enchantment.
  4. Is there currently a way to detect an item being enchanted by a plugin using the Bukkit API?
  5. EnchantItemEvent
  6. "Called when an ItemStack is successfully enchanted (currently at enchantment table)"