hey, I want to know how to seperate my command in a diffrent class, I just want to do it to be more organized because this plugin is of a “big size”. I checked search found multiple threads but noone clearly explained how to seperate a command from main class. Thanks hopefully you guys can help me !
Here is my way: 1. Create an abstract class that extend Command class and implement PluginIdentifiableCommand class. PHP: abstract class CommandBase extends Command implements PluginIdentifiableCommand { /** * CommandBase constructor. * * @param string $name * @param string $description * @param null $usageMessage * @param array $aliases */ public function __construct($name, $description = "", $usageMessage = null, $aliases = []) { parent::__construct($name, $description, $usageMessage, $aliases); } /** * NOTE: You must implement this function. * @return Plugin */ public function getPlugin() : Plugin { return Loader::getInstance(); // Loader is my main class. }} 2. Create separated command classes and extend CommandBase (your abstract class, on point number 1). PHP: class MyFirstCommand extends CommandBase{ public function __construct() { parent::__construct("firstcommand", "My first command!", "Usage: /fcmd", ["fcmd"]); } public function execute(CommandSender $sender, string $commandLabel, array $args) { // a condition that will be executed after player run "/firstcommand" or any aliases. // return mixed }} 3. Don't forget to register your commands to server. Do it in your main class. PHP: $this->getServer()->getCommandMap()->registerAll("YourPluginNameShouldBeHere", [new MyFirstCommand()]); And done! I think its really complicated if you are beginner, there are also many alternatives way and more simple than this one. I used it for big plugin.