Can anyone help? I have no idea how to fix :( @annotations

Discussion in 'Plugin Development' started by Pizza371, Jan 5, 2014.

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

    Pizza371

    whatsup people? I got another problem!
    Now I know this might not be strictly to do with bukkit, but, please help? D:

    So I have this:
    Code:
        public void registerCommands(Object o) {
            Class<?> c = o.getClass();
            for(Method m : c.getDeclaredMethods()) {
                if(m.isAnnotationPresent(Override.class)) {
                    System.out.println("method " + m.getName() + " has @override");
                }
                if(m.isAnnotationPresent(CommandListener.class)) {
                    map.put(m.getAnnotation(CommandListener.class), m);
                }
            }
        }
    Code:
    public class Main extends JavaPlugin {
        private MineManager mm;
        private CommandHandler ch;
     
        @Override
        public void onEnable() {
            this.getConfig().options().copyDefaults(true);
            this.saveDefaultConfig();
            ch = new CommandHandler();
            ch.registerCommands(this);
        }
     
        public boolean onCommand(CommandSender s, Command cmd, String cmdname, String[] args) {
            return ch.handleCommand(s, cmd, cmdname, args);
        }
     
        @CommandListener(
                name = "lol.me",
                noPermission = "lolloeleo"
                )
        public void killMe(CommandInfo ci) {
         
        }
     
        @Override
        public void onDisable() {
            mm.saveMinesToFile();
        }
     
        public MineManager getMM() {
            return mm;
        }
     
        public CommandHandler getCH() {
            return ch;
        }
    }
    and this to check if the hashmap from registerCommands method was filled with anything..

    Code:
    if(getCommands().isEmpty()) {
                System.out.println("set is e pty! OH NO");
                return false;
            } else System.out.println("SET IS EMPTY NOT");
    it shows "set is e pty! OH NO" every time (i know it's not a Set..).

    when I added the debug lines, it shows nothing in console (apparently none of the methods have @Override either..).

    Uh.. idk what else to say.. the code is a bit messy because I was screwing around with it trying to find the problem.

    I know this looks similar to the ones in Resources, and yes, I took the idea from there.
    I didn't copy anyones work, just trying to reproduce it so i can add my own implementations and see if I can actually achieve it. :)

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page