From 313fdb9e8747fd62cb79ad90bcfbd1cb5488a00d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 14 Jun 2017 19:34:32 +0100 Subject: [PATCH] Added INT32_MIN and INT32_MAX constants and an exception throw for out-of-range effect amplifiers --- src/pocketmine/PocketMine.php | 3 +++ src/pocketmine/entity/Effect.php | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index b8f6b860c..66804a7b9 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -22,6 +22,9 @@ declare(strict_types=1); namespace { + const INT32_MIN = -0x80000000; + const INT32_MAX = 0x7fffffff; + function safe_var_dump(){ static $cnt = 0; foreach(func_get_args() as $var){ diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 9d96adf22..17ccb97f6 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -174,7 +174,10 @@ class Effect{ * * @return $this */ - public function setDuration($ticks){ + public function setDuration(int $ticks){ + if($ticks < 0 or $ticks > INT32_MAX){ + throw new \InvalidArgumentException("Effect duration must be in range of 0 - " . INT32_MAX); + } $this->duration = $ticks; return $this; } @@ -248,7 +251,7 @@ class Effect{ * @return $this */ public function setAmplifier(int $amplifier){ - $this->amplifier = $amplifier & 0xff; + $this->amplifier = ($amplifier & 0xff); return $this; }