From 39d5903c3edb23125aa33cd2c87a5d792dd156ac Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 25 Aug 2019 16:09:51 +0100 Subject: [PATCH] Remove INT32_MIN and INT32_MAX global constants --- src/PocketMine.php | 5 ----- src/command/defaults/EffectCommand.php | 4 ++-- src/entity/Human.php | 5 ++--- src/entity/effect/EffectInstance.php | 6 +++--- src/world/SimpleChunkManager.php | 7 +++---- src/world/World.php | 7 +++---- src/world/WorldManager.php | 5 ++--- src/world/format/io/data/BedrockWorldData.php | 3 ++- 8 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/PocketMine.php b/src/PocketMine.php index 6f38f9ec9..f54bea158 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -21,11 +21,6 @@ declare(strict_types=1); -namespace { - const INT32_MIN = -0x80000000; - const INT32_MAX = 0x7fffffff; -} - namespace pocketmine { use pocketmine\thread\ThreadManager; diff --git a/src/command/defaults/EffectCommand.php b/src/command/defaults/EffectCommand.php index d78b5cc04..b7ec3760b 100644 --- a/src/command/defaults/EffectCommand.php +++ b/src/command/defaults/EffectCommand.php @@ -28,10 +28,10 @@ use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\entity\effect\EffectInstance; use pocketmine\entity\effect\VanillaEffects; use pocketmine\lang\TranslationContainer; +use pocketmine\utils\Limits; use pocketmine\utils\TextFormat; use function count; use function strtolower; -use const INT32_MAX; class EffectCommand extends VanillaCommand{ @@ -78,7 +78,7 @@ class EffectCommand extends VanillaCommand{ $amplification = 0; if(count($args) >= 3){ - if(($d = $this->getBoundedInt($sender, $args[2], 0, (int) (INT32_MAX / 20))) === null){ + if(($d = $this->getBoundedInt($sender, $args[2], 0, (int) (Limits::INT32_MAX / 20))) === null){ return false; } $duration = $d * 20; //ticks diff --git a/src/entity/Human.php b/src/entity/Human.php index 5876e1fd7..955db74c7 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -49,6 +49,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; use pocketmine\network\mcpe\protocol\types\entity\StringMetadataProperty; use pocketmine\network\mcpe\protocol\types\PlayerListEntry; use pocketmine\player\Player; +use pocketmine\utils\Limits; use pocketmine\utils\UUID; use pocketmine\world\sound\TotemUseSound; use pocketmine\world\World; @@ -59,8 +60,6 @@ use function in_array; use function min; use function random_int; use function strlen; -use const INT32_MAX; -use const INT32_MIN; class Human extends Living implements ProjectileSource, InventoryHolder{ @@ -274,7 +273,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ if($nbt->hasTag("XpSeed", IntTag::class)){ $this->xpSeed = $nbt->getInt("XpSeed"); }else{ - $this->xpSeed = random_int(INT32_MIN, INT32_MAX); + $this->xpSeed = random_int(Limits::INT32_MIN, Limits::INT32_MAX); } } diff --git a/src/entity/effect/EffectInstance.php b/src/entity/effect/EffectInstance.php index 4da94f602..ee7665d38 100644 --- a/src/entity/effect/EffectInstance.php +++ b/src/entity/effect/EffectInstance.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\entity\effect; use pocketmine\utils\Color; +use pocketmine\utils\Limits; use function max; -use const INT32_MAX; class EffectInstance{ /** @var Effect */ @@ -89,8 +89,8 @@ class EffectInstance{ * @return $this */ public function setDuration(int $duration) : EffectInstance{ - if($duration < 0 or $duration > INT32_MAX){ - throw new \InvalidArgumentException("Effect duration must be in range 0 - " . INT32_MAX . ", got $duration"); + if($duration < 0 or $duration > Limits::INT32_MAX){ + throw new \InvalidArgumentException("Effect duration must be in range 0 - " . Limits::INT32_MAX . ", got $duration"); } $this->duration = $duration; diff --git a/src/world/SimpleChunkManager.php b/src/world/SimpleChunkManager.php index 928f033ba..14673fe5f 100644 --- a/src/world/SimpleChunkManager.php +++ b/src/world/SimpleChunkManager.php @@ -26,10 +26,9 @@ namespace pocketmine\world; use pocketmine\block\Block; use pocketmine\block\BlockFactory; use pocketmine\block\VanillaBlocks; +use pocketmine\utils\Limits; use pocketmine\world\format\Chunk; use pocketmine\world\utils\SubChunkIteratorManager; -use const INT32_MAX; -use const INT32_MIN; class SimpleChunkManager implements ChunkManager{ @@ -102,9 +101,9 @@ class SimpleChunkManager implements ChunkManager{ public function isInWorld(int $x, int $y, int $z) : bool{ return ( - $x <= INT32_MAX and $x >= INT32_MIN and + $x <= Limits::INT32_MAX and $x >= Limits::INT32_MIN and $y < $this->worldHeight and $y >= 0 and - $z <= INT32_MAX and $z >= INT32_MIN + $z <= Limits::INT32_MAX and $z >= Limits::INT32_MIN ); } } diff --git a/src/world/World.php b/src/world/World.php index 27c29472b..caf1c7344 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -60,6 +60,7 @@ use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\player\Player; use pocketmine\Server; use pocketmine\timings\Timings; +use pocketmine\utils\Limits; use pocketmine\utils\ReversePriorityQueue; use pocketmine\world\biome\Biome; use pocketmine\world\format\Chunk; @@ -100,8 +101,6 @@ use function mt_rand; use function spl_object_id; use function strtolower; use function trim; -use const INT32_MAX; -use const INT32_MIN; use const M_PI; use const PHP_INT_MAX; use const PHP_INT_MIN; @@ -1260,9 +1259,9 @@ class World implements ChunkManager{ public function isInWorld(int $x, int $y, int $z) : bool{ return ( - $x <= INT32_MAX and $x >= INT32_MIN and + $x <= Limits::INT32_MAX and $x >= Limits::INT32_MIN and $y < $this->worldHeight and $y >= 0 and - $z <= INT32_MAX and $z >= INT32_MIN + $z <= Limits::INT32_MAX and $z >= Limits::INT32_MIN ); } diff --git a/src/world/WorldManager.php b/src/world/WorldManager.php index f7604dc59..f8059aaa8 100644 --- a/src/world/WorldManager.php +++ b/src/world/WorldManager.php @@ -29,6 +29,7 @@ use pocketmine\event\world\WorldLoadEvent; use pocketmine\event\world\WorldUnloadEvent; use pocketmine\Server; use pocketmine\timings\Timings; +use pocketmine\utils\Limits; use pocketmine\utils\Utils; use pocketmine\world\format\io\exception\CorruptedWorldException; use pocketmine\world\format\io\exception\UnsupportedWorldFormatException; @@ -50,8 +51,6 @@ use function random_int; use function round; use function sprintf; use function trim; -use const INT32_MAX; -use const INT32_MIN; class WorldManager{ /** @var World[] */ @@ -276,7 +275,7 @@ class WorldManager{ return false; } - $seed = $seed ?? random_int(INT32_MIN, INT32_MAX); + $seed = $seed ?? random_int(Limits::INT32_MIN, Limits::INT32_MAX); Utils::testValidInstance($generator, Generator::class); diff --git a/src/world/format/io/data/BedrockWorldData.php b/src/world/format/io/data/BedrockWorldData.php index b38c5fa83..6e04c434d 100644 --- a/src/world/format/io/data/BedrockWorldData.php +++ b/src/world/format/io/data/BedrockWorldData.php @@ -31,6 +31,7 @@ use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\TreeRoot; use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\utils\Binary; +use pocketmine\utils\Limits; use pocketmine\utils\Utils; use pocketmine\world\format\io\exception\CorruptedWorldException; use pocketmine\world\format\io\exception\UnsupportedWorldFormatException; @@ -112,7 +113,7 @@ class BedrockWorldData extends BaseNbtWorldData{ throw new CorruptedWorldException($e->getMessage(), 0, $e); } - $version = $worldData->getInt("StorageVersion", INT32_MAX, true); + $version = $worldData->getInt("StorageVersion", Limits::INT32_MAX, true); if($version > self::CURRENT_STORAGE_VERSION){ throw new UnsupportedWorldFormatException("LevelDB world format version $version is currently unsupported"); }