PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
BlockEventHelper.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block\utils;
25
33
39final class BlockEventHelper{
40
41 public static function grow(Block $oldState, Block $newState, ?Player $causingPlayer) : bool{
43 $ev = new BlockGrowEvent($oldState, $newState, $causingPlayer);
44 $ev->call();
45 if($ev->isCancelled()){
46 return false;
47 }
48 $newState = $ev->getNewState();
49 }
50
51 $position = $oldState->getPosition();
52 $position->getWorld()->setBlock($position, $newState);
53 return true;
54 }
55
56 public static function spread(Block $oldState, Block $newState, Block $source) : bool{
58 $ev = new BlockSpreadEvent($oldState, $source, $newState);
59 $ev->call();
60 if($ev->isCancelled()){
61 return false;
62 }
63 $newState = $ev->getNewState();
64 }
65
66 $position = $oldState->getPosition();
67 $position->getWorld()->setBlock($position, $newState);
68 return true;
69 }
70
71 public static function form(Block $oldState, Block $newState, Block $cause) : bool{
73 $ev = new BlockFormEvent($oldState, $newState, $cause);
74 $ev->call();
75 if($ev->isCancelled()){
76 return false;
77 }
78 $newState = $ev->getNewState();
79 }
80
81 $position = $oldState->getPosition();
82 $position->getWorld()->setBlock($position, $newState);
83 return true;
84 }
85
86 public static function melt(Block $oldState, Block $newState) : bool{
88 $ev = new BlockMeltEvent($oldState, $newState);
89 $ev->call();
90 if($ev->isCancelled()){
91 return false;
92 }
93 $newState = $ev->getNewState();
94 }
95
96 $position = $oldState->getPosition();
97 $position->getWorld()->setBlock($position, $newState);
98 return true;
99 }
100
101 public static function die(Block $oldState, Block $newState) : bool{
103 $ev = new BlockDeathEvent($oldState, $newState);
104 $ev->call();
105 if($ev->isCancelled()){
106 return false;
107 }
108 $newState = $ev->getNewState();
109 }
110
111 $position = $oldState->getPosition();
112 $position->getWorld()->setBlock($position, $newState);
113 return true;
114 }
115}
static hasHandlers()
Definition: Event.php:77