How to create custom enchantments?

Discussion in 'Spigot Plugin Development' started by TOminerTV, Apr 15, 2019.

  1. #1 TOminerTV, Apr 15, 2019
    Last edited: Apr 15, 2019
  2. I would recommend an existing enchants api over the Spigot api. There's a few considerations I'd make:
    • Standardization / Existing Resources
    • Ease of coding
    • End look
    Standardization / Existing Resources: Do you plan on using other custom enchants which depend on TokenEnchants or another enchants api? I wouldn't recommend using some plugins for your server which require token enchants, and others that use the spigot api. I'd also look at how many existing plugins use token enchants vs. the Spigot api. I would assume more use the former, but I have no idea.

    Ease of coding: In the article you linked, 2008Choco made a good point about the Spigot api being much simpler to use. I've actually written a custom enchants api, and it's a lot more work than using the Spigot api. If your plan is to use an existing enchants api, this isn't really a concern. I think plugins like crazy enchants have a lot of issues, I've got no idea how many other ones have, so that is one concern. Also, do you want features like /enchanter or /tinkerer. I'd assume these resources are built into a custom enchant plugin. If you don't want these, this is less of a concern.

    End look: Do you want your custom enchants to have roman numerals? I'd also check if the Spigot api provides color code support, if that's something you value.


    If you're going to use the Spigot API, I think 2008Choco's answer includes how you can register the enchants.
     
  3. I tried to use this answer, but i dont know how i can register the enchantment:
    https://proxy.spigotmc.org/b76b56ee30ab13f598d586943eb08bc9cf0b3aa8?url=http://i.imgur.com/CIOVqy6.png
    https://proxy.spigotmc.org/02b7422a9a5bb8fa7fe8d7aabc7029b92d66ad9c?url=http://i.imgur.com/dMH8rDE.png

    Does this have to be in the main class, or where should I write it?
     
  4. The first link is meant to be put in it's own class with a bunch of other enchants. "This is similar to an enum, but I also have various other methods in this class." (2008Choco)

    Code (Text):
    public static final CustomEnchant BEAMSHOT = new EnchantBeamshot();

    public static final CustomEnchant OtherEnchant = new EnchantOtherEnchant();

    public static final CustomEnchant ThridEnchant = new EnchantNumberThree();
    I would paste the registerLocalEnchants() inside your main class. To add an enchant, add a new line of code with registerEnchantment(BEAMSHOT) for whatever enchant you're referencing.
     
  5. If i try to register the enchants i getting these error by creating the method:
    Code (Text):
    EnchantmentRegistrationResult cannot be resolved to a type
    And the method
    Code (Text):
    registerEnchantment();
    cant found too, where i get it from or how to create it?
     
    #5 TOminerTV, Apr 16, 2019
    Last edited: Apr 16, 2019
  6. Is EnchantmentRegistrationResult something you can import? I assumed it was a Spigot AIP Enum, but you might have to create it.

    Choco also said something about Enchantment.stopAcceptingRegistrations(), not working. I'm not 100% sure on what he meant, but, I assume that would add your enchants to a list of enchants for when you tab in a command.
     
  7. I cant import EnchantmentRegistrationResult i only can create a class, enum or something else.
     
  8. You'll have to create an enum.
     
  9. And how i create that, what must i write in the file?
     
  10. I think you're in a little over your head.
     
  11. Now i created a enum for the returns but the
    Code (Text):
    Enchantment.stopAcceptingRegistrations();
    throws an error, in Choco's post stand i should use the
    Code (Text):
    org.bukkit.command.EnchantCommand
    but this class doesnt exists. This class only exists in 1.7.10!

    Here is my current main code:
    https://pastebin.com/PWqHQyzy
     
  12. Enum is a data type (??? - not sure about saying data) type in Java. Just like you've got interfaces, classes, you have enums. They are used to get some pre-set values. For instance, ChatColor.<colorName> is an Enum. For enchantments, enums would be an enum class holding enchantments.


    Code (Java):
    public Enum Custom
    {

      BEAMSHOT(args);

      CustomType type;

      Custom(ArgType args)
      {
        //Do something with the args

        Type type = new Type(someOtherArgsIDKHowYouUseIt);
        this.type = type;
      }

      public Type getType()
      {
        return type;
      }

    }
    After that, you can get the enchantment with:
    Code (Java):
    Type enchantment = Custom.BEAMSHOT.getType();
     
  13. Ok, but why do I need that, it's about return messages, which I think I've managed too. Now I have the problem with the registration that you can not use the function and the class no longer exists.
     
  14. Firstly I thought you didn't understand what Enums mean or how to use them so I tried to clarify. Either way; for the API it's either that you're using a build tool (like Maven) and not compiling on build (shading) or you're using an API and it is not running in the /plugins/ folder. It can't call for a method from another file - if that file doesn't exist;
     
  15. But there must be some way to add in the 1.8 own enchantments. But how?
    Best without maven or such a other tool.
     
  16. I hate to be 'that guy' but Custom Enchantments are quite a complicated matter and potentially more so when you have a larger number of them. I suggest using a public plugin whilst you develop your coding skills so you can learn more about how enums and classes work. You don't need maven.
     
  17. Can not someone just send me a tutorial on how to do that or say it's not working but not always talking around, I'm far from finished learning, but I think I know a bit about Java.

    So is it possible to add your own enchantments or should I simply use item descriptions? And can you get these enchantments through the enchantment table?
     
  18. Meant on using Maven if he's using an API and wants it shaded.
     
    • Like Like x 1

Share This Page