Plugin Support - randomblink/PocketMine-MP GitHub Wiki

PocketMine-MP has a PluginAPI than enables developers to write Plugins for the server. These plugins use PHP as its programming language, and have access to all the API's, or the Server methods itself (not recommended). These plugins are loaded after the server starts.

How to install plugins (video)

###Plugin Repository

A plugin Structure

<?php

/*
__PocketMine Plugin__
name=ExamplePlugin
version=0.0.1
author=shoghicp
class=ExamplePlugin
apiversion=7
*/

class ExamplePlugin implements Plugin{
	private $api;
	public function __construct(ServerAPI $api, $server = false){
		$this->api = $api;
	}
	
	public function init(){
		$this->api->console->register("example", "Example command", array($this, "handleCommand"));
	}
	
	public function __destruct(){
	
	}
	
	public function handleCommand($cmd, $arg){
		switch($cmd){
			case "example":
				console("EXAMPLE!!!");
				break;
		}
	}

}

Header

/*
__PocketMine Plugin__
name=ExamplePlugin
version=0.0.1
author=shoghicp
class=ExamplePlugin
apiversion=7
*/

The header is required. Here you'll define plugin information and loading procedure.

name

  • Required
  • The name of the plugin, can contain spaces.

version

  • Required
  • Version number

description

  • Describes your plugin, only for informative purposes

author

  • Required
  • The author of the plugin

class

  • Required
  • Class Name that is used to init the Plugin

apiversion

  • Required
  • The versions that the plugin has been designed to work for. Example: 7 5,6,7

Main Class

class ExamplePlugin implements Plugin{
	private $api;
	public function __construct(ServerAPI $api, $server = false){
		$this->api = $api;
	}
	
	public function init(){
		$this->api->console->register("example", "Example command", array($this, "handleCommand"));
	}
	
	public function __destruct(){
	
	}
	
	public function handleCommand($cmd, $arg){
		switch($cmd){
			case "example":
				console("EXAMPLE!!!");
				break;
		}
	}

}

The Main class is used to init the Plugin, and it's specified in the header. The class should implement the Plugin Interface