Remove INT32_MIN and INT32_MAX global constants

This commit is contained in:
Dylan K. Taylor 2019-08-25 16:09:51 +01:00
parent 95a4081d24
commit 39d5903c3e
8 changed files with 17 additions and 25 deletions

View File

@ -21,11 +21,6 @@
declare(strict_types=1);
namespace {
const INT32_MIN = -0x80000000;
const INT32_MAX = 0x7fffffff;
}
namespace pocketmine {
use pocketmine\thread\ThreadManager;

View File

@ -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

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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
);
}
}

View File

@ -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
);
}

View File

@ -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);

View File

@ -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");
}