koply / KCommando

Annotation-based multifunctional command handler framework for JDA & Javacord.
GNU General Public License v3.0
47 stars 7 forks source link

Verbose logging triggers wrongly #13

Open Phoenix-Starlight opened 9 months ago

Phoenix-Starlight commented 9 months ago

Describe the bug Verbose logging fires incorrectly and logs messages about methods not being annotated, even though they are annotated.

To Reproduce Steps to reproduce the behavior:

  1. Create a slash command class
    public class Ping {
    @HandleSlash(name = "ping", desc = "Ping the bot")
    public static void pingCommand(SlashCommandCreateEvent event) {
        event
            .getSlashCommandInteraction()
            .createImmediateResponder()
            .setContent("Pong!")
            .respond();
    }
    }
  2. Enable verbose logging in KCommando configuration.
  3. Annotate with HandleSlash
  4. Execute the project
  5. See The skipped methods at bot_test.commands.slash.Ping: (They don't have any appropriate annotation)

Expected behavior It shouldn't log this message unless it is wrong. (Not annotated)

Versions Your current JDA, Reflections8 and KCommando versions. Javacord 3.8.0 KCommando 5.1.0 Reflections8: N/A

PillageDev commented 6 months ago

If your message is saying something like this: [19:48:55.885 INFO] KCommando -> The skipped methods at dev.tiertests.commands.cooldown.ManageCooldownCmd: hashCode,getClass,notify,notifyAll (They don't have any appropriate annotation)

It is because those methods are inherited from the java Object class, and the annotation is just seeing those too.

PillageDev commented 6 months ago

The simple fix would be to in the KInitalizer class add this check

if (annotationType == null) {
    if (KCommando.verbose) {
        if (!(method.getDeclaringClass() == Object.class)) {
            skippedMethods.add(method.getName());
        }
    }
    continue;
}