To put it simply, the same reason we use any functions in plugins. To save time and make things simpler. If you are going to have to run the same code at many different instances, it is way easier to type that code once, then use $this->my function($args); as often as needed later on. You can create one pretty easily: PHP: /*Keep in mind that you would have a lot more in your function, and you can "return" anything you need. This is just an example. */ public function myFunction(Player $player) { if($player->getName() === "Steve") { return true; } else { return false; } Let's say our plugin is supposed to give a specific player an item. Using the above function, we can check and return easily. PHP: /* At another point in your plugin */if($this->myFunction($player) === true) { $player->getInventory()->addItem(Item::get(322, 0, 1)); $player->sendMessage("Your name is Steve!"); } elseif($this->myFunction($player) === false) { $player->sendMessage("Your name is not Steve"); } Keep in mind that this is NOT a good example. In practice, you can use functions to run annoying math problems without typing it all every time. You can use functions to run code after you have done your checks, unlike in my example. You can return a player's name, their data you may have stored in a config, write data, parse data, etc. Basically, functions are immensely useful.
That's calling a 'custom' function. You can declare a simple function in OOP PHP like this: PHP: public function yourFunctionName(){ // put your code here} Then you can call this function from any reference you have to an object that declares this function: PHP: // assuming we are working from your plugins main class (class extending plugin base)public function onEnable() { $this->yourFunctionName();} You can read more about functions in PHP here. Please refrain from asking PHP questions on these forums, these forums exist to discuss and seek help for PocketMine. Whilst PocketMine is written in PHP it does not mean it's forums should be swamped with PHP questions that have already been answered elsewhere.
you can also declare anonymous functions using something highly similar to Code: $func = function($arg1, $arg2){/*do stuff*/} $func(1,2)