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) { public SongodaCore(JavaPlugin javaPlugin) {
piggybackedPlugin = javaPlugin; piggybackedPlugin = javaPlugin;
commandManager = new CommandManager(javaPlugin); commandManager = new CommandManager(piggybackedPlugin);
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager); commandManager.registerCommandDynamically(new SongodaCoreCommand(this))
commandManager.addCommand(new SongodaCoreCommand(this))
.addSubCommand(new SongodaCoreDiagCommand(this)); .addSubCommand(new SongodaCoreDiagCommand(this));
Bukkit.getPluginManager().registerEvents(loginListener, javaPlugin); Bukkit.getPluginManager().registerEvents(loginListener, javaPlugin);
} }

View File

@ -55,6 +55,27 @@ public class CommandManager implements CommandExecutor, TabCompleter {
return all; 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) { public SimpleNestedCommand addCommand(AbstractCommand abstractCommand) {
SimpleNestedCommand nested = new SimpleNestedCommand(abstractCommand); SimpleNestedCommand nested = new SimpleNestedCommand(abstractCommand);
abstractCommand.getCommands().stream().forEach(cmd -> { abstractCommand.getCommands().stream().forEach(cmd -> {