Added some asserts

This commit is contained in:
Shoghi Cervantes 2015-09-27 19:48:42 +02:00
parent eaef40618b
commit cf3d8f449e
9 changed files with 30 additions and 41 deletions

View File

@ -2487,7 +2487,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = EntityEventPacket::USE_ITEM;
$pk;
$this->dataPacket($pk);
Server::broadcastPacket($this->getViewers(), $pk);

View File

@ -1518,6 +1518,9 @@ class Server{
}
define('pocketmine\DEBUG', (int) $this->getProperty("debug.level", 1));
ini_set('assert.exception', 1);
if($this->logger instanceof MainLogger){
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
}
@ -1867,10 +1870,6 @@ class Server{
* @throws \Exception
*/
public function dispatchCommand(CommandSender $sender, $commandLine){
if(!($sender instanceof CommandSender)){
throw new ServerException("CommandSender is not valid");
}
if($this->commandMap->dispatch($sender, $commandLine)){
return true;
}

View File

@ -206,9 +206,8 @@ abstract class Entity extends Location implements Metadatable{
public function __construct(FullChunk $chunk, CompoundTag $nbt){
if($chunk === null or $chunk->getProvider() === null){
throw new ChunkException("Invalid garbage Chunk given to Entity");
}
assert($chunk !== null and $chunk->getProvider() !== null);
$this->timings = Timings::getEntityTimings($this);
@ -240,6 +239,8 @@ abstract class Entity extends Location implements Metadatable{
);
$this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z));
if(!isset($this->namedtag->FallDistance)){
$this->namedtag->FallDistance = new FloatTag("FallDistance", 0);
}
@ -501,6 +502,8 @@ abstract class Entity extends Location implements Metadatable{
}
protected function initEntity(){
assert($this->namedtag instanceof CompoundTag);
if(isset($this->namedtag->ActiveEffects)){
foreach($this->namedtag->ActiveEffects->getValue() as $e){
$effect = Effect::getEffect($e["Id"]);

View File

@ -30,6 +30,7 @@ use pocketmine\item\Item as ItemItem;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\Network;
@ -70,6 +71,9 @@ class Item extends Entity{
if(isset($this->namedtag->Thrower)){
$this->thrower = $this->namedtag["Thrower"];
}
assert($this->namedtag->Item instanceof CompoundTag);
if(!isset($this->namedtag->Item)){
$this->close();
return;

View File

@ -78,9 +78,7 @@ class Position extends Vector3{
* @throws LevelException
*/
public function getSide($side, $step = 1){
if(!$this->isValid()){
throw new LevelException("Undefined Level reference");
}
assert($this->isValid());
return Position::fromObject(parent::getSide($side, $step), $this->level);
}

View File

@ -118,15 +118,10 @@ abstract class Generator{
* @return \SplFixedArray
*/
public static function getFastNoise2D(Noise $noise, $xSize, $zSize, $samplingRate, $x, $y, $z){
if($samplingRate === 0){
throw new \InvalidArgumentException("samplingRate cannot be 0");
}
if ($xSize % $samplingRate !== 0) {
throw new \InvalidArgumentCountException("xSize % samplingRate must return 0");
}
if ($zSize % $samplingRate !== 0) {
throw new \InvalidArgumentCountException("zSize % samplingRate must return 0");
}
assert($samplingRate !== 0, new \InvalidArgumentException("samplingRate cannot be 0"));
assert($xSize % $samplingRate === 0, new \InvalidArgumentCountException("xSize % samplingRate must return 0"));
assert($zSize % $samplingRate === 0, new \InvalidArgumentCountException("zSize % samplingRate must return 0"));
$noiseArray = new \SplFixedArray($xSize + 1);
@ -173,24 +168,14 @@ abstract class Generator{
* @return \SplFixedArray
*/
public static function getFastNoise3D(Noise $noise, $xSize, $ySize, $zSize, $xSamplingRate, $ySamplingRate, $zSamplingRate, $x, $y, $z){
if($xSamplingRate === 0){
throw new \InvalidArgumentException("xSamplingRate cannot be 0");
}
if($zSamplingRate === 0){
throw new \InvalidArgumentException("zSamplingRate cannot be 0");
}
if($ySamplingRate === 0){
throw new \InvalidArgumentException("ySamplingRate cannot be 0");
}
if ($xSize % $xSamplingRate !== 0) {
throw new \InvalidArgumentCountException("xSize % xSamplingRate must return 0");
}
if ($zSize % $zSamplingRate !== 0) {
throw new \InvalidArgumentCountException("zSize % zSamplingRate must return 0");
}
if ($ySize % $ySamplingRate !== 0) {
throw new \InvalidArgumentCountException("ySize % ySamplingRate must return 0");
}
assert($xSamplingRate !== 0, new \InvalidArgumentException("xSamplingRate cannot be 0"));
assert($zSamplingRate !== 0, new \InvalidArgumentException("zSamplingRate cannot be 0"));
assert($ySamplingRate !== 0, new \InvalidArgumentException("ySamplingRate cannot be 0"));
assert($xSize % $xSamplingRate === 0, new \InvalidArgumentCountException("xSize % xSamplingRate must return 0"));
assert($zSize % $zSamplingRate === 0, new \InvalidArgumentCountException("zSize % zSamplingRate must return 0"));
assert($ySize % $ySamplingRate === 0, new \InvalidArgumentCountException("ySize % ySamplingRate must return 0"));
$noiseArray = array_fill(0, $xSize + 1, array_fill(0, $zSize + 1, []));

View File

@ -62,6 +62,8 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
}
}
assert(false, "Offset $offset not found");
return null;
}

View File

@ -84,6 +84,7 @@ network:
upnp-forwarding: false
debug:
#To enable assertion execution, set zend.assertions in your php.ini to 1
#If > 1, it will show debug messages in the console
level: 1
#Enables /status, /gc

View File

@ -111,9 +111,7 @@ abstract class Tile extends Position{
}
public function __construct(FullChunk $chunk, CompoundTag $nbt){
if($chunk === null or $chunk->getProvider() === null){
throw new ChunkException("Invalid garbage Chunk given to Tile");
}
assert($chunk !== null and $chunk->getProvider() !== null);
$this->timings = Timings::getTileEntityTimings($this);