The final directory structure looks like: Code: MyPlugin ├── plugin.yml └── src └── pmmp └── MyPlugin └── Main.php Spoiler: MyPlugin/plugin.yml Code: name: MyPlugin main: pmmp\MyPlugin\Main version: 0.0.1 api: 2.1.0 description: My Plugin author: pmmp commands: hello: description: "Sends 'Hello world!' to the sender" usage: "/hello" Spoiler: MyPlugin/src/pmmp/MyPlugin/Main.php PHP: <?phpnamespace pmmp\MyPlugin;use pocketmine\plugin\PluginBase;use pocketmine\command\Command;use pocketmine\command\CommandSender;class Main extends PluginBase{ public function onCommand(CommandSender $sender, Command $command, $label, array $args){ switch($command->getName()){ case "hello": $sender->sendMessage("Hello world!"); return true; } }}
You only have to register the events if you work with Listeners, they aren't needed for just commands.
It helps, how can I add that a player used the command and it will display their name? Exampe: PianoRalph04 said Hello World!
PHP: $name = $sender->getName();$this->getServer()->broadcastMessage("$name said {whatever}"); If you want custom messages, you can use $args to make it happen
What we really need is a tutorial on how to register commands per file, using the command map. I use it in all my plugins because its just cleaner imo
It is called extending the Command class directly, not registering commands per file. Usually it results in more redundant code rather than cleaner code. You shouldn't use this method if you don't understand why it works anyway. You shouldn't use this method if you think in files rather than thinking in classes.
broadcastMessage is defined. https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Server.php#L1641
Oops, I meant to add getServer... It should be $sender->getLevel()->getServer()->broadcastMessage("message");
Plus, how can I find out where a variable or a function is defined? Do I need to get used how PMMP works?