mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Cancel PlayerInteractEvent automatically on left-click block when spawn protection is triggered
This commit is contained in:
parent
716c1f29b4
commit
6daa0135d5
@ -2623,13 +2623,19 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
if($this->lastBreak !== PHP_INT_MAX or $pos->distanceSquared($this) > 10000){
|
||||
break;
|
||||
}
|
||||
|
||||
$target = $this->level->getBlock($pos);
|
||||
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK);
|
||||
if(!$this->level->checkSpawnProtection($this, $target)){
|
||||
$ev->setCancelled();
|
||||
}
|
||||
|
||||
$this->getServer()->getPluginManager()->callEvent($ev);
|
||||
if($ev->isCancelled()){
|
||||
$this->inventory->sendHeldItem($this);
|
||||
break;
|
||||
}
|
||||
|
||||
$block = $target->getSide($packet->face);
|
||||
if($block->getId() === Block::FIRE){
|
||||
$this->level->setBlock($block, BlockFactory::get(Block::AIR));
|
||||
|
@ -1585,7 +1585,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
*
|
||||
* @return bool false if spawn protection cancelled the action, true if not.
|
||||
*/
|
||||
protected function checkSpawnProtection(Player $player, Vector3 $vector) : bool{
|
||||
public function checkSpawnProtection(Player $player, Vector3 $vector) : bool{
|
||||
if(!$player->hasPermission("pocketmine.spawnprotect.bypass") and ($distance = $this->server->getSpawnRadius()) > -1){
|
||||
$t = new Vector2($vector->x, $vector->z);
|
||||
$s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
|
||||
|
Loading…
x
Reference in New Issue
Block a user