mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 04:17:07 +00:00
Item: restrict bounds of count to 0-255
This commit is contained in:
parent
46ac4cbca1
commit
10317527e4
@ -557,6 +557,10 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setCount(int $count) : Item{
|
public function setCount(int $count) : Item{
|
||||||
|
if($count < 0 or $count > 255){
|
||||||
|
throw new \InvalidArgumentException("Count must be in the range 0-255");
|
||||||
|
}
|
||||||
|
|
||||||
$this->count = $count;
|
$this->count = $count;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -89,4 +89,18 @@ class ItemTest extends TestCase{
|
|||||||
self::assertEquals($id, $item->getId());
|
self::assertEquals($id, $item->getId());
|
||||||
self::assertEquals($meta, $item->getDamage());
|
self::assertEquals($meta, $item->getDamage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetCountTooBig() : void{
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
|
$item = ItemFactory::get(ItemIds::STONE);
|
||||||
|
$item->setCount(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetCountTooSmall() : void{
|
||||||
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
|
$item = ItemFactory::get(ItemIds::STONE);
|
||||||
|
$item->setCount(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user