mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-19 15:35:52 +00:00
Replace Closure::fromCallable() usages with first-class callables
PHP 8.1 <3
This commit is contained in:
parent
fba51e3bf9
commit
537721fe7d
@ -312,7 +312,7 @@ abstract class Liquid extends Transparent{
|
||||
}
|
||||
|
||||
if($adjacentDecay <= self::MAX_DECAY){
|
||||
$calculator = new MinimumCostFlowCalculator($world, $this->getFlowDecayPerBlock(), \Closure::fromCallable([$this, 'canFlowInto']));
|
||||
$calculator = new MinimumCostFlowCalculator($world, $this->getFlowDecayPerBlock(), $this->canFlowInto(...));
|
||||
foreach($calculator->getOptimalFlowDirections($this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ()) as $facing){
|
||||
$this->flowIntoBlock($world->getBlock($this->position->getSide($facing)), $adjacentDecay, false);
|
||||
}
|
||||
|
@ -209,9 +209,6 @@ final class CraftingManagerFromDataHelper{
|
||||
public static function make(string $directoryPath) : CraftingManager{
|
||||
$result = new CraftingManager();
|
||||
|
||||
$ingredientDeserializerFunc = \Closure::fromCallable([self::class, "deserializeIngredient"]);
|
||||
$itemDeserializerFunc = \Closure::fromCallable([self::class, 'deserializeItemStack']);
|
||||
|
||||
foreach(self::loadJsonArrayOfObjectsFile(Path::join($directoryPath, 'shapeless_crafting.json'), ShapelessRecipeData::class) as $recipe){
|
||||
$recipeType = match($recipe->block){
|
||||
"crafting_table" => ShapelessRecipeType::CRAFTING(),
|
||||
@ -225,7 +222,7 @@ final class CraftingManagerFromDataHelper{
|
||||
}
|
||||
$inputs = [];
|
||||
foreach($recipe->input as $inputData){
|
||||
$input = $ingredientDeserializerFunc($inputData);
|
||||
$input = self::deserializeIngredient($inputData);
|
||||
if($input === null){ //unknown input item
|
||||
continue 2;
|
||||
}
|
||||
@ -233,7 +230,7 @@ final class CraftingManagerFromDataHelper{
|
||||
}
|
||||
$outputs = [];
|
||||
foreach($recipe->output as $outputData){
|
||||
$output = $itemDeserializerFunc($outputData);
|
||||
$output = self::deserializeItemStack($outputData);
|
||||
if($output === null){ //unknown output item
|
||||
continue 2;
|
||||
}
|
||||
@ -251,7 +248,7 @@ final class CraftingManagerFromDataHelper{
|
||||
}
|
||||
$inputs = [];
|
||||
foreach(Utils::stringifyKeys($recipe->input) as $symbol => $inputData){
|
||||
$input = $ingredientDeserializerFunc($inputData);
|
||||
$input = self::deserializeIngredient($inputData);
|
||||
if($input === null){ //unknown input item
|
||||
continue 2;
|
||||
}
|
||||
@ -259,7 +256,7 @@ final class CraftingManagerFromDataHelper{
|
||||
}
|
||||
$outputs = [];
|
||||
foreach($recipe->output as $outputData){
|
||||
$output = $itemDeserializerFunc($outputData);
|
||||
$output = self::deserializeItemStack($outputData);
|
||||
if($output === null){ //unknown output item
|
||||
continue 2;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ class InventoryManager{
|
||||
private NetworkSession $session
|
||||
){
|
||||
$this->containerOpenCallbacks = new ObjectSet();
|
||||
$this->containerOpenCallbacks->add(\Closure::fromCallable([self::class, 'createContainerOpen']));
|
||||
$this->containerOpenCallbacks->add(self::createContainerOpen(...));
|
||||
|
||||
$this->add(ContainerIds::INVENTORY, $this->player->getInventory());
|
||||
$this->add(ContainerIds::OFFHAND, $this->player->getOffHandInventory());
|
||||
|
@ -225,13 +225,13 @@ class NetworkSession{
|
||||
$this->logger->setPrefix($this->getLogPrefix());
|
||||
$this->manager->markLoginReceived($this);
|
||||
},
|
||||
\Closure::fromCallable([$this, "setAuthenticationStatus"])
|
||||
$this->setAuthenticationStatus(...)
|
||||
));
|
||||
}
|
||||
|
||||
protected function createPlayer() : void{
|
||||
$this->server->createPlayer($this, $this->info, $this->authenticated, $this->cachedOfflinePlayerData)->onCompletion(
|
||||
\Closure::fromCallable([$this, 'onPlayerCreated']),
|
||||
$this->onPlayerCreated(...),
|
||||
function() : void{
|
||||
//TODO: this should never actually occur... right?
|
||||
$this->logger->error("Failed to create player");
|
||||
|
@ -1610,7 +1610,7 @@ class World implements ChunkManager{
|
||||
* the current weather and time of day.
|
||||
*/
|
||||
public function getHighestAdjacentFullLightAt(int $x, int $y, int $z) : int{
|
||||
return $this->getHighestAdjacentLight($x, $y, $z, \Closure::fromCallable([$this, 'getFullLightAt']));
|
||||
return $this->getHighestAdjacentLight($x, $y, $z, $this->getFullLightAt(...));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1706,7 +1706,7 @@ class World implements ChunkManager{
|
||||
* Returns the highest potential level of sky light in the positions adjacent to the specified block coordinates.
|
||||
*/
|
||||
public function getHighestAdjacentPotentialBlockSkyLight(int $x, int $y, int $z) : int{
|
||||
return $this->getHighestAdjacentLight($x, $y, $z, \Closure::fromCallable([$this, 'getPotentialBlockSkyLightAt']));
|
||||
return $this->getHighestAdjacentLight($x, $y, $z, $this->getPotentialBlockSkyLightAt(...));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1721,7 +1721,7 @@ class World implements ChunkManager{
|
||||
* Returns the highest block light level available in the positions adjacent to the specified block coordinates.
|
||||
*/
|
||||
public function getHighestAdjacentBlockLight(int $x, int $y, int $z) : int{
|
||||
return $this->getHighestAdjacentLight($x, $y, $z, \Closure::fromCallable([$this, 'getBlockLightAt']));
|
||||
return $this->getHighestAdjacentLight($x, $y, $z, $this->getBlockLightAt(...));
|
||||
}
|
||||
|
||||
private function executeQueuedLightUpdates() : void{
|
||||
|
@ -41,13 +41,13 @@ final class WorldProviderManager{
|
||||
private WritableWorldProviderManagerEntry $default;
|
||||
|
||||
public function __construct(){
|
||||
$leveldb = new WritableWorldProviderManagerEntry(\Closure::fromCallable([LevelDB::class, 'isValid']), fn(string $path, \Logger $logger) => new LevelDB($path, $logger), \Closure::fromCallable([LevelDB::class, 'generate']));
|
||||
$leveldb = new WritableWorldProviderManagerEntry(LevelDB::isValid(...), fn(string $path, \Logger $logger) => new LevelDB($path, $logger), LevelDB::generate(...));
|
||||
$this->default = $leveldb;
|
||||
$this->addProvider($leveldb, "leveldb");
|
||||
|
||||
$this->addProvider(new ReadOnlyWorldProviderManagerEntry(\Closure::fromCallable([Anvil::class, 'isValid']), fn(string $path, \Logger $logger) => new Anvil($path, $logger)), "anvil");
|
||||
$this->addProvider(new ReadOnlyWorldProviderManagerEntry(\Closure::fromCallable([McRegion::class, 'isValid']), fn(string $path, \Logger $logger) => new McRegion($path, $logger)), "mcregion");
|
||||
$this->addProvider(new ReadOnlyWorldProviderManagerEntry(\Closure::fromCallable([PMAnvil::class, 'isValid']), fn(string $path, \Logger $logger) => new PMAnvil($path, $logger)), "pmanvil");
|
||||
$this->addProvider(new ReadOnlyWorldProviderManagerEntry(Anvil::isValid(...), fn(string $path, \Logger $logger) => new Anvil($path, $logger)), "anvil");
|
||||
$this->addProvider(new ReadOnlyWorldProviderManagerEntry(McRegion::isValid(...), fn(string $path, \Logger $logger) => new McRegion($path, $logger)), "mcregion");
|
||||
$this->addProvider(new ReadOnlyWorldProviderManagerEntry(PMAnvil::isValid(...), fn(string $path, \Logger $logger) => new PMAnvil($path, $logger)), "pmanvil");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,7 +78,7 @@ final class UnsafeForeachArrayOfStringRule implements Rule{
|
||||
return $type;
|
||||
});
|
||||
if($hasCastableKeyTypes && !$expectsIntKeyTypes){
|
||||
$func = \Closure::fromCallable([Utils::class, 'stringifyKeys']);
|
||||
$func = Utils::stringifyKeys(...);
|
||||
return [
|
||||
RuleErrorBuilder::message(sprintf(
|
||||
"Unsafe foreach on array with key type %s (they might be casted to int).",
|
||||
|
Loading…
x
Reference in New Issue
Block a user