mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 22:45:28 +00:00
Cancel unallowed break/place events
This commit is contained in:
parent
470352cd31
commit
c959e14718
@ -44,13 +44,24 @@ class BlockAPI{
|
|||||||
$this->server->addHandler("player.block.action", array($this, "blockAction"), 1);
|
$this->server->addHandler("player.block.action", array($this, "blockAction"), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function cancelAction($block){
|
||||||
|
$this->server->trigger("world.block.change", array(
|
||||||
|
"x" => $block[2][0],
|
||||||
|
"y" => $block[2][1],
|
||||||
|
"z" => $block[2][2],
|
||||||
|
"block" => $block[0],
|
||||||
|
"meta" => $block[1],
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function blockBreak($data, $event){
|
public function blockBreak($data, $event){
|
||||||
if($event !== "player.block.break"){
|
if($event !== "player.block.break"){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
||||||
if(isset(Material::$unbreakable[$target[0]])){
|
if(isset(Material::$unbreakable[$target[0]])){
|
||||||
return false;
|
return $this->cancelAction($target);
|
||||||
}
|
}
|
||||||
$drop = array(
|
$drop = array(
|
||||||
$target[0], //Block
|
$target[0], //Block
|
||||||
@ -247,7 +258,10 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($cancelPlace === true){
|
if($cancelPlace === true){
|
||||||
return false;
|
$this->cancelAction($target);
|
||||||
|
BlockFace::setPosition($data, $data["face"]);
|
||||||
|
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
||||||
|
return $this->cancelAction($target);
|
||||||
}
|
}
|
||||||
|
|
||||||
$replace = false;
|
$replace = false;
|
||||||
@ -275,13 +289,13 @@ class BlockAPI{
|
|||||||
$block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
$block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
||||||
|
|
||||||
if($replace === false and !isset(Material::$replaceable[$block[0]])){
|
if($replace === false and !isset(Material::$replaceable[$block[0]])){
|
||||||
return false;
|
return $this->cancelAction($block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset(Material::$placeable[$data["block"]])){
|
if(isset(Material::$placeable[$data["block"]])){
|
||||||
$data["block"] = Material::$placeable[$data["block"]] === true ? $data["block"]:Material::$placeable[$data["block"]];
|
$data["block"] = Material::$placeable[$data["block"]] === true ? $data["block"]:Material::$placeable[$data["block"]];
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return $this->cancelAction($block);
|
||||||
}
|
}
|
||||||
|
|
||||||
$direction = $this->server->api->entity->get($data["eid"])->getDirection();
|
$direction = $this->server->api->entity->get($data["eid"])->getDirection();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user