Plugin examples - randomblink/PocketMine-MP GitHub Wiki
You can use these plugins dropping then on the plugins folder
<?php
/*
__PocketMine Plugin__
name=Reactor As Water
description=Replaces the Nether Reactor with Water
version=0.0.2
author=shoghicp
class=ReactorAsWater
*/
class ReactorAsWater implements Plugin{
private $api;
public function __construct(ServerAPI $api, $server = false){
$this->api = $api;
}
public function init(){
$this->api->addHandler("player.block.action", array($this, "handle"), 15); //Priority higher that API
$this->api->addHandler("player.equipment.change", array($this, "handle"), 15);
}
public function __destruct(){
}
public function handle(&$data, $event){
switch($event){
case "player.equipment.change":
if($data["block"] === 247){
$this->api->player->getByEID($data["eid"])->eventHandler("[ReactorAsWater] Placing water", "server.chat");
$data["block"] = 9;
$data["meta"] = 0;
}
break;
case "player.block.action":
if($data["block"] === 247){ //nether reactor
$data["block"] = 9; //water source
$data["meta"] = 0;
}
break;
}
}
}
<?php
/*
__PocketMine Plugin__
name=SpawnChanger
description=Change the spawn coordinates, or make it default for all players!
version=0.0.1
author=shoghicp
class=SpawnChanger
*/
class SpawnChanger implements Plugin{
private $api, $config, $path;
public function __construct(ServerAPI $api, $server = false){
$this->api = $api;
}
public function init(){
$spawn = $this->api->level->getSpawn();
$this->path = $this->api->plugin->createConfig($this, array(
"spawnX" => $spawn["x"],
"spawnY" => $spawn["y"],
"spawnZ" => $spawn["z"],
"custom-spawn" => false,
"force-spawn" => false,
));
$this->config = $this->api->plugin->readYAML($this->path."config.yml");
if($this->config["custom-spawn"] === false){
$this->config["spawnX"] = $spawn["x"];
$this->config["spawnY"] = $spawn["y"];
$this->config["spawnZ"] = $spawn["z"];
$this->api->plugin->writeYAML($this->path."config.yml", $this->config);
}
$this->api->addHandler("api.player.offline.get", array($this, "handle"), 15);
$this->api->console->register("spawnchanger", "SpawnChanger init point managing", array($this, "command"));
$this->api->console->register("spawn", "Teleports to spawn", array($this, "command"));
}
public function __destruct(){
}
public function command($cmd, $args){
switch($cmd){
case "spawnchanger":
switch(strtolower(array_shift($args))){
case "force":
$l = array_shift($args);
if($l != "0" and $l != "1"){
console("[SpawnChanger] Usage: /spawnchanger force <1 | 0>");
}else{
$this->config["force-spawn"] = $l == "0" ? false:true;
if($this->config["force-spawn"] === true){
console("[SpawnChanger] Forced spawn point");
}else{
console("[SpawnChanger] Freed pawn point");
}
$this->api->plugin->writeYAML($this->path."config.yml", $this->config);
}
break;
case "set":
$z = array_pop($args);
$y = array_pop($args);
$x = array_pop($args);
if($x === null or $y === null or $z === null){
console("[SpawnChanger] Usage: /spawnchanger set <x> <y> <z>");
}else{
$this->config["custom-spawn"] = true;
$this->config["spawnX"] = (float) $x;
$this->config["spawnY"] = (float) $y;
$this->config["spawnZ"] = (float) $z;
console("[SpawnChanger] Spawn point set at X ".$this->config["spawnX"]." Y ".$this->config["spawnY"]." Z ".$this->config["spawnZ"]);
$this->api->plugin->writeYAML($this->path."config.yml", $this->config);
}
break;
default:
console("[SpawnChanger] Always spawn player in spawn point: /spawnchanger force <1 | 0>");
console("[SpawnChanger] Set the spawn point: /spawnchanger set <x> <y> <z>");
break;
}
break;
case "spawn":
if($this->api->player->tppos(implode(" ", $args), $this->config["spawnX"], $this->config["spawnY"], $this->config["spawnZ"]) !== false){
console("[SpawnChanger] Teleported to spawn!");
}else{
console("[SpawnChanger] Usage: /spawn <player>");
}
break;
}
}
public function handle(&$data, $event){
switch($event){
case "api.player.offline.get":
if($this->config["force-spawn"] === true){
$data["spawn"]["x"] = $this->config["spawnX"];
$data["spawn"]["y"] = $this->config["spawnY"];
$data["spawn"]["z"] = $this->config["spawnZ"];
}
break;
}
}
}
<?php
/*
__PocketMine Plugin__
name=TreeCapitator
description=Break trees faster breaking the lowest trunk
version=0.0.1
author=shoghicp
class=TreeCapitator
*/
class TreeCapitator implements Plugin{
private $api;
public function __construct(ServerAPI $api, $server = false){
$this->api = $api;
}
public function init(){
$this->api->addHandler("player.block.break", array($this, "handle"), 2);
}
public function __destruct(){
}
public function handle(&$data, $event){
switch($event){
case "player.block.break":
$block = $this->api->level->getBlock($data["x"], $data["y"], $data["z"]);
if($block[0] === 17){
$down = $this->api->level->getBlockFace($block, 0);
if($down[0] !== 17){
for($y = $block[2][1]; $y <= ($block[2][1] + 10); ++$y){
for($x = $block[2][0] - 4; $x <= ($block[2][0] + 4); ++$x){
for($z = $block[2][2] - 4; $z <= ($block[2][2] + 4); ++$z){
$b = $this->api->level->getBlock($x, $y, $z);
if($b[0] === 17 or $b[0] === 18){
$this->api->trigger("player.block.break", array(
"x" => $x,
"y" => $y,
"z" => $z,
"eid" => $data["eid"],
));
}
}
}
}
$this->api->block->drop($block[2][0], $block[2][1], $block[2][2], $block[0], $block[1], $y - $block[2][1] + 1);
$this->api->trigger("server.chat", $this->api->player->getByEID($data["eid"])->username." used TreeCapitator");
return false;
}
}
break;
}
}
}