What is a Plugin?
Plugins are extensions that add custom functionality to your PocketMine-MP server. They can add new commands, listen to events, create custom game mechanics, and much more.Prerequisites
- Basic PHP knowledge
- A PocketMine-MP server
- A text editor or IDE (PHPStorm, VSCode, etc.)
Plugin Types
PocketMine-MP supports two types of plugins:- Folder plugins - Full-featured plugins with proper structure (recommended)
- Script plugins - Single-file plugins for quick testing only
This guide focuses on folder plugins. Script plugins have limited features and are not recommended for production use.
Creating Your First Plugin
Create your main plugin class
Create
src/MyNamespace/Main.php:src/MyNamespace/Main.php
All plugin main classes must extend
pocketmine\plugin\PluginBase (or implement pocketmine\plugin\Plugin).Plugin Lifecycle Methods
Your plugin has three lifecycle methods you can override:onLoad()
Called when the plugin is loaded, beforeonEnable(). Use this for early initialization.
onEnable()
Called when the plugin is enabled. This is where most initialization happens.onDisable()
Called when the plugin is disabled. Use this for cleanup.Complete Example
Here’s a complete first plugin that announces when players join:Common Methods
These methods are available in your plugin class (viaPluginBase):
| Method | Description | Example |
|---|---|---|
getServer() | Get the Server instance | $this->getServer()->getOnlinePlayers() |
getLogger() | Get the plugin’s logger | $this->getLogger()->info("Message") |
getDataFolder() | Get the plugin’s data folder | $this->getDataFolder() . "data.json" |
getConfig() | Get the plugin’s config | $this->getConfig()->get("setting") |
getScheduler() | Get the task scheduler | $this->getScheduler()->scheduleTask($task) |
saveResource() | Save an embedded resource | $this->saveResource("config.yml") |
Next Steps
Plugin Structure
Learn about plugin.yml and folder organization
Event Handlers
Respond to game events
Commands
Create custom commands
Configuration
Manage plugin settings
Troubleshooting
Plugin not loading
- Check
plugin.ymlsyntax (use a YAML validator) - Ensure the
mainclass exists and namespace matches - Verify file permissions
- Check server logs for error messages
”Class not found” errors
- Verify namespace matches folder structure
- Check spelling of class names
- Ensure
declare(strict_types=1);is at the top of PHP files
Plugin loads but doesn’t work
- Check for errors in server console
- Use
$this->getLogger()->debug()to add debug messages - Verify API version compatibility