Solved NoSuchMethodError despite the method being there

Discussion in 'Spigot Plugin Development' started by notjacob1, Feb 13, 2020.

  1. Code (Text):

    [17:14:59 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing 'setarena' in github.notjacobdev.commands.CmdSetarena(setarena)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:148) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    at java.base/java.lang.Thread.run(Thread.java:830) [?:?]
    Caused by: java.lang.NoSuchMethodError: 'java.lang.String github.notjacobdev.util.ChatUtil.usage(java.lang.String)'
    at github.notjacobdev.commands.CmdSetarena.execute(CmdSetarena.java:42) ~[?:?]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
    ... 14 more
     
    I get this error while running /setarena, despite the method being there when the jar is decompiled
    [​IMG]

    Line 42:
    Code (Text):
    p.sendMessage(ChatUtil.usage("/setarena"));
    Any ideas?
    EDIT: This error seems to be happening with all the methods in ChatUtil, though when I get the string with Text#get() directly there is no error
     

    Attached Files:

  2. Since it looks like it's caused by Bukkit not recognizing the command, are you sure you've registered it properly? (with an executor and defined in your plugin.yml)
     
  3. as far as I can tell they are being registered properly
    I added a debug println and this was the result
    Code (Text):

    [18:36:09 INFO]: Registered command: arenatp
    [18:36:09 INFO]: Registered command: dhelp
    [18:36:09 INFO]: Registered command: rmarena
    [18:36:09 INFO]: Registered command: setspawn
    [18:36:09 INFO]: Registered command: daccept
    [18:36:09 INFO]: Registered command: rmtype
    [18:36:09 INFO]: Registered command: resetstats
    [18:36:09 INFO]: Registered command: gettypeitem
    [18:36:09 INFO]: Registered command: dtypes
    [18:36:09 INFO]: Registered command: settype
    [18:36:09 INFO]: Registered command: darenas
    [18:36:09 INFO]: Registered command: dleave
    [18:36:09 INFO]: Registered command: setarena
    [18:36:09 INFO]: Registered command: ddeny
    [18:36:09 INFO]: Registered command: viewinvbasecomponent
    [18:36:09 INFO]: Registered command: leavequeue
    [18:36:09 INFO]: Registered command: duel
    [18:36:09 INFO]: Registered command: stool
    [18:36:09 INFO]: Registered command: dtool
    [18:36:09 INFO]: Registered command: dstats
    [18:36:09 INFO]: Registered command: duelqueue
     
    Code (Text):

    private synchronized void registerCommands() {
       Field bukkitCommandMap;
       try {
          bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
          bukkitCommandMap.setAccessible(true);
          CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
          for (int i = 0; i < commandmap.size(); i++) {
             commandMap.register("NotDuels", commandmap.get(i));
             System.out.println("Registered command: " + commandmap.get(i).getName());
          }
       } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
          e.printStackTrace();
       }
    }
     
     
  4. md_5

    Administrator Developer

    Do a clean recompile
     
  5. Did a gradle clean, artifact clean, intellij cache invalidation, rebuild, recompile, deleting and remaking the class etc, nothing changed
     
  6. Are you modifying the jar while running?
     
  7. No, I am not
     
  8. bump, have done a ton of updates to my plugin and I'm still getting this error
    Here's a screenshot of my IDE if it helps any
     
  9. Update: Solved!
    Renaming the class from ChatUtil to ChatUtilities worked