Introduction
PocketMine-MP is server software for Minecraft: Bedrock Edition, downloaded in PHP. This tutorial walks you through creating a plugin for PocketMine 5.0.0 and later versions.
Preparation
Condition
- Knowledge of PHP basics
- Can be entered using (can be a text editor such as VS Code, Sublime Text, etc.)
- PocketMine-MP Server 5.0.0 or higher
- Composer ( untuk PHP)
PocketMine-MP installation
- Download the last version of PocketMine-MP from there Official Website.
- Follow the instructions to install PocketMine in your operating system.
Basic Plugin Structure
A PocketMine-MP plugin consisting of various archives, but the most important is plugin.yml, which describes the plugin, and a PHP archive containing p logic.
Carpet Structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyFirstPlugin/ | |
├── src/ | |
│ └── MyFirstPlugin/ | |
│ └── Main.php | |
└── plugin.yml |
Primer Plugin
Archive plugin.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: MyFirstPlugin | |
icon: icon.png | |
main: MyFirstPlugin\Main | |
version: 1.0.0 | |
api: 5.0.0 | |
author: TuNombre | |
description: Mi primer plugin para PocketMine-MP 5.0.0 |
Archive Main.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyFirstPlugin; | |
use pocketmine\plugin\PluginBase; | |
class Main extends PluginBase { | |
public function onEnable(): void { | |
$this->getLogger()->info("¡Hola, mundo! Mi primer plugin ha sido habilitado."); | |
} | |
} |
Command Personalization
To add personalized commands, you must specify them plugin.yml and create logic in PHP archive.
Modification plugin.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commands: | |
hello: | |
description: Saluda al jugador | |
usage: "/hello" |
Modification Main.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyFirstPlugin; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\command\Command; | |
use pocketmine\command\CommandSender; | |
use pocketmine\player\Player; | |
class Main extends PluginBase { | |
public function onEnable(): void { | |
$this->getLogger()->info("¡Hola, mundo! Mi primer plugin ha sido habilitado."); | |
} | |
public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool { | |
if ($command->getName() === "hello") { | |
if ($sender instanceof Player) { | |
$sender->sendMessage("¡Hola, " . $sender->getName() . "!"); | |
return true; | |
} else { | |
$sender->sendMessage("Este comando solo puede ser usado en el juego."); | |
return false; | |
} | |
} | |
return false; | |
} | |
} |
Events and Listener
These events allow the plugin to customize actions on the server.
Example: Events and Listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyFirstPlugin; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\event\Listener; | |
use pocketmine\event\player\PlayerJoinEvent; | |
class Main extends PluginBase implements Listener { | |
public function onEnable(): void { | |
$this->getLogger()->info("¡Hola, mundo! Mi primer plugin ha sido habilitado."); | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
} | |
public function onPlayerJoin(PlayerJoinEvent $event): void { | |
$player = $event->getPlayer(); | |
$player->sendMessage("¡Bienvenido, " . $player->getName() . " al servidor!"); | |
} | |
} |
Plugin Configuration
To allow plugin configuration, you can create an archive config.yml.
Archive config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mensaje_bienvenida: "¡Bienvenido al servidor, %player%!" |
Modification Main.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyFirstPlugin; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\event\Listener; | |
use pocketmine\event\player\PlayerJoinEvent; | |
class Main extends PluginBase implements Listener { | |
public function onEnable(): void { | |
$this->saveDefaultConfig(); | |
$this->getLogger()->info("¡Hola, mundo! Mi primer plugin ha sido habilitado."); | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
} | |
public function onPlayerJoin(PlayerJoinEvent $event): void { | |
$player = $event->getPlayer(); | |
$message = str_replace("%player%", $player->getName(), $this->getConfig()->get("mensaje_bienvenida")); | |
$player->sendMessage($message); | |
} | |
} |
Most Important Part
- Starting the PocketMine-MP server.
- Organize the plugins you entered into the list of loaded plugins.
- Run the server to verify who did it.
Publishing plugins
- Make sure your plugin is well documented.
- Put the plugin into a public repository such as GitHub.
- Share your plugins in the PocketMin community.