diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index abace213d..4543e9c0a 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -156,7 +156,7 @@ use function microtime; use function min; use function preg_match; use function round; -use function spl_object_hash; +use function spl_object_id; use function strlen; use function strpos; use function strtolower; @@ -3247,7 +3247,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return int */ public function getWindowId(Inventory $inventory) : int{ - return $this->windows[spl_object_hash($inventory)] ?? ContainerIds::NONE; + return $this->windows[spl_object_id($inventory)] ?? ContainerIds::NONE; } /** @@ -3297,7 +3297,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $this->windowIndex[$cnt] = $inventory; - $this->windows[spl_object_hash($inventory)] = $cnt; + $this->windows[spl_object_id($inventory)] = $cnt; if($inventory->open($this)){ if($isPermanent){ $this->permanentWindows[$cnt] = true; @@ -3319,7 +3319,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @throws \InvalidArgumentException if trying to remove a fixed inventory window without the `force` parameter as true */ public function removeWindow(Inventory $inventory, bool $force = false){ - $id = $this->windows[$hash = spl_object_hash($inventory)] ?? null; + $id = $this->windows[$hash = spl_object_id($inventory)] ?? null; if($id !== null and !$force and isset($this->permanentWindows[$id])){ throw new \InvalidArgumentException("Cannot remove fixed window $id (" . get_class($inventory) . ") from " . $this->getName()); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index d60c05f06..071606e28 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -134,7 +134,6 @@ use function register_shutdown_function; use function rename; use function round; use function sleep; -use function spl_object_hash; use function spl_object_id; use function sprintf; use function str_repeat; @@ -1436,7 +1435,7 @@ class Server{ foreach(explode(";", $permissions) as $permission){ foreach(PermissionManager::getInstance()->getPermissionSubscriptions($permission) as $permissible){ if($permissible instanceof CommandSender and $permissible->hasPermission($permission)){ - $recipients[spl_object_hash($permissible)] = $permissible; // do not send messages directly, or some might be repeated + $recipients[spl_object_id($permissible)] = $permissible; // do not send messages directly, or some might be repeated } } } @@ -1900,14 +1899,14 @@ class Server{ } public function addPlayer(Player $player){ - $this->players[spl_object_hash($player)] = $player; + $this->players[spl_object_id($player)] = $player; } /** * @param Player $player */ public function removePlayer(Player $player){ - unset($this->players[spl_object_hash($player)]); + unset($this->players[spl_object_id($player)]); } public function addOnlinePlayer(Player $player){ diff --git a/src/pocketmine/ThreadManager.php b/src/pocketmine/ThreadManager.php index 3694d6c98..a4bbe2a57 100644 --- a/src/pocketmine/ThreadManager.php +++ b/src/pocketmine/ThreadManager.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine; -use function spl_object_hash; +use function spl_object_id; class ThreadManager extends \Volatile{ @@ -46,7 +46,7 @@ class ThreadManager extends \Volatile{ */ public function add($thread){ if($thread instanceof Thread or $thread instanceof Worker){ - $this->{spl_object_hash($thread)} = $thread; + $this->{spl_object_id($thread)} = $thread; } } @@ -55,7 +55,7 @@ class ThreadManager extends \Volatile{ */ public function remove($thread){ if($thread instanceof Thread or $thread instanceof Worker){ - unset($this->{spl_object_hash($thread)}); + unset($this->{spl_object_id($thread)}); } } diff --git a/src/pocketmine/event/HandlerList.php b/src/pocketmine/event/HandlerList.php index 8b833a4c3..60b3d4bac 100644 --- a/src/pocketmine/event/HandlerList.php +++ b/src/pocketmine/event/HandlerList.php @@ -28,7 +28,7 @@ use pocketmine\plugin\RegisteredListener; use pocketmine\utils\Utils; use function array_fill_keys; use function in_array; -use function spl_object_hash; +use function spl_object_id; class HandlerList{ /** @@ -120,10 +120,10 @@ class HandlerList{ if(!in_array($listener->getPriority(), EventPriority::ALL, true)){ return; } - if(isset($this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)])){ + if(isset($this->handlerSlots[$listener->getPriority()][spl_object_id($listener)])){ throw new \InvalidStateException("This listener is already registered to priority {$listener->getPriority()} of event {$this->class}"); } - $this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)] = $listener; + $this->handlerSlots[$listener->getPriority()][spl_object_id($listener)] = $listener; } /** @@ -150,8 +150,8 @@ class HandlerList{ } } }elseif($object instanceof RegisteredListener){ - if(isset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)])){ - unset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)]); + if(isset($this->handlerSlots[$object->getPriority()][spl_object_id($object)])){ + unset($this->handlerSlots[$object->getPriority()][spl_object_id($object)]); } } } diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index ce015b3e2..2be0a0ef1 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -37,7 +37,7 @@ use function array_slice; use function count; use function max; use function min; -use function spl_object_hash; +use function spl_object_id; abstract class BaseInventory implements Inventory{ @@ -420,11 +420,11 @@ abstract class BaseInventory implements Inventory{ } public function onOpen(Player $who) : void{ - $this->viewers[spl_object_hash($who)] = $who; + $this->viewers[spl_object_id($who)] = $who; } public function onClose(Player $who) : void{ - unset($this->viewers[spl_object_hash($who)]); + unset($this->viewers[spl_object_id($who)]); } public function onSlotChange(int $index, Item $before, bool $send) : void{ diff --git a/src/pocketmine/inventory/transaction/InventoryTransaction.php b/src/pocketmine/inventory/transaction/InventoryTransaction.php index 55219fac6..e74bfa603 100644 --- a/src/pocketmine/inventory/transaction/InventoryTransaction.php +++ b/src/pocketmine/inventory/transaction/InventoryTransaction.php @@ -34,6 +34,7 @@ use function count; use function get_class; use function min; use function spl_object_hash; +use function spl_object_id; /** * This InventoryTransaction only allows doing Transaction between one / two inventories @@ -85,7 +86,7 @@ class InventoryTransaction{ * @param InventoryAction $action */ public function addAction(InventoryAction $action) : void{ - if(!isset($this->actions[$hash = spl_object_hash($action)])){ + if(!isset($this->actions[$hash = spl_object_id($action)])){ $this->actions[$hash] = $action; $action->onAddToTransaction($this); }else{ @@ -100,7 +101,7 @@ class InventoryTransaction{ * @param Inventory $inventory */ public function addInventory(Inventory $inventory) : void{ - if(!isset($this->inventories[$hash = spl_object_hash($inventory)])){ + if(!isset($this->inventories[$hash = spl_object_id($inventory)])){ $this->inventories[$hash] = $inventory; } } @@ -188,7 +189,7 @@ class InventoryTransaction{ } foreach($list as $action){ - unset($this->actions[spl_object_hash($action)]); + unset($this->actions[spl_object_id($action)]); } if(!$targetItem->equalsExact($sourceItem)){ diff --git a/src/pocketmine/inventory/transaction/action/SlotChangeAction.php b/src/pocketmine/inventory/transaction/action/SlotChangeAction.php index 8b2a1812c..3bc826548 100644 --- a/src/pocketmine/inventory/transaction/action/SlotChangeAction.php +++ b/src/pocketmine/inventory/transaction/action/SlotChangeAction.php @@ -27,7 +27,7 @@ use pocketmine\inventory\Inventory; use pocketmine\inventory\transaction\InventoryTransaction; use pocketmine\item\Item; use pocketmine\Player; -use function spl_object_hash; +use function spl_object_id; /** * Represents an action causing a change in an inventory slot. @@ -110,7 +110,7 @@ class SlotChangeAction extends InventoryAction{ */ public function onExecuteSuccess(Player $source) : void{ $viewers = $this->inventory->getViewers(); - unset($viewers[spl_object_hash($source)]); + unset($viewers[spl_object_id($source)]); $this->inventory->sendSlot($this->inventorySlot, $viewers); } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index a975caf25..60d0961ba 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -30,7 +30,7 @@ use pocketmine\event\server\NetworkInterfaceRegisterEvent; use pocketmine\event\server\NetworkInterfaceUnregisterEvent; use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\protocol\PacketPool; -use function spl_object_hash; +use function spl_object_id; class Network{ /** @var NetworkInterface[] */ @@ -105,7 +105,7 @@ class Network{ $ev->call(); if(!$ev->isCancelled()){ $interface->start(); - $this->interfaces[$hash = spl_object_hash($interface)] = $interface; + $this->interfaces[$hash = spl_object_id($interface)] = $interface; if($interface instanceof AdvancedNetworkInterface){ $this->advancedInterfaces[$hash] = $interface; $interface->setNetwork($this); @@ -119,7 +119,7 @@ class Network{ */ public function unregisterInterface(NetworkInterface $interface) : void{ (new NetworkInterfaceUnregisterEvent($interface))->call(); - unset($this->interfaces[$hash = spl_object_hash($interface)], $this->advancedInterfaces[$hash]); + unset($this->interfaces[$hash = spl_object_id($interface)], $this->advancedInterfaces[$hash]); } /** @@ -183,6 +183,6 @@ class Network{ } public function scheduleSessionTick(NetworkSession $session) : void{ - $this->updateSessions[spl_object_hash($session)] = $session; + $this->updateSessions[spl_object_id($session)] = $session; } } diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 962c3643c..17d073b84 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -42,7 +42,7 @@ use function addcslashes; use function count; use function implode; use function rtrim; -use function spl_object_hash; +use function spl_object_id; use function substr; use function unserialize; use const PTHREADS_INHERIT_CONSTANTS; @@ -121,14 +121,14 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ public function closeSession(string $identifier, string $reason) : void{ if(isset($this->sessions[$identifier])){ $session = $this->sessions[$identifier]; - unset($this->identifiers[spl_object_hash($session)]); + unset($this->identifiers[spl_object_id($session)]); unset($this->sessions[$identifier]); $session->onClientDisconnect($reason); } } public function close(NetworkSession $session, string $reason = "unknown reason") : void{ - if(isset($this->identifiers[$h = spl_object_hash($session)])){ + if(isset($this->identifiers[$h = spl_object_id($session)])){ unset($this->sessions[$this->identifiers[$h]]); $this->interface->closeSession($this->identifiers[$h], $reason); unset($this->identifiers[$h]); @@ -143,7 +143,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ public function openSession(string $identifier, string $address, int $port, int $clientID) : void{ $session = new NetworkSession($this->server, $this, $address, $port); $this->sessions[$identifier] = $session; - $this->identifiers[spl_object_hash($session)] = $identifier; + $this->identifiers[spl_object_id($session)] = $identifier; } public function handleEncapsulated(string $identifier, EncapsulatedPacket $packet, int $flags) : void{ @@ -227,7 +227,7 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ } public function putPacket(NetworkSession $session, string $payload, bool $immediate = true) : void{ - if(isset($this->identifiers[$h = spl_object_hash($session)])){ + if(isset($this->identifiers[$h = spl_object_id($session)])){ $identifier = $this->identifiers[$h]; $pk = new EncapsulatedPacket(); diff --git a/src/pocketmine/permission/PermissibleBase.php b/src/pocketmine/permission/PermissibleBase.php index 32fd74d82..809d62c75 100644 --- a/src/pocketmine/permission/PermissibleBase.php +++ b/src/pocketmine/permission/PermissibleBase.php @@ -26,7 +26,7 @@ namespace pocketmine\permission; use pocketmine\plugin\Plugin; use pocketmine\plugin\PluginException; use pocketmine\timings\Timings; -use function spl_object_hash; +use function spl_object_id; class PermissibleBase implements Permissible{ /** @var ServerOperator */ @@ -117,7 +117,7 @@ class PermissibleBase implements Permissible{ } $result = new PermissionAttachment($plugin, $this->parent ?? $this); - $this->attachments[spl_object_hash($result)] = $result; + $this->attachments[spl_object_id($result)] = $result; if($name !== null and $value !== null){ $result->setPermission($name, $value); } @@ -131,8 +131,8 @@ class PermissibleBase implements Permissible{ * @param PermissionAttachment $attachment */ public function removeAttachment(PermissionAttachment $attachment){ - if(isset($this->attachments[spl_object_hash($attachment)])){ - unset($this->attachments[spl_object_hash($attachment)]); + if(isset($this->attachments[spl_object_id($attachment)])){ + unset($this->attachments[spl_object_id($attachment)]); if(($ex = $attachment->getRemovalCallback()) !== null){ $ex->attachmentRemoved($attachment); } diff --git a/src/pocketmine/permission/PermissionManager.php b/src/pocketmine/permission/PermissionManager.php index 02d7d9664..6cd1d8ab1 100644 --- a/src/pocketmine/permission/PermissionManager.php +++ b/src/pocketmine/permission/PermissionManager.php @@ -25,7 +25,7 @@ namespace pocketmine\permission; use pocketmine\timings\Timings; use function count; -use function spl_object_hash; +use function spl_object_id; class PermissionManager{ /** @var PermissionManager|null */ @@ -146,7 +146,7 @@ class PermissionManager{ if(!isset($this->permSubs[$permission])){ $this->permSubs[$permission] = []; } - $this->permSubs[$permission][spl_object_hash($permissible)] = $permissible; + $this->permSubs[$permission][spl_object_id($permissible)] = $permissible; } /** @@ -155,7 +155,7 @@ class PermissionManager{ */ public function unsubscribeFromPermission(string $permission, Permissible $permissible){ if(isset($this->permSubs[$permission])){ - unset($this->permSubs[$permission][spl_object_hash($permissible)]); + unset($this->permSubs[$permission][spl_object_id($permissible)]); if(count($this->permSubs[$permission]) === 0){ unset($this->permSubs[$permission]); } @@ -167,7 +167,7 @@ class PermissionManager{ */ public function unsubscribeFromAllPermissions(Permissible $permissible) : void{ foreach($this->permSubs as $permission => &$subs){ - unset($subs[spl_object_hash($permissible)]); + unset($subs[spl_object_id($permissible)]); if(empty($subs)){ unset($this->permSubs[$permission]); } @@ -189,9 +189,9 @@ class PermissionManager{ */ public function subscribeToDefaultPerms(bool $op, Permissible $permissible){ if($op){ - $this->defSubsOp[spl_object_hash($permissible)] = $permissible; + $this->defSubsOp[spl_object_id($permissible)] = $permissible; }else{ - $this->defSubs[spl_object_hash($permissible)] = $permissible; + $this->defSubs[spl_object_id($permissible)] = $permissible; } } @@ -201,9 +201,9 @@ class PermissionManager{ */ public function unsubscribeFromDefaultPerms(bool $op, Permissible $permissible){ if($op){ - unset($this->defSubsOp[spl_object_hash($permissible)]); + unset($this->defSubsOp[spl_object_id($permissible)]); }else{ - unset($this->defSubs[spl_object_hash($permissible)]); + unset($this->defSubs[spl_object_id($permissible)]); } } diff --git a/src/pocketmine/plugin/PluginLogger.php b/src/pocketmine/plugin/PluginLogger.php index 585d9da39..944533dcd 100644 --- a/src/pocketmine/plugin/PluginLogger.php +++ b/src/pocketmine/plugin/PluginLogger.php @@ -25,7 +25,7 @@ namespace pocketmine\plugin; use LogLevel; use pocketmine\Server; -use function spl_object_hash; +use function spl_object_id; class PluginLogger implements \AttachableLogger{ @@ -35,11 +35,11 @@ class PluginLogger implements \AttachableLogger{ private $attachments = []; public function addAttachment(\LoggerAttachment $attachment){ - $this->attachments[spl_object_hash($attachment)] = $attachment; + $this->attachments[spl_object_id($attachment)] = $attachment; } public function removeAttachment(\LoggerAttachment $attachment){ - unset($this->attachments[spl_object_hash($attachment)]); + unset($this->attachments[spl_object_id($attachment)]); } public function removeAttachments(){ diff --git a/src/pocketmine/scheduler/AsyncPool.php b/src/pocketmine/scheduler/AsyncPool.php index f6eec52e7..60e1bcac5 100644 --- a/src/pocketmine/scheduler/AsyncPool.php +++ b/src/pocketmine/scheduler/AsyncPool.php @@ -27,7 +27,7 @@ use pocketmine\utils\Utils; use function array_keys; use function assert; use function count; -use function spl_object_hash; +use function spl_object_id; use function time; use const PHP_INT_MAX; use const PTHREADS_INHERIT_CONSTANTS; @@ -97,7 +97,7 @@ class AsyncPool{ */ public function addWorkerStartHook(\Closure $hook) : void{ Utils::validateCallableSignature(function(int $worker) : void{}, $hook); - $this->workerStartHooks[spl_object_hash($hook)] = $hook; + $this->workerStartHooks[spl_object_id($hook)] = $hook; foreach($this->workers as $i => $worker){ $hook($i); } @@ -109,7 +109,7 @@ class AsyncPool{ * @param \Closure $hook */ public function removeWorkerStartHook(\Closure $hook) : void{ - unset($this->workerStartHooks[spl_object_hash($hook)]); + unset($this->workerStartHooks[spl_object_id($hook)]); } /** diff --git a/src/pocketmine/scheduler/AsyncTask.php b/src/pocketmine/scheduler/AsyncTask.php index af78f29bb..38f6429c6 100644 --- a/src/pocketmine/scheduler/AsyncTask.php +++ b/src/pocketmine/scheduler/AsyncTask.php @@ -25,7 +25,7 @@ namespace pocketmine\scheduler; use function is_scalar; use function serialize; -use function spl_object_hash; +use function spl_object_id; use function unserialize; /** @@ -256,7 +256,7 @@ abstract class AsyncTask extends \Threaded{ */ self::$threadLocalStorage = new \ArrayObject(); } - self::$threadLocalStorage[spl_object_hash($this)] = $complexData; + self::$threadLocalStorage[spl_object_id($this)] = $complexData; } /** @@ -270,16 +270,16 @@ abstract class AsyncTask extends \Threaded{ * @throws \InvalidArgumentException if no data were stored by this AsyncTask instance. */ protected function fetchLocal(){ - if(self::$threadLocalStorage === null or !isset(self::$threadLocalStorage[spl_object_hash($this)])){ + if(self::$threadLocalStorage === null or !isset(self::$threadLocalStorage[spl_object_id($this)])){ throw new \InvalidArgumentException("No matching thread-local data found on this thread"); } - return self::$threadLocalStorage[spl_object_hash($this)]; + return self::$threadLocalStorage[spl_object_id($this)]; } final public function __destruct(){ $this->reallyDestruct(); - if(self::$threadLocalStorage !== null and isset(self::$threadLocalStorage[$h = spl_object_hash($this)])){ + if(self::$threadLocalStorage !== null and isset(self::$threadLocalStorage[$h = spl_object_id($this)])){ unset(self::$threadLocalStorage[$h]); if(self::$threadLocalStorage->count() === 0){ self::$threadLocalStorage = null; diff --git a/src/pocketmine/timings/TimingsHandler.php b/src/pocketmine/timings/TimingsHandler.php index 4667cb231..102f5466c 100644 --- a/src/pocketmine/timings/TimingsHandler.php +++ b/src/pocketmine/timings/TimingsHandler.php @@ -29,7 +29,7 @@ use function count; use function fwrite; use function microtime; use function round; -use function spl_object_hash; +use function spl_object_id; use const PHP_EOL; class TimingsHandler{ @@ -154,7 +154,7 @@ class TimingsHandler{ $this->name = $name; $this->parent = $parent; - self::$HANDLERS[spl_object_hash($this)] = $this; + self::$HANDLERS[spl_object_id($this)] = $this; } public function startTiming(){ @@ -195,6 +195,6 @@ class TimingsHandler{ } public function remove(){ - unset(self::$HANDLERS[spl_object_hash($this)]); + unset(self::$HANDLERS[spl_object_id($this)]); } }