onTabComplete not getting called.

Discussion in 'Plugin Development' started by sparkinex, Aug 20, 2019.

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

    sparkinex

    Hi I am trying to setup tab auto complete on my custom commands however it appears the method is not getting called. Does anyone have any idea why the onTabComplete method is not getting called? I posted the code that should be relevant in order to keep this post short but if you need more please let me know.

    This is were I register the command as well as attempt to set the tab completer for the command this is in my BaseCommand class which implements TabExecutor:
    Code:
        private ReflectCommand cmd = new ReflectCommand(command);
    
        public void register() {
            CommandUtils.registerToCommandMap(command, cmd);
    
            cmd.setExecutor(this);
            CommandUtils.createPluginCommand(command).setTabCompleter(this);
        }
    And here is my onTabComplete method also in my BaseCommand class:
    (Random question: Should I return null or a empty string I heard that craftbukkit interprets null as show a list of plugins?)
    Code:
    @Override
        public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
            System.out.println("ON TAB COMPLETE WAS CALLED!");
            return new ArrayList<String>();
        }
    Heres how I register the method to the command map:
    Code:
    public static void registerToCommandMap(String fallback, Command command) {
            try {
                Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
                bukkitCommandMap.setAccessible(true);
                CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
                commandMap.register(fallback, command);
            } catch (IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException e) {
                e.printStackTrace();
            }
        }
    Here is the method I use to create a PluginCommand instance:
    Code:
    @Nullable
        public static PluginCommand createPluginCommand( @Nonnull String name ) {
            try {
                Constructor<PluginCommand> constructor = PluginCommand.class.getDeclaredConstructor( String.class, Plugin.class );
                constructor.setAccessible( true );
                return constructor.newInstance(name, PluginBase.INSTANCE);
            } catch ( NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e ) {
                e.printStackTrace();
            }
            return null;
        }
     
    Last edited by a moderator: Aug 20, 2019
  2. Offline

    KarimAKL

    @sparkinex May i ask why you are using reflection?
    Btw, if the method returns null, you'll get a list of the online players, if it's an empty list, you'll get nothing.
     
Thread Status:
Not open for further replies.

Share This Page