Use first-class closures in more places

This commit is contained in:
Dylan K. Taylor 2023-07-19 13:56:48 +01:00
parent 537721fe7d
commit 914dd90b3d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
5 changed files with 9 additions and 23 deletions

View File

@ -1009,7 +1009,7 @@ class Server{
$this->playerDataProvider = new DatFilePlayerDataProvider(Path::join($this->dataPath, "players")); $this->playerDataProvider = new DatFilePlayerDataProvider(Path::join($this->dataPath, "players"));
register_shutdown_function([$this, "crashDump"]); register_shutdown_function($this->crashDump(...));
$loadErrorCount = 0; $loadErrorCount = 0;
$this->pluginManager->loadPlugins($this->pluginPath, $loadErrorCount); $this->pluginManager->loadPlugins($this->pluginPath, $loadErrorCount);

View File

@ -116,9 +116,7 @@ class InventoryManager{
$this->addComplex(UIInventorySlotOffset::CURSOR, $this->player->getCursorInventory()); $this->addComplex(UIInventorySlotOffset::CURSOR, $this->player->getCursorInventory());
$this->addComplex(UIInventorySlotOffset::CRAFTING2X2_INPUT, $this->player->getCraftingGrid()); $this->addComplex(UIInventorySlotOffset::CRAFTING2X2_INPUT, $this->player->getCraftingGrid());
$this->player->getInventory()->getHeldItemIndexChangeListeners()->add(function() : void{ $this->player->getInventory()->getHeldItemIndexChangeListeners()->add($this->syncSelectedHotbarSlot(...));
$this->syncSelectedHotbarSlot();
});
} }
private function associateIdWithInventory(int $id, Inventory $inventory) : void{ private function associateIdWithInventory(int $id, Inventory $inventory) : void{

View File

@ -197,7 +197,7 @@ class NetworkSession{
$this->setHandler(new SessionStartPacketHandler( $this->setHandler(new SessionStartPacketHandler(
$this, $this,
fn() => $this->onSessionStartSuccess() $this->onSessionStartSuccess(...)
)); ));
$this->manager->add($this); $this->manager->add($this);
@ -787,9 +787,7 @@ class NetworkSession{
$this->cipher = EncryptionContext::fakeGCM($encryptionKey); $this->cipher = EncryptionContext::fakeGCM($encryptionKey);
$this->setHandler(new HandshakePacketHandler(function() : void{ $this->setHandler(new HandshakePacketHandler($this->onServerLoginSuccess(...)));
$this->onServerLoginSuccess();
}));
$this->logger->debug("Enabled encryption"); $this->logger->debug("Enabled encryption");
})); }));
}else{ }else{
@ -818,9 +816,7 @@ class NetworkSession{
public function notifyTerrainReady() : void{ public function notifyTerrainReady() : void{
$this->logger->debug("Sending spawn notification, waiting for spawn response"); $this->logger->debug("Sending spawn notification, waiting for spawn response");
$this->sendDataPacket(PlayStatusPacket::create(PlayStatusPacket::PLAYER_SPAWN)); $this->sendDataPacket(PlayStatusPacket::create(PlayStatusPacket::PLAYER_SPAWN));
$this->setHandler(new SpawnResponsePacketHandler(function() : void{ $this->setHandler(new SpawnResponsePacketHandler($this->onClientSpawnResponse(...)));
$this->onClientSpawnResponse();
}));
} }
private function onClientSpawnResponse() : void{ private function onClientSpawnResponse() : void{

View File

@ -95,12 +95,8 @@ final class CraftingDataCache{
$recipesWithTypeIds[] = new ProtocolShapelessRecipe( $recipesWithTypeIds[] = new ProtocolShapelessRecipe(
CraftingDataPacket::ENTRY_SHAPELESS, CraftingDataPacket::ENTRY_SHAPELESS,
Binary::writeInt($index), Binary::writeInt($index),
array_map(function(RecipeIngredient $item) use ($converter) : ProtocolRecipeIngredient{ array_map($converter->coreRecipeIngredientToNet(...), $recipe->getIngredientList()),
return $converter->coreRecipeIngredientToNet($item); array_map($converter->coreItemStackToNet(...), $recipe->getResults()),
}, $recipe->getIngredientList()),
array_map(function(Item $item) use ($converter) : ItemStack{
return $converter->coreItemStackToNet($item);
}, $recipe->getResults()),
$nullUUID, $nullUUID,
$typeTag, $typeTag,
50, 50,
@ -118,9 +114,7 @@ final class CraftingDataCache{
CraftingDataPacket::ENTRY_SHAPED, CraftingDataPacket::ENTRY_SHAPED,
Binary::writeInt($index), Binary::writeInt($index),
$inputs, $inputs,
array_map(function(Item $item) use ($converter) : ItemStack{ array_map($converter->coreItemStackToNet(...), $recipe->getResults()),
return $converter->coreItemStackToNet($item);
}, $recipe->getResults()),
$nullUUID, $nullUUID,
CraftingRecipeBlockName::CRAFTING_TABLE, CraftingRecipeBlockName::CRAFTING_TABLE,
50, 50,

View File

@ -121,8 +121,6 @@ trait RegistryTrait{
*/ */
private static function _registryGetAll() : array{ private static function _registryGetAll() : array{
self::checkInit(); self::checkInit();
return array_map(function(object $o) : object{ return array_map(self::preprocessMember(...), self::$members);
return self::preprocessMember($o);
}, self::$members);
} }
} }