Better EnchantAPI?

Discussion in 'Spigot Plugin Development' started by Futurize, May 3, 2017.

  1. Hey guys! Currently, I have began working on a custom enchantment plugin using this API https://dev.bukkit.org/projects/enchantmentapi. It works exactly the way I want it to, except for the weird placeholder that shows up when placing it into the enchantment table. Does anyone have an API for custom enchants with most of the same features as this but without the placeholder thing? Thanks!
     
  2. You can always make your own using the Bukkit enchantment API.
     
  3. Yeah but does that allow you to get them through an enchanting table?
     
  4. Only 2 backsides:
    - Requires lores.
    - Requires you to reflect the field which allows registration in Enchantment to be set to true then call Enchantments#stopRegistrations or whatever it's called.
     
  5. Any tutorials anywhere on how to do this? Don't quite have a grasp on how to do this. Also, I am looking for something that allows you to combine them in anvils to get higher levels.
     
  6. https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/enchantments/Enchantment.html
    Extend it.
    https://hub.spigotmc.org/stash/proj.../org/bukkit/enchantments/Enchantment.java#166
    Reflect this field to true(It's changed when bukkit is done loading):
    Code (Java):
    try {
        Field field = Enchantment.class.getDeclaredField("acceptingNew");
        field.setAccessible(true);
        field.set(null, true);
    } catch (Exception ex) {ex.printStackTrace();}
    Then register using Enchantment#registerEnchantment
    Once you're done, let it load them by calling Enchantment#stopAcceptingRegistrations
     
  7. Didn't try it out yet but someone told me that this will not work for anvils/enchanting tables.

    What do I do from here? I reflected it to true in the onEnable().
    Code (Text):
    public class Test extends Enchantment {

        public Test(int id) {
            super(id);
            registerEnchantment(Enchantment.getByName("test"));
        }

        @Override
        public boolean canEnchantItem(ItemStack item) {
            return false;
        }

        @Override
        public boolean conflictsWith(Enchantment enchant) {
            return false;
        }

        @Override
        public EnchantmentTarget getItemTarget() {
            return null;
        }

        @Override
        public int getMaxLevel() {
            return 2;
        }

        @Override
        public String getName() {
            return "test";
        }

        @Override
        public int getStartLevel() {
            return 1;
        }
    }
     
  8. this wont work at all