forked from ColinHDev/CPlot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlotPlayerRemoveAsyncEvent.php
57 lines (48 loc) · 1.73 KB
/
PlotPlayerRemoveAsyncEvent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace ColinHDev\CPlot\event;
use ColinHDev\CPlot\plots\Plot;
use ColinHDev\CPlot\plots\PlotPlayer;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
use SOFe\AwaitGenerator\Await;
/**
* This event is called when a {@see PlotPlayer} is removed from a {@see Plot} by a {@see Player}.
*/
class PlotPlayerRemoveAsyncEvent extends PlotAsyncEvent implements Cancellable {
use CancellableTrait;
private PlotPlayer $plotPlayer;
private Player $player;
public function __construct(Plot $plot, PlotPlayer $plotPlayer, Player $player) {
parent::__construct($plot);
$this->plotPlayer = $plotPlayer;
$this->player = $player;
}
/**
* Returns the {@see PlotPlayer} that is being removed from the plot.
*/
public function getPlotPlayer() : PlotPlayer {
return $this->plotPlayer;
}
/**
* Returns the {@see Player} that removes the {@see PlotPlayer} from the plot.
*/
public function getPlayer() : Player {
return $this->player;
}
/**
* @phpstan-return \Generator<mixed, Await::RESOLVE|null|Await::RESOLVE_MULTI|Await::REJECT|Await::ONCE|Await::ALL|Await::RACE|\Generator, mixed, self>
*/
public static function create(Plot $plot, PlotPlayer $plotPlayer, Player $player) : \Generator {
$event = yield from Await::promise(
static function ($onSuccess, $onError) use ($plot, $plotPlayer, $player) : void {
$event = new self($plot, $plotPlayer, $player);
$event->setCallback($onSuccess);
$event->call();
}
);
assert($event instanceof self);
return $event;
}
}