Solved NoSuchMethodError Enchantment Constructor

Discussion in 'Plugin Development' started by Smeary_Subset, Dec 29, 2023.

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

    Smeary_Subset

    I am receiving the following error with my AbstractCustomEnchantment class when I call super() for its parent class (Enchantment)

    Code:
    [19:59:36 ERROR]: Error occurred while enabling SurvivalEnhancer v1.0-SNAPSHOT (Is it up to date?)
    java.lang.NoSuchMethodError: 'void org.bukkit.enchantments.Enchantment.<init>(org.bukkit.NamespacedKey)'
            at com.coreminigames.survivalenhancer.customenchants.AbstractCustomEnchantment.<init>(AbstractCustomEnchantment.java:11) ~[SurvivalEnhancer.jar:?]
            at com.coreminigames.survivalenhancer.customenchants.NecroTeleportation.<init>(NecroTeleportation.java:15) ~[SurvivalEnhancer.jar:?]
            at com.coreminigames.survivalenhancer.customenchants.EnchantmentRegistrar.customEnchantments(EnchantmentRegistrar.java:19) ~[SurvivalEnhancer.jar:?]
            at com.coreminigames.survivalenhancer.customenchants.EnchantmentRegistrar.<init>(EnchantmentRegistrar.java:12) ~[SurvivalEnhancer.jar:?]
            at com.coreminigames.survivalenhancer.main.CorePlugin.onEnable(CorePlugin.java:14) ~[SurvivalEnhancer.jar:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:281) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
            at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:190) ~[paper-1.20.4.jar:git-Paper-364]
            at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[paper-1.20.4.jar:git-Paper-364]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.craftbukkit.v1_20_R3.CraftServer.enablePlugin(CraftServer.java:637) ~[paper-1.20.4.jar:git-Paper-364]
            at org.bukkit.craftbukkit.v1_20_R3.CraftServer.enablePlugins(CraftServer.java:548) ~[paper-1.20.4.jar:git-Paper-364]
            at org.bukkit.craftbukkit.v1_20_R3.CraftServer.reload(CraftServer.java:1097) ~[paper-1.20.4.jar:git-Paper-364]
            at com.coreminigames.universecontroller.commands.player.Rl.onCommand(Rl.java:18) ~[UniverseController.jar:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.craftbukkit.v1_20_R3.CraftServer.dispatchCommand(CraftServer.java:987) ~[paper-1.20.4.jar:git-Paper-364]
            at org.bukkit.craftbukkit.v1_20_R3.CraftServer.dispatchServerCommand(CraftServer.java:972) ~[paper-1.20.4.jar:git-Paper-364]
            at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:500) ~[paper-1.20.4.jar:git-Paper-364]
            at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:447) ~[paper-1.20.4.jar:git-Paper-364]
            at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1518) ~[paper-1.20.4.jar:git-Paper-364]
            at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1214) ~[paper-1.20.4.jar:git-Paper-364]
            at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:321) ~[paper-1.20.4.jar:git-Paper-364]
            at java.lang.Thread.run(Thread.java:842) ~[?:?]

    Code:
    Code:
    import org.bukkit.NamespacedKey;
    import org.bukkit.enchantments.Enchantment;
    import org.jetbrains.annotations.NotNull;
    
    public abstract class AbstractCustomEnchantment extends Enchantment {
        protected final String name;
    
        public AbstractCustomEnchantment(@NotNull String name) {
            super(NamespacedKey.minecraft(name));
            this.name = name;
        }
    
        @Override
        public final @NotNull String getName() {
            return name;
        }
    }
    I just upgraded to paper 1.20.4...may be a bug? I get no red lines in my IDE and according to the java docs the constructor does take a NamespacedKey. So I'm not sure what the problem is.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Smeary_Subset what javadocs are you looking at?
    The one I looked at didn't take arguments, not public at least
     
  3. Offline

    Smeary_Subset

    I am using Paper 1.20.2

    Code:
            <dependency>
                <groupId>io.papermc.paper</groupId>
                <artifactId>paper-api</artifactId>
                <version>1.20.2-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>

    I can also see in the java docs that it doesn't take any arguments. It used to work but ever since I upgraded my server is hasn't.

    My IDE is saying that it needs an argument
    upload_2024-1-1_14-5-15.png
     
  4. Offline

    KarimAKL

  5. Offline

    Smeary_Subset

    Yup, you are correct. Turns out I was referencing 1.20.2 in pom.xml and when I changed it to 1.20.4 the new constructor registered.
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page