mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
EnchantingTableInventoryWindow: cleanup weakref mess
this really needs a shorter name
This commit is contained in:
parent
edf4e9d333
commit
d69d8d6217
@ -43,8 +43,7 @@ final class EnchantingTableInventoryWindow extends BlockInventoryWindow{
|
|||||||
/** @var EnchantingOption[] $options */
|
/** @var EnchantingOption[] $options */
|
||||||
private array $options = [];
|
private array $options = [];
|
||||||
|
|
||||||
/** @phpstan-var \WeakReference<InventoryListener> */
|
private InventoryListener $listener;
|
||||||
private \WeakReference $listener;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Player $viewer,
|
Player $viewer,
|
||||||
@ -54,7 +53,7 @@ final class EnchantingTableInventoryWindow extends BlockInventoryWindow{
|
|||||||
|
|
||||||
/** @phpstan-var \WeakReference<self> $weakThis */
|
/** @phpstan-var \WeakReference<self> $weakThis */
|
||||||
$weakThis = \WeakReference::create($this);
|
$weakThis = \WeakReference::create($this);
|
||||||
$listener = new CallbackInventoryListener(
|
$this->listener = new CallbackInventoryListener(
|
||||||
onSlotChange: static function(Inventory $_, int $slot) use ($weakThis) : void{ //remaining params unneeded
|
onSlotChange: static function(Inventory $_, int $slot) use ($weakThis) : void{ //remaining params unneeded
|
||||||
if($slot === self::SLOT_INPUT && ($strongThis = $weakThis->get()) !== null){
|
if($slot === self::SLOT_INPUT && ($strongThis = $weakThis->get()) !== null){
|
||||||
$strongThis->regenerateOptions();
|
$strongThis->regenerateOptions();
|
||||||
@ -66,16 +65,11 @@ final class EnchantingTableInventoryWindow extends BlockInventoryWindow{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$this->inventory->getListeners()->add($listener);
|
$this->inventory->getListeners()->add($this->listener);
|
||||||
|
|
||||||
$this->listener = \WeakReference::create($listener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct(){
|
public function __destruct(){
|
||||||
$listener = $this->listener->get();
|
$this->inventory->getListeners()->remove($this->listener);
|
||||||
if($listener !== null){
|
|
||||||
$this->inventory->getListeners()->remove($listener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function regenerateOptions() : void{
|
private function regenerateOptions() : void{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user