Why some people use onCommand() function in the main class and some people register commands? Whats the different between them?
Actually, you could say there's three types of command handling. One where you use the onCommand function is in your main class, with a plugin.yml. One with a CommandExecutor class, registering it and adding it in a plugin.yml, and lastly a method to extend Command and implement PluginIdentifiableCommand and stuff. Then registering it in the main file. Most people will agree that the last option is the most viable for bigger plugins. That is because it is easier to create a superclass and make the subclasses extend it, so you can prevent duplicate code. Furthermore, a lot of people (like me) simply dislike adding the commands in the plugin.yml file. There is not a big difference between the first and second method. It's essentially the same but in a different class. You register a command because a class won't just magically be executed without initiating it.
They aren't three "types of commands". They're all the same type of command. They are three ways of handling and declaring commands.
You can also prevent reduce duplicate code by simply declaring functions. Nonetheless, it allows you to have non-hardcoded description and usage more easily.
To register commands via your plugin code, you can do PHP: public function onEnable(){$this->getServer()->getCommandMap()->register("mycommand", new MyCommand($this));}//"mycommand" should be replaced as your command label/name//You should also create a class for the command handling what is does, in this case the class is named "MyCommand". You can also register commands normally in the plugin.yml. However, if your plugin contains a numerous amount of commands, this is not recommended. EssentialsPE being a plugin which has an immense command count handles them this way.