add commandmanager dynamic register class function

This commit is contained in:
jascotty2 2019-08-21 23:58:41 -05:00
parent a9cc94e246
commit 2ca8925d14
2 changed files with 23 additions and 3 deletions

View File

@ -63,9 +63,8 @@ public class SongodaCore {
public SongodaCore(JavaPlugin javaPlugin) {
piggybackedPlugin = javaPlugin;
commandManager = new CommandManager(javaPlugin);
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);
commandManager.addCommand(new SongodaCoreCommand(this))
commandManager = new CommandManager(piggybackedPlugin);
commandManager.registerCommandDynamically(new SongodaCoreCommand(this))
.addSubCommand(new SongodaCoreDiagCommand(this));
Bukkit.getPluginManager().registerEvents(loginListener, javaPlugin);
}

View File

@ -55,6 +55,27 @@ public class CommandManager implements CommandExecutor, TabCompleter {
return all;
}
public CommandManager registerCommandDynamically(String command) {
CommandManager.registerCommandDynamically(plugin, command, this, this);
return this;
}
public SimpleNestedCommand registerCommandDynamically(AbstractCommand abstractCommand) {
SimpleNestedCommand nested = new SimpleNestedCommand(abstractCommand);
abstractCommand.getCommands().stream().forEach(cmd -> {
CommandManager.registerCommandDynamically(plugin, cmd, this, this);
commands.put(cmd.toLowerCase(), nested);
PluginCommand pcmd = plugin.getCommand(cmd);
if(pcmd != null) {
pcmd.setExecutor(this);
pcmd.setTabCompleter(this);
} else {
plugin.getLogger().warning("Failed to register command: /" + cmd);
}
});
return nested;
}
public SimpleNestedCommand addCommand(AbstractCommand abstractCommand) {
SimpleNestedCommand nested = new SimpleNestedCommand(abstractCommand);
abstractCommand.getCommands().stream().forEach(cmd -> {