Solved Custom Enchantments?

Discussion in 'Plugin Development' started by Minnymin3, Apr 28, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Minnymin3

    Im making a magic plugin and i came across an instance where i want to put in a new enchantment.
    Ive created a class that extends Enchantment and then attempted to register it and i got:
    Code:
    12:59:21 [SEVERE] Error occurred while enabling Zephyrus v0.1 (Is it up to date?)
    java.lang.IllegalStateException: No longer accepting new enchantments (can only be done by the server implementation)
    at org.bukkit.enchantments.Enchantment.registerEnchantment(Enchantment.java:222)
    at minny.zephyrus.Zephyrus.addEnchants(Zephyrus.java:45)
    at minny.zephyrus.Zephyrus.onEnable(Zephyrus.java:24)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
    at org.bukkit.craftbukkit.v1_5_R2.CraftServer.loadPlugin(CraftServer.java:282)
    at org.bukkit.craftbukkit.v1_5_R2.CraftServer.enablePlugins(CraftServer.java:264)
    at org.bukkit.craftbukkit.v1_5_R2.CraftServer.<init>(CraftServer.java:218)
    at net.minecraft.server.v1_5_R2.PlayerList.<init>(PlayerList.java:55)
    at net.minecraft.server.v1_5_R2.DedicatedPlayerList.<init>(SourceFile:11)
    at net.minecraft.server.v1_5_R2.DedicatedServer.init(DedicatedServer.java:105)
    at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:381)
    at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    
    Heres my registration code:
    Code:
    public void addEnchants() {
    EnchantGlow glow = new EnchantGlow(120);
    Enchantment.registerEnchantment(glow);
    }
    
    and heres my EnchantGlow class:
    Code:
    public class EnchantGlow extends EnchantmentWrapper{
     
    public EnchantGlow(int id) {
    super(id);
    }
     
    @Override
    public boolean canEnchantItem(ItemStack item) {
    returntrue;
    }
     
    @Override
    public boolean conflictsWith(Enchantment other) {
    returnfalse;
    }
     
    @Override
    public EnchantmentTarget getItemTarget() {
    returnnull;
    }
     
    @Override
    public int getMaxLevel() {
    return 10;
    }
     
    @Override
    public String getName() {
    return"Glow";
    }
     
    @Override
    public int getStartLevel() {
    return 1;
    }
     
    }
    
     
  2. Offline

    chasechocolate

    Well here's what's wrong:
    Code:
    java.lang.IllegalStateException: No longer accepting new enchantments (can only be done by the server implementation)
    I'm not sure what that means, though...
     
  3. Offline

    Minnymin3

    Ya i figured out that :p but ive been googling this for like 2 hours and no answer :'(
     
  4. Offline

    Cybermaxke

    Put this before registering a new echantment. ;)
    Code:
    try {
        Field f = Enchantment.class.getDeclaredField("acceptingNew");
        f.setAccessible(true);
        f.set(null, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
     
  5. Offline

    FlareLine

    This could be useful for an idea I have... :)
    How would one go about registering a custom Enchantment and applying it to an item?
     
  6. Offline

    Minnymin3

    YAY it works thx :D
    I registered the enchantment with:
    Code:
    try {
    EnchantmentWrapper.registerEnchantment(glow);
    } catch (IllegalArgumentException e){
     
    }
    
    Glow is the enchantment class
    and then did
    Code:
    item.addEnchantment(plugin.glow, 1);
    
     
  7. Offline

    FlareLine

    Thanks. This will help a lot. :)
     
  8. Offline

    CeramicTitan

    EnchantGlow glow = new EnchantGlow(120); what enchantment is enchantment 120
     
  9. Offline

    Minnymin3

    120 is the id that i decided to assign to my custom enchant.

    Dont leave out the try and catch because then on a /reload it will cause errors

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  10. Offline

    FlareLine

    Minnymin3 Gotcha :) I'll tag you or PM you if I need any more help. Right now I'm busy with another plugin.
     
  11. Offline

    Minnymin3

    Ok
     
  12. Offline

    CeramicTitan

    could you add these custom enchantments to enchantment table?
     
  13. Offline

    Minnymin3

    You could do it hackily by randomly giving it to an item that is pulled out of the enchantment table
     
  14. Offline

    malikdbuseck

    Having some troubles with this. I cant seem to get it to register the plugin.glow
     
Thread Status:
Not open for further replies.

Share This Page