Last active
December 14, 2015 11:49
-
-
Save Omattyao/5081655 to your computer and use it in GitHub Desktop.
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 | |
/* | |
__PocketMine Plugin__ | |
name=PrivateAreaProtector | |
version=0.0.1 | |
author=Omattyao | |
apiversion=2 | |
class=scPrivateArea | |
*/ | |
class scPrivateArea extends scClass{ | |
private $config, $path; | |
public function init() { | |
$this->path = $this->sc->createConfig($this, array()); | |
$this->config = $this->api->plugin->readYAML($this->path."config.yml"); | |
$this->sc->register("protect", "Protects the area for you.", array($this, "commandH")); | |
$this->sc->register("unprotect", "Unprotects the area for you.", array($this, "commandH")); | |
$this->api->addHandler("player.block.break", array($this, "handle"), 15); | |
$this->api->addHandler("player.block.place", array($this, "handle"), 15); | |
} | |
public function commandH($cmd, $params, TileEntity $sign, &$option){ | |
$output = ""; | |
$username = $sign->data['creator']; | |
switch($cmd){ | |
case "protect": | |
$pos1 = $this->sc->pos1[$username]; | |
$pos2 = $this->sc->pos2[$username]; | |
if(empty($pos1) or empty($pos2)){ | |
$output .= "Make a selection first.\n"; | |
return false; | |
} | |
$minX = min($pos1[0], $pos2[0]); | |
$maxX = max($pos1[0], $pos2[0]); | |
$minY = min($pos1[1], $pos2[1]); | |
$maxY = max($pos1[1], $pos2[1]); | |
$minZ = min($pos1[2], $pos2[2]); | |
$maxZ = max($pos1[2], $pos2[2]); | |
$max = array($maxX, $maxY, $maxZ); | |
$min = array($minX, $minY, $minZ); | |
$this->config[$username]['protect'] = true; | |
$this->config[$username]['max'] = $max; | |
$this->config[$username]['min'] = $min; | |
$this->api->plugin->writeYAML($this->path."config.yml", $this->config); | |
$output .= "Protected this area ($minX, $minY, $minZ)-($maxX, $maxY, $maxZ)\n"; | |
break; | |
case "unprotect": | |
if ($this->config[$username]['protect'] == false) { | |
$output .= "Your area is already unprotected!\n"; | |
break; | |
} | |
$this->config[$username]['protect'] = false; | |
$this->api->plugin->writeYAML($this->path."config.yml", $this->config); | |
$output .= "Lifted the protect.\n"; | |
break; | |
} | |
return $output; | |
} | |
public function handle(&$data, $event){ | |
switch ($event) { | |
case 'player.block.break': | |
$block = $data['target']; | |
foreach ($this->config as $name => $config) { | |
if ($config['protect'] !== true) { continue; } | |
$x = $block->x; | |
$y = $block->y; | |
$z = $block->z; | |
if ($config['min'][0] <= $x and $x <= $config['max'][0]) { | |
if ($config['min'][1] <= $y and $y <= $config['max'][1]) { | |
if ($config['min'][2] <= $z and $z <= $config['max'][2]) { | |
$protect = true; | |
break; | |
} | |
} | |
} | |
$protect = false; | |
} | |
if ($protect == true) { | |
$this->api->player->get($data['player'])->eventHandler("This is $name's private area.", "server.chat"); | |
$this->api->dhandle("block.change", array( | |
"x" => $x, | |
"y" => $y, | |
"z" => $z, | |
"block" => $block->getID(), | |
"meta" => $block->getMetadata(), | |
"fake" => true, | |
)); | |
} | |
break; | |
case 'player.block.place': | |
$block = $data['block']; | |
foreach ($this->config as $name => $config) { | |
if ($config['protect'] !== true) { continue; } | |
$x = $block->x; | |
$y = $block->y; | |
$z = $block->z; | |
if ($config['min'][0] <= $x and $x <= $config['max'][0]) { | |
if ($config['min'][1] <= $y and $y <= $config['max'][1]) { | |
if ($config['min'][2] <= $z and $z <= $config['max'][2]) { | |
$protect = true; | |
break; | |
} | |
} | |
} | |
$protect = false; | |
} | |
if ($protect == true) { | |
$this->api->player->get($data['player'])->eventHandler("This is $name's private area.", "server.chat"); | |
$this->api->dhandle("block.change", array( | |
"x" => $x, | |
"y" => $y, | |
"z" => $z, | |
"block" => $block->getID(), | |
"meta" => $block->getMetadata(), | |
"fake" => true, | |
)); | |
//$this->api->block->setBlock(new Vector3($x, $y, $z), 0, 0, false); | |
} | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment